Skip to content

Commit

Permalink
Upgrade PhpUnit to v11
Browse files Browse the repository at this point in the history
  • Loading branch information
senaranya committed Jan 6, 2025
1 parent b6f7d03 commit 6fdc319
Show file tree
Hide file tree
Showing 12 changed files with 517 additions and 661 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^9",
"dms/phpunit-arraysubset-asserts": "^0.2",
"phpunit/phpunit": "^11.5.2",
"ext-pcntl": "*",
"ext-sockets": "*",
"squizlabs/php_codesniffer": "^3.6"
"squizlabs/php_codesniffer": "^3.11.2"
},
"autoload": {
"psr-4": {
Expand Down
828 changes: 380 additions & 448 deletions composer.lock

Large diffs are not rendered by default.

24 changes: 16 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="HL7 test suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./</directory>
</include>
Expand All @@ -9,10 +22,5 @@
<directory>./docs</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="HL7 test suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</source>
</phpunit>
8 changes: 4 additions & 4 deletions tests/AckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Aranyasen\HL7\Messages\ACK;
use Aranyasen\HL7\Segments\MSH;
use Exception;
use PHPUnit\Framework\Attributes\Test;

class AckTest extends TestCase
{
Expand Down Expand Up @@ -82,10 +83,10 @@ public function test()
self::assertSame('CE', $seg1->getField(1), 'Code CE after setting message');
}

/** @test
/**
* @throws Exception
*/
public function a_MSH_can_be_provided_to_get_the_fields_from(): void
#[Test] public function a_MSH_can_be_provided_to_get_the_fields_from(): void
{
$msg = new Message("MSH|^~\\&|1|\rPV1|1|O|^AAAA1^^^BB|");
$msh = new MSH(
Expand All @@ -99,10 +100,9 @@ public function a_MSH_can_be_provided_to_get_the_fields_from(): void
}

/**
* @test
* @throws Exception
*/
public function globals_can_be_passed_to_constructor(): void
#[Test] public function globals_can_be_passed_to_constructor(): void
{
$msg = new Message("MSH|^~\\&|1|\rPV1|1|O|^AAAA1^^^BB|");
$ack = new ACK($msg, null, ['SEGMENT_SEPARATOR' => '\r\n']);
Expand Down
7 changes: 3 additions & 4 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Aranyasen\Exceptions\HL7Exception;
use Aranyasen\HL7\Message;
use Aranyasen\HL7\Connection;
use PHPUnit\Framework\Attributes\Test;
use RuntimeException;

class ConnectionTest extends TestCase
Expand All @@ -23,11 +24,10 @@ protected function tearDown(): void
}

/**
* @test
* @throws HL7ConnectionException
* @throws HL7Exception
*/
public function a_message_can_be_sent_to_a_hl7_server(): void
#[Test] public function a_message_can_be_sent_to_a_hl7_server(): void
{
if (!extension_loaded('pcntl')) {
self::markTestSkipped("Extension pcntl_fork is not loaded");
Expand Down Expand Up @@ -56,11 +56,10 @@ public function a_message_can_be_sent_to_a_hl7_server(): void
}

/**
* @test
* @throws HL7ConnectionException
* @throws HL7Exception
*/
public function do_not_wait_for_ack_after_sending_if_corresponding_parameter_is_set(): void
#[Test] public function do_not_wait_for_ack_after_sending_if_corresponding_parameter_is_set(): void
{
if (!extension_loaded('pcntl')) {
self::markTestSkipped("Extension pcntl_fork is not loaded");
Expand Down
43 changes: 18 additions & 25 deletions tests/HL7Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@
use Aranyasen\Exceptions\HL7Exception;
use Aranyasen\HL7;
use Aranyasen\HL7\Segments\PID;
use DMS\PHPUnitExtensions\ArraySubset\Assert;
use PHPUnit\Framework\Attributes\Test;

class HL7Test extends TestCase
{
/** @test
/**
* @throws HL7Exception
*/
public function hl7_message_can_be_created_using_factory_class(): void
#[Test] public function hl7_message_can_be_created_using_factory_class(): void
{
$msg = HL7::build()->createMessage();
self::assertIsObject($msg);
self::assertSame(HL7\Message::class, $msg::class);
}

/** @test
/**
* @throws HL7Exception
*/
public function factory_creates_a_msh_segment_with_defaults_when_no_message_string_provided(): void
#[Test] public function factory_creates_a_msh_segment_with_defaults_when_no_message_string_provided(): void
{
$msg = HL7::build()->createMessage();
self::assertStringContainsString('MSH|^~\&|||||', $msg->toString(true));
}

/** @test
/**
* @throws HL7Exception
*/
public function a_message_can_be_built_from_a_provided_hl7_string(): void
#[Test] public function a_message_can_be_built_from_a_provided_hl7_string(): void
{
$msg = HL7::from("MSH|^~\\&|1|\rABC|||xxx|\r")->createMessage();
self::assertSame("MSH|^~\\&|1|\nABC|||xxx|\n", $msg->toString(true));
}

/** @test
/**
* @throws HL7Exception
*/
public function hl7_property_in_a_given_hl7_string_can_be_overridden(): void
#[Test] public function hl7_property_in_a_given_hl7_string_can_be_overridden(): void
{
self::markTestSkipped('property cannot be overridden yet in Message() constructor');
$msg = HL7::from("MSH|^~\\&|1|\rABC|||xxx|\r")
Expand All @@ -51,10 +51,9 @@ public function hl7_property_in_a_given_hl7_string_can_be_overridden(): void
self::assertSame("MSH|^~=&|1|\nABC|||xxx|\n", $msg->toString(true));
}
/**
* @test
* @throws HL7Exception
*/
public function hl7_properties_can_be_set_using_chained_methods(): void
#[Test] public function hl7_properties_can_be_set_using_chained_methods(): void
{
$msg = HL7::build()
->withSegmentSeparator('[')
Expand All @@ -68,20 +67,16 @@ public function hl7_properties_can_be_set_using_chained_methods(): void
self::assertStringContainsString('MSH#*`=}#', $msg->toString(true));
}

/**
* @test
* @throws Exception
*/
public function empty_subfields_can_be_retained_if_needed(): void
#[Test] public function empty_subfields_can_be_retained_if_needed(): void
{
$msg = HL7::from("MSH|^~\\&|1|\rPV1|1|O|^AAAA1^^^BB|")->keepEmptySubfields()->createMessage();
Assert::assertArraySubset(['', 'AAAA1', '', '', 'BB'], $msg->getSegmentByIndex(1)->getField(3));
$this->assertSame(['', 'AAAA1', '', '', 'BB'], $msg->getSegmentByIndex(1)->getField(3));
}

/** @test
/**
* @throws HL7Exception
*/
public function indices_of_each_segment_can_be_reset_when_message_is_composed(): void
#[Test] public function indices_of_each_segment_can_be_reset_when_message_is_composed(): void
{
// Create a message with a PID segment
$msg1 = HL7::from("MSH|^~\&|||||||ORM^O01||P|2.3.1|")->createMessage();
Expand Down Expand Up @@ -124,10 +119,9 @@ public function indices_of_each_segment_can_be_reset_when_message_is_composed():
}

/**
* @test
* @throws HL7Exception
*/
public function auto_increment_of_segment_indices_can_be_avoided(): void
#[Test] public function auto_increment_of_segment_indices_can_be_avoided(): void
{
$hl7String = "MSH|^~\&|||||||ORU^R01|00001|P|2.3.1|\n" . "OBX|1||11^AA|\n" . "OBX|1||22^BB|\n";

Expand Down Expand Up @@ -157,10 +151,10 @@ public function auto_increment_of_segment_indices_can_be_avoided(): void
);
}

/** @test
/**
* @throws HL7Exception
*/
public function repetition_separation_character_can_be_ignored(): void
#[Test] public function repetition_separation_character_can_be_ignored(): void
{
$message = Hl7::from("MSH|^~\&|||||||ADT^A01||P|2.3.1|\nPID|||3^0~4^1")
->createMessage();
Expand All @@ -177,8 +171,7 @@ public function repetition_separation_character_can_be_ignored(): void
self::assertSame(['3', '0~4', '1'], $patientIdentifierList);
}

/** @test */
public function it_throws_exception_when_multiple_character_property_is_provided(): void
#[Test] public function it_throws_exception_when_multiple_character_property_is_provided(): void
{
$this->expectException(HL7Exception::class);
$this->expectExceptionMessage("Parameter should be a single character. Received: 'aa'");
Expand Down
Loading

0 comments on commit 6fdc319

Please sign in to comment.