diff --git a/CHANGELOG.md b/CHANGELOG.md index 31536a44..c128717a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to `data-transfer-object` will be documented in this file +## 1.14.0 - 2021-08-31 + +- Support PHP ^8.0 ## 1.13.3 - 2020-01-29 diff --git a/composer.json b/composer.json index 1fe28c7f..3a435364 100644 --- a/composer.json +++ b/composer.json @@ -16,11 +16,11 @@ } ], "require": { - "php": "^7.1" + "php": "^7.1|^8.0" }, "require-dev": { - "larapack/dd": "^1.0", - "phpunit/phpunit": "^7.0" + "larapack/dd": "^1.1", + "phpunit/phpunit": "^7.0|^9.0" }, "autoload": { "psr-4": { diff --git a/tests/DataTransferObjectTest.php b/tests/DataTransferObjectTest.php index d8065698..e28fdde0 100644 --- a/tests/DataTransferObjectTest.php +++ b/tests/DataTransferObjectTest.php @@ -28,12 +28,13 @@ public function only_the_type_hinted_type_may_be_passed() $this->markTestSucceeded(); $this->expectException(DataTransferObjectError::class); - $this->expectExceptionMessageRegExp('/Invalid type: expected `class@anonymous[^:]+::foo` to be of type `string`, instead got value ``, which is boolean/'); new class(['foo' => false]) extends DataTransferObject { /** @var string */ public $foo; }; + + $this->assertMatchesRegularExpression('/Invalid type: expected `class@anonymous[^:]+::foo` to be of type `string`, instead got value ``, which is boolean/', $this->getExpectedExceptionMessage()); } /** @test */ @@ -81,22 +82,24 @@ public function default_values_are_supported() public function null_is_allowed_only_if_explicitly_specified() { $this->expectException(DataTransferObjectError::class); - $this->expectExceptionMessageRegExp('/Invalid type: expected `class@anonymous[^:]+::foo` to be of type `string`, instead got value `null`, which is NULL/'); new class(['foo' => null]) extends DataTransferObject { /** @var string */ public $foo; }; + + $this->assertMatchesRegularExpression('/Invalid type: expected `class@anonymous[^:]+::foo` to be of type `string`, instead got value `null`, which is NULL/', $this->getExpectedExceptionMessage()); } /** @test */ public function unknown_properties_throw_an_error() { $this->expectException(DataTransferObjectError::class); - $this->expectExceptionMessageRegExp('/Public properties `bar` not found on class@anonymous/'); new class(['bar' => null]) extends DataTransferObject { }; + + $this->assertMatchesRegularExpression('/Public properties `bar` not found on class@anonymous/', $this->getExpectedExceptionMessage()); } /** @test */ @@ -106,8 +109,8 @@ public function unknown_properties_show_a_comprehensive_error_message() new class(['foo' => null, 'bar' => null]) extends DataTransferObject { }; } catch (DataTransferObjectError $error) { - $this->assertContains('`foo`', $error->getMessage()); - $this->assertContains('`bar`', $error->getMessage()); + $this->assertStringContainsString('`foo`', $error->getMessage()); + $this->assertStringContainsString('`bar`', $error->getMessage()); } } @@ -191,7 +194,6 @@ public function classes_are_supported() $this->markTestSucceeded(); $this->expectException(DataTransferObjectError::class); - $this->expectExceptionMessageRegExp('/Invalid type: expected `class@anonymous[^:]+::foo` to be of type `\\\Spatie\\\DataTransferObject\\\Tests\\\TestClasses\\\DummyClass`, instead got value `class@anonymous[^`]+`, which is object/'); new class(['foo' => new class() { }, @@ -200,6 +202,8 @@ public function classes_are_supported() /** @var \Spatie\DataTransferObject\Tests\TestClasses\DummyClass */ public $foo; }; + + $this->assertMatchesRegularExpression('/Invalid type: expected `class@anonymous[^:]+::foo` to be of type `\\\Spatie\\\DataTransferObject\\\Tests\\\TestClasses\\\DummyClass`, instead got value `class@anonymous[^`]+`, which is object/', $this->getExpectedExceptionMessage()); } /** @test */ @@ -213,36 +217,39 @@ public function generic_collections_are_supported() $this->markTestSucceeded(); $this->expectException(DataTransferObjectError::class); - $this->expectExceptionMessageRegExp('/Invalid type: expected `class@anonymous[^:]+::foo` to be of type `\\\Spatie\\\DataTransferObject\\\Tests\\\TestClasses\\\DummyClass\[\]`, instead got value `array`, which is array/'); new class(['foo' => [new OtherClass()]]) extends DataTransferObject { /** @var \Spatie\DataTransferObject\Tests\TestClasses\DummyClass[] */ public $foo; }; + + $this->assertMatchesRegularExpression('/Invalid type: expected `class@anonymous[^:]+::foo` to be of type `\\\Spatie\\\DataTransferObject\\\Tests\\\TestClasses\\\DummyClass\[\]`, instead got value `array`, which is array/', $this->getExpectedExceptionMessage()); } /** @test */ public function an_exception_is_thrown_for_a_generic_collection_of_null() { $this->expectException(DataTransferObjectError::class); - $this->expectExceptionMessageRegExp('/Invalid type: expected `class@anonymous[^:]+::foo` to be of type `string\[\]`, instead got value `array`, which is array./'); new class(['foo' => [null]]) extends DataTransferObject { /** @var string[] */ public $foo; }; + + $this->assertMatchesRegularExpression('/Invalid type: expected `class@anonymous[^:]+::foo` to be of type `string\[\]`, instead got value `array`, which is array./', $this->getExpectedExceptionMessage()); } /** @test */ public function an_exception_is_thrown_when_property_was_not_initialised() { $this->expectException(DataTransferObjectError::class); - $this->expectExceptionMessageRegExp('/Invalid type: expected `class@anonymous[^:]+::foo` to be of type `string`, instead got value `null`, which is NULL/'); new class([]) extends DataTransferObject { /** @var string */ public $foo; }; + + $this->assertMatchesRegularExpression('/Invalid type: expected `class@anonymous[^:]+::foo` to be of type `string`, instead got value `null`, which is NULL/', $this->getExpectedExceptionMessage()); } /** @test */ @@ -424,12 +431,13 @@ public function iterable_is_supported() public function an_exception_is_thrown_for_incoherent_iterator_type() { $this->expectException(DataTransferObjectError::class); - $this->expectExceptionMessageRegExp('/Invalid type: expected `class@anonymous[^:]+::strings` to be of type `iterable`, instead got value `array`, which is array./'); new class(['strings' => ['foo', 1]]) extends DataTransferObject { /** @var iterable */ public $strings; }; + + $this->assertMatchesRegularExpression('/Invalid type: expected `class@anonymous[^:]+::strings` to be of type `iterable`, instead got value `array`, which is array./', $this->getExpectedExceptionMessage()); } /** @test */ @@ -472,8 +480,8 @@ public function array_of_dtos() $this->assertSame(1, $arrayOf[0]->testProperty); $this->assertSame(2, $arrayOf[1]->testProperty); } - - + + /** @test */ public function ignore_static_public_properties() {