diff --git a/composer.json b/composer.json index 5dad547..d45c475 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ }, "scripts": { "test": "vendor/bin/phpunit tests/ --coverage-text", - "lint": "vendor/bin/phpcs --standard=psr12 src/" + "lint": "vendor/bin/phpcs" }, "extra": { "branch-alias": { diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..50605ce --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,14 @@ + + + + PHPCS configuration file. + + + + src + tests + + + */tests/* + + diff --git a/tests/AckTest.php b/tests/AckTest.php index b2a2a7c..fa8dc68 100644 --- a/tests/AckTest.php +++ b/tests/AckTest.php @@ -1,4 +1,5 @@ toString(true)); } diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 8fa3902..5303a03 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -1,4 +1,5 @@ port); $msg = new Message("MSH|^~\\&|1|\rPV1|1|O|^AAAA1^^^BB|", null, true, true); - self::assertNull($connection->send($msg,' UTF-8', true)); + self::assertNull($connection->send($msg, ' UTF-8', true)); $this->closeTcpSocket($connection->getSocket()); // Clean up listener pcntl_wait($status); // Wait till child is closed diff --git a/tests/Hl7ListenerTrait.php b/tests/Hl7ListenerTrait.php index 6a6ed48..04a4760 100644 --- a/tests/Hl7ListenerTrait.php +++ b/tests/Hl7ListenerTrait.php @@ -5,6 +5,8 @@ use Aranyasen\Exceptions\HL7Exception; use Aranyasen\HL7\Message; use Aranyasen\HL7\Messages\ACK; +use ReflectionException; +use RuntimeException; /** * Trait Hl7ListenerTrait @@ -25,13 +27,13 @@ trait Hl7ListenerTrait public function writeToPipe(string $value): void { - $pipe = fopen($this->pipeName,'wb'); + $pipe = fopen($this->pipeName, 'wb'); fwrite($pipe, $value); } public function readFromPipe(): string { - $pipe = fopen($this->pipeName,'rb'); + $pipe = fopen($this->pipeName, 'rb'); return fread($pipe, 1024); } @@ -44,12 +46,14 @@ public function getWhatServerGot(): string * @param int $port * @param int $totalClientsToConnect How many clients are expected to connect to this server, once it's up * @throws HL7Exception - * @throws \ReflectionException + * @throws ReflectionException */ public function createTcpServer(int $port, int $totalClientsToConnect): void { if (($socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) { - throw new \RuntimeException('socket_create() failed: reason: ' . socket_strerror(socket_last_error()) . "\n"); + throw new RuntimeException( + 'socket_create() failed: reason: ' . socket_strerror(socket_last_error()) . "\n" + ); } // This is to avoid "address already in use" error while doing ->bind() diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 42cac88..946c58d 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -121,7 +121,8 @@ public function fields_can_be_separated_by_custom_character(): void $msg = new Message("MSH*^~\\&*1\rABC***xxx\r"); // Use * as a field separator self::assertSame( - 'MSH*^~\&*1*\nABC***xxx*\n', $msg->toString(), + 'MSH*^~\&*1*\nABC***xxx*\n', + $msg->toString(), 'String representation of message with * as field separator' ); self::assertSame('1', $msg->getSegmentByIndex(0)->getField(3), '3d field of MSH'); @@ -162,7 +163,11 @@ public function segment_can_be_removed_from_message(): void $msg = new Message("MSH|^~\\&|1|\nAAA|1||xxx|\nBBB|1|a|\nBBB|2|b|\nBBB|3|c|"); $segment = $msg->getSegmentsByName('BBB')[1]; $msg->removeSegment($segment, true); - self::assertSame("MSH|^~\\&|1|\nAAA|1||xxx|\nBBB|1|a|\nBBB|2|c|\n", $msg->toString(true), 'Should reset index of subsequent segments'); + self::assertSame( + "MSH|^~\\&|1|\nAAA|1||xxx|\nBBB|1|a|\nBBB|2|c|\n", + $msg->toString(true), + 'Should reset index of subsequent segments' + ); } /** @test */ @@ -299,7 +304,7 @@ public function an_exception_will_be_throw_in_invalid_string(): void /** @test */ public function segment_ending_bar_can_be_omitted(): void { - $msg = new Message("MSH|^~\\&|1|\nABC|||xxx|\n", ['SEGMENT_ENDING_BAR' => false]); + $msg = new Message("MSH|^~\\&|1|\nABC|||xxx|\n", ['SEGMENT_ENDING_BAR' => false]); self::assertSame("MSH|^~\\&|1\nABC|||xxx\n", $msg->toString(true), 'No ending bar on each segment'); $msg = new Message("MSH|^~\\&|1|\nABC|||xxx|\n"); @@ -341,11 +346,13 @@ public function message_type_can_be_checked(): void /** * The segment classes use static properties to maintain segment-index. This is required as one can add new segments - * to a given message object and expect the index to auto-increment. The side-effect to this is, if you create a - * second message, adding the same segments will now start indexing from their index in the last message instead of 1! - * This happens because static properties are class properties, not object ones, and thus shared across all objects. + * to a given message object and expect the index to auto-increment. The side effect to this is, if you create a + * second message, adding the same segments will now start indexing from their index in the last message instead of + * 1! This happens because static properties are class properties, not object ones, and thus shared across all + * objects. * - * To counter this, use 'true' in the 4th argument while creating a message, or call resetSegmentIndices() explicitly + * To counter this, use 'true' in the 4th argument while creating a message, or call resetSegmentIndices() + * explicitly. * * This test verifies both. * @@ -357,12 +364,20 @@ public function segment_id_can_be_reset_on_demand(): void // Create a message with a PID segment $msg1 = new Message("MSH|^~\&|||||||ORM^O01||P|2.3.1|"); $msg1->addSegment(new PID()); - self::assertSame("MSH|^~\&|||||||ORM^O01||P|2.3.1|\nPID|1|\n", $msg1->toString(true), 'PID index in first message is 1'); + self::assertSame( + "MSH|^~\&|||||||ORM^O01||P|2.3.1|\nPID|1|\n", + $msg1->toString(true), + 'PID index in first message is 1' + ); // Create another message with a PID segment $msg2 = new Message("MSH|^~\&|||||||ORM^O01||P|2.3.1|"); $msg2->addSegment(new PID()); - self::assertSame("MSH|^~\&|||||||ORM^O01||P|2.3.1|\nPID|2|\n", $msg2->toString(true), 'PID index gets incremented'); + self::assertSame( + "MSH|^~\&|||||||ORM^O01||P|2.3.1|\nPID|2|\n", + $msg2->toString(true), + 'PID index gets incremented' + ); // Create another message with a PID segment, this time 4th argument to message as true $msg3 = new Message("MSH|^~\&|||||||ORM^O01||P|2.3.1|", null, true, true); @@ -372,7 +387,11 @@ public function segment_id_can_be_reset_on_demand(): void // Create a message with a PID segment $msg4 = new Message("MSH|^~\&|||||||ORM^O01||P|2.3.1|"); $msg4->addSegment(new PID()); - self::assertSame("MSH|^~\&|||||||ORM^O01||P|2.3.1|\nPID|2|\n", $msg4->toString(true), 'PID index gets incremented'); + self::assertSame( + "MSH|^~\&|||||||ORM^O01||P|2.3.1|\nPID|2|\n", + $msg4->toString(true), + 'PID index gets incremented' + ); $msg5 = new Message("MSH|^~\&|||||||ORM^O01||P|2.3.1|"); $msg5->resetSegmentIndices(); diff --git a/tests/Segments/MSHTest.php b/tests/Segments/MSHTest.php index 888f76d..f43c528 100644 --- a/tests/Segments/MSHTest.php +++ b/tests/Segments/MSHTest.php @@ -6,6 +6,7 @@ use Aranyasen\HL7\Segments\MSH; use Aranyasen\HL7\Tests\TestCase; +use Exception; class MSHTest extends TestCase { @@ -21,13 +22,21 @@ public function MSH_formed_without_any_arguments_should_have_mandatory_fields_se } /** @test - * @throws \Exception + * @throws Exception */ public function an_array_of_fields_can_be_passed_to_constructor_to_construct_MSH(): void { - $msh = new MSH(['MSH', '^~\&', 'HL7 Corp', 'HL7 HQ', 'VISION', 'MISYS', '200404061744', '', ['DFT', 'P03'], 'TC-22222', 'T', '2.3']); + $msh = new MSH( + [ + 'MSH', '^~\&', 'HL7 Corp', 'HL7 HQ', 'VISION', 'MISYS', '200404061744', '', ['DFT', 'P03'], 'TC-22222', + 'T', '2.3', + ] + ); self::assertSame( - ['MSH', '', '^~\&', 'HL7 Corp', 'HL7 HQ', 'VISION', 'MISYS', '200404061744', '', ['DFT', 'P03'], 'TC-22222', 'T', '2.3'], + [ + 'MSH', '', '^~\&', 'HL7 Corp', 'HL7 HQ', 'VISION', 'MISYS', '200404061744', '', ['DFT', 'P03'], + 'TC-22222', 'T', '2.3', + ], $msh->getFields() ); } diff --git a/tests/Segments/PIDTest.php b/tests/Segments/PIDTest.php index bb44916..777678e 100644 --- a/tests/Segments/PIDTest.php +++ b/tests/Segments/PIDTest.php @@ -49,7 +49,8 @@ public function PID_5_should_parse_properly(): void $msg = new Message($messageString, null, false, true, true, true); self::assertSame( - 'MSH|^~\&|1|\nPID|1||||Test &""&firstname &""&""^F^N N^F^""~Test &""&Test^Test^""^B~""&""&""^P~^Lastname^N|\n', + 'MSH|^~\&|1|\nPID|1||||Test &""&firstname &""&""^F^N N^F^""~Test &""&Test^Test^""^B~""&""&""^P~^' . + 'Lastname^N|\n', $msg->toString() ); }