From 8594980daec826709150d3b94d5d59e0199de787 Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Mon, 29 Aug 2022 12:44:45 +0200 Subject: [PATCH 1/5] fix Dynamic Properties attribute --- src/Factories/TestCaseFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index 77f71cf0..938b0d2b 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -186,7 +186,7 @@ final class TestCaseFactory use Pest\TestSuite as __PestTestSuite; $classAttributesCode - #[AllowDynamicProperties] + #[\AllowDynamicProperties] final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN { $traitsCode From 6252e288b9399f9ba1ade1fac311a3450b9dd3af Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Mon, 29 Aug 2022 12:45:08 +0200 Subject: [PATCH 2/5] add php8.2 tests --- .github/workflows/tests.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4e1381e8..f6a94d92 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,14 +8,9 @@ jobs: strategy: matrix: os: [ubuntu-latest] # (macos-latest, windows-latest) 2.x-dev is under development - php: ['8.1'] + php: ['8.1', '8.2'] dependency-version: [prefer-lowest, prefer-stable] parallel: ['', '--parallel'] - exclude: - - php: 8.1 - os: macos-latest - - php: 8.1 - os: windows-latest name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} - ${{ matrix.parallel }} From 42ceddf37475560ab55f9e8c33843eef0a27bfca Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Mon, 29 Aug 2022 12:47:31 +0200 Subject: [PATCH 3/5] fix tests --- src/Mixins/Expectation.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index ace37cf9..8c9dd99d 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -710,11 +710,11 @@ final class Expectation /** * Asserts that the value array matches the given array subset. * - * @param iterable $array + * @param iterable|object $array * * @return Expectation */ - public function toMatchArray(iterable|object $array): Expectation + public function toMatchArray(array|object $array): Expectation { if (is_object($this->value) && method_exists($this->value, 'toArray')) { $valueAsArray = $this->value->toArray(); @@ -722,6 +722,10 @@ final class Expectation $valueAsArray = (array) $this->value; } + if (is_object($array) && method_exists($array, 'toArray')) { + $array = $array->toArray(); + } + foreach ($array as $key => $value) { Assert::assertArrayHasKey($key, $valueAsArray); @@ -743,11 +747,11 @@ final class Expectation * Asserts that the value object matches a subset * of the properties of an given object. * - * @param iterable|object $object + * @param object|array $object * * @return Expectation */ - public function toMatchObject(iterable|object $object): Expectation + public function toMatchObject(object|array $object): Expectation { foreach ((array) $object as $property => $value) { if (!is_object($this->value) && !is_string($this->value)) { From 38a82cd14228a3acb7f0ab361b1a38bcf9a5e14a Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Mon, 29 Aug 2022 14:04:47 +0200 Subject: [PATCH 4/5] fix types --- src/Mixins/Expectation.php | 8 ++++---- tests/Features/Expect/toMatchObject.php | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index 8c9dd99d..61d5bf6e 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -710,11 +710,11 @@ final class Expectation /** * Asserts that the value array matches the given array subset. * - * @param iterable|object $array + * @param iterable $array * * @return Expectation */ - public function toMatchArray(array|object $array): Expectation + public function toMatchArray(iterable $array): Expectation { if (is_object($this->value) && method_exists($this->value, 'toArray')) { $valueAsArray = $this->value->toArray(); @@ -747,11 +747,11 @@ final class Expectation * Asserts that the value object matches a subset * of the properties of an given object. * - * @param object|array $object + * @param iterable $object * * @return Expectation */ - public function toMatchObject(object|array $object): Expectation + public function toMatchObject(iterable $object): Expectation { foreach ((array) $object as $property => $value) { if (!is_object($this->value) && !is_string($this->value)) { diff --git a/tests/Features/Expect/toMatchObject.php b/tests/Features/Expect/toMatchObject.php index fd2c358b..a4394e4c 100644 --- a/tests/Features/Expect/toMatchObject.php +++ b/tests/Features/Expect/toMatchObject.php @@ -17,6 +17,16 @@ test('pass', function () { ]); }); +test('pass with class', function () { + expect(new class() { + public $name = 'Nuno'; + public $email = 'enunomaduro@gmail.com'; + })->toMatchObject([ + 'name' => 'Nuno', + 'email' => 'enunomaduro@gmail.com', + ]); +}); + test('failures', function () { expect($this->user)->toMatchObject([ 'name' => 'Not the same name', From 173a72e69d994f5623f171803ed78a38944d53db Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Mon, 29 Aug 2022 15:51:22 +0200 Subject: [PATCH 5/5] revert unwanted code --- src/Mixins/Expectation.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index 61d5bf6e..d1020cae 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -722,10 +722,6 @@ final class Expectation $valueAsArray = (array) $this->value; } - if (is_object($array) && method_exists($array, 'toArray')) { - $array = $array->toArray(); - } - foreach ($array as $key => $value) { Assert::assertArrayHasKey($key, $valueAsArray);