From fc414a70ea18f55ccb66c63c5b296ba33604ccc2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 11 Jul 2023 00:41:16 +0000 Subject: [PATCH 01/11] Lock file maintenance Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Ian Foulds --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index a523e83..a02aa12 100644 --- a/composer.lock +++ b/composer.lock @@ -2544,16 +2544,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.2.3", + "version": "10.2.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "35c8cac1734ede2ae354a6644f7088356ff5b08e" + "reference": "68484779b5a2ed711fbdeba6ca01910d87acdff2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/35c8cac1734ede2ae354a6644f7088356ff5b08e", - "reference": "35c8cac1734ede2ae354a6644f7088356ff5b08e", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/68484779b5a2ed711fbdeba6ca01910d87acdff2", + "reference": "68484779b5a2ed711fbdeba6ca01910d87acdff2", "shasum": "" }, "require": { @@ -2625,7 +2625,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.3" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.4" }, "funding": [ { @@ -2641,7 +2641,7 @@ "type": "tidelift" } ], - "time": "2023-06-30T06:17:38+00:00" + "time": "2023-07-10T04:06:08+00:00" }, { "name": "psalm/plugin-phpunit", From 5cee2bec757425a4a625412be3f61fa27c636f79 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 15 Jul 2023 00:36:20 +0000 Subject: [PATCH 02/11] Lock file maintenance Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Ian Foulds --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index a02aa12..7341afd 100644 --- a/composer.lock +++ b/composer.lock @@ -2544,16 +2544,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.2.4", + "version": "10.2.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "68484779b5a2ed711fbdeba6ca01910d87acdff2" + "reference": "15a89f123d8ca9c1e1598d6d87a56a8bf28c72cd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/68484779b5a2ed711fbdeba6ca01910d87acdff2", - "reference": "68484779b5a2ed711fbdeba6ca01910d87acdff2", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/15a89f123d8ca9c1e1598d6d87a56a8bf28c72cd", + "reference": "15a89f123d8ca9c1e1598d6d87a56a8bf28c72cd", "shasum": "" }, "require": { @@ -2625,7 +2625,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.4" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.5" }, "funding": [ { @@ -2641,7 +2641,7 @@ "type": "tidelift" } ], - "time": "2023-07-10T04:06:08+00:00" + "time": "2023-07-14T04:18:47+00:00" }, { "name": "psalm/plugin-phpunit", From d526684d0857d9654ab90b7244e261a8eb844670 Mon Sep 17 00:00:00 2001 From: George Steel Date: Sat, 15 Jul 2023 21:47:56 +0100 Subject: [PATCH 03/11] Remove trailing spaces Signed-off-by: George Steel Signed-off-by: Ian Foulds --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 957c3f5..eab81a2 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,19 @@ [![Psalm coverage](https://shepherd.dev/github/laminas/laminas-hydrator/coverage.svg?)](https://shepherd.dev/github/laminas/laminas-hydrator) > ## πŸ‡·πŸ‡Ί Русским Π³Ρ€Π°ΠΆΠ΄Π°Π½Π°ΠΌ -> +> > ΠœΡ‹, участники Laminas, Ρ€ΠΎΠ΄ΠΈΠ»ΠΈΡΡŒ ΠΈ ΠΆΠΈΠ²Π΅ΠΌ Π² Ρ€Π°Π·Π½Ρ‹Ρ… странах. Π£ ΠΌΠ½ΠΎΠ³ΠΈΡ… ΠΈΠ· нас Π΅ΡΡ‚ΡŒ Π΄Ρ€ΡƒΠ·ΡŒΡ, родствСнники ΠΈ ΠΊΠΎΠ»Π»Π΅Π³ΠΈ ΠΊΠ°ΠΊ Π² России, Ρ‚Π°ΠΊ ΠΈ Π² Π£ΠΊΡ€Π°ΠΈΠ½Π΅. НСкоторыС ΠΈΠ· нас Ρ€ΠΎΠ΄ΠΈΠ»ΠΈΡΡŒ Π² России. НСкоторыС ΠΈΠ· нас ΠΆΠΈΠ²ΡƒΡ‚ Π² России. Π£ Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Ρ… Π±Π°Π±ΡƒΡˆΠΊΠΈ ΠΈ Π΄Π΅Π΄ΡƒΡˆΠΊΠΈ ΡΡ€Π°ΠΆΠ°Π»ΠΈΡΡŒ с Ρ„Π°ΡˆΠΈΡΡ‚Π°ΠΌΠΈ Π²ΠΎ Π’Ρ‚ΠΎΡ€ΠΎΠΉ ΠΌΠΈΡ€ΠΎΠ²ΠΎΠΉ Π²ΠΎΠΉΠ½Π΅. Π—Π΄Π΅ΡΡŒ Π½ΠΈΠΊΡ‚ΠΎ Π½Π΅ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ Ρ„Π°ΡˆΠΈΠ·ΠΌ. -> +> > Π£ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ· нас Π΅ΡΡ‚ΡŒ украинская родствСнница, которая спаслась ΠΈΠ· Π΄ΠΎΠΌΠ° вмСстС с сыном. ПоСзд задСрТался ΠΈΠ·-Π·Π° Π±ΠΎΠΌΠ±Π΅ΠΆΠΊΠΈ Π½Π° Π΄ΠΎΡ€ΠΎΠ³Π΅ Π²ΠΏΠ΅Ρ€Π΅Π΄ΠΈ. Π£ нас Π΅ΡΡ‚ΡŒ Π΄Ρ€ΡƒΠ·ΡŒΡ, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ прячутся Π² Π±ΠΎΠΌΠ±ΠΎΡƒΠ±Π΅ΠΆΠΈΡ‰Π°Ρ…. ΠœΡ‹ с Ρ‚Ρ€Π΅Π²ΠΎΠ³ΠΎΠΉ ΠΆΠ΄Π΅ΠΌ вСсточки ΠΎΡ‚ Π½ΠΈΡ… послС Π²ΠΎΠ·Π΄ΡƒΡˆΠ½Ρ‹Ρ… Π½Π°Π»Π΅Ρ‚ΠΎΠ², ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ бСспорядочно наносят ΡƒΠ΄Π°Ρ€Ρ‹ ΠΈ ΠΏΠΎΠΏΠ°Π΄Π°ΡŽΡ‚ ΠΏΠΎ Π±ΠΎΠ»ΡŒΠ½ΠΈΡ†Π°ΠΌ, школам, дСтским садам ΠΈ Π΄ΠΎΠΌΠ°ΠΌ. ΠœΡ‹ Π½Π΅ Π±Π΅Ρ€Π΅ΠΌ это ΠΈΠ· ΠΊΠ°ΠΊΠΈΡ…-Π»ΠΈΠ±ΠΎ БМИ. ΠœΡ‹ наблюдаСм это Π½Π°ΠΏΡ€ΡΠΌΡƒΡŽ. -> +> > Π’Ρ‹ довСряСтС Π½Π°ΠΌ достаточно, Ρ‡Ρ‚ΠΎΠ± ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ наши ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹, ΠΈ ΠΌΡ‹ просим вас Π΄ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒΡΡ Π½Π°ΠΌ вновь. ΠœΡ‹ нуТдаСмся Π² ΠΏΠΎΠΌΠΎΡ‰ΠΈ. Π’Ρ‹Ρ…ΠΎΠ΄ΠΈΡ‚Π΅ ΠΈ протСстуйтС ΠΏΡ€ΠΎΡ‚ΠΈΠ² этой бСсполСзной Π²ΠΎΠΉΠ½Ρ‹. ΠžΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚Π΅ ΠΊΡ€ΠΎΠ²ΠΎΠΏΡ€ΠΎΠ»ΠΈΡ‚ΠΈΠ΅. Π‘ΠΊΠ°ΠΆΠΈΡ‚Π΅ "НСт Π²ΠΎΠΉΠ½Π΅!" -> +> > ## πŸ‡ΊπŸ‡Έ To Citizens of Russia -> +> > We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism. -> +> > One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences. -> +> > You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!" `Laminas\Hydrator` provides utilities for mapping arrays to objects, and vice From 7693235357f34b8c2064ddcaeb0521c36ee1bae2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 18 Jul 2023 00:58:13 +0000 Subject: [PATCH 04/11] Lock file maintenance Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Ian Foulds --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 7341afd..b6f6724 100644 --- a/composer.lock +++ b/composer.lock @@ -2544,16 +2544,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.2.5", + "version": "10.2.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "15a89f123d8ca9c1e1598d6d87a56a8bf28c72cd" + "reference": "1c17815c129f133f3019cc18e8d0c8622e6d9bcd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/15a89f123d8ca9c1e1598d6d87a56a8bf28c72cd", - "reference": "15a89f123d8ca9c1e1598d6d87a56a8bf28c72cd", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1c17815c129f133f3019cc18e8d0c8622e6d9bcd", + "reference": "1c17815c129f133f3019cc18e8d0c8622e6d9bcd", "shasum": "" }, "require": { @@ -2625,7 +2625,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.5" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.6" }, "funding": [ { @@ -2641,7 +2641,7 @@ "type": "tidelift" } ], - "time": "2023-07-14T04:18:47+00:00" + "time": "2023-07-17T12:08:28+00:00" }, { "name": "psalm/plugin-phpunit", From 78ff56759afe7b7ad64725a9a5bbf8b46a200a70 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 20 Jul 2023 01:49:54 +0000 Subject: [PATCH 05/11] Lock file maintenance Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Ian Foulds --- composer.lock | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/composer.lock b/composer.lock index b6f6724..f6eb65f 100644 --- a/composer.lock +++ b/composer.lock @@ -3360,16 +3360,16 @@ }, { "name": "sebastian/global-state", - "version": "6.0.0", + "version": "6.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "aab257c712de87b90194febd52e4d184551c2d44" + "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/aab257c712de87b90194febd52e4d184551c2d44", - "reference": "aab257c712de87b90194febd52e4d184551c2d44", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/7ea9ead78f6d380d2a667864c132c2f7b83055e4", + "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4", "shasum": "" }, "require": { @@ -3409,7 +3409,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.0" + "security": "https://github.com/sebastianbergmann/global-state/security/policy", + "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.1" }, "funding": [ { @@ -3417,7 +3418,7 @@ "type": "github" } ], - "time": "2023-02-03T07:07:38+00:00" + "time": "2023-07-19T07:19:23+00:00" }, { "name": "sebastian/lines-of-code", @@ -3887,16 +3888,16 @@ }, { "name": "spatie/array-to-xml", - "version": "3.1.6", + "version": "3.2.0", "source": { "type": "git", "url": "https://github.com/spatie/array-to-xml.git", - "reference": "e210b98957987c755372465be105d32113f339a4" + "reference": "f9ab39c808500c347d5a8b6b13310bd5221e39e7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/array-to-xml/zipball/e210b98957987c755372465be105d32113f339a4", - "reference": "e210b98957987c755372465be105d32113f339a4", + "url": "https://api.github.com/repos/spatie/array-to-xml/zipball/f9ab39c808500c347d5a8b6b13310bd5221e39e7", + "reference": "f9ab39c808500c347d5a8b6b13310bd5221e39e7", "shasum": "" }, "require": { @@ -3934,7 +3935,7 @@ "xml" ], "support": { - "source": "https://github.com/spatie/array-to-xml/tree/3.1.6" + "source": "https://github.com/spatie/array-to-xml/tree/3.2.0" }, "funding": [ { @@ -3946,7 +3947,7 @@ "type": "github" } ], - "time": "2023-05-11T14:04:07+00:00" + "time": "2023-07-19T18:30:26+00:00" }, { "name": "squizlabs/php_codesniffer", From 97b9083cd4568862c60d8f479da8034ec3dfd3d6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 27 Jul 2023 00:48:13 +0000 Subject: [PATCH 06/11] Lock file maintenance Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Ian Foulds --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index f6eb65f..78fc863 100644 --- a/composer.lock +++ b/composer.lock @@ -2224,16 +2224,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "10.1.2", + "version": "10.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "db1497ec8dd382e82c962f7abbe0320e4882ee4e" + "reference": "be1fe461fdc917de2a29a452ccf2657d325b443d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/db1497ec8dd382e82c962f7abbe0320e4882ee4e", - "reference": "db1497ec8dd382e82c962f7abbe0320e4882ee4e", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/be1fe461fdc917de2a29a452ccf2657d325b443d", + "reference": "be1fe461fdc917de2a29a452ccf2657d325b443d", "shasum": "" }, "require": { @@ -2290,7 +2290,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.2" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.3" }, "funding": [ { @@ -2298,7 +2298,7 @@ "type": "github" } ], - "time": "2023-05-22T09:04:27+00:00" + "time": "2023-07-26T13:45:28+00:00" }, { "name": "phpunit/php-file-iterator", From 05116abd48cf0108518ae67550ef9799237ae2b7 Mon Sep 17 00:00:00 2001 From: Ian Foulds Date: Sun, 1 Oct 2023 17:22:49 +0100 Subject: [PATCH 07/11] Buf fix fir issue #113 - Use static instead of self. Signed-off-by: Ian Foulds --- src/ReflectionHydrator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ReflectionHydrator.php b/src/ReflectionHydrator.php index 9718743..a94cc6c 100644 --- a/src/ReflectionHydrator.php +++ b/src/ReflectionHydrator.php @@ -24,7 +24,7 @@ class ReflectionHydrator extends AbstractHydrator public function extract(object $object): array { $result = []; - foreach (self::getReflProperties($object) as $property) { + foreach (static::getReflProperties($object) as $property) { $propertyName = $this->extractName($property->getName(), $object); if (! $this->getCompositeFilter()->filter($propertyName)) { continue; @@ -44,7 +44,7 @@ public function extract(object $object): array */ public function hydrate(array $data, object $object) { - $reflProperties = self::getReflProperties($object); + $reflProperties = static::getReflProperties($object); foreach ($data as $key => $value) { $name = $this->hydrateName($key, $data); if (isset($reflProperties[$name])) { From a4c7c73a2f3e0804491cb9cf33769b64850ffee4 Mon Sep 17 00:00:00 2001 From: Ian Foulds Date: Sun, 1 Oct 2023 17:24:38 +0100 Subject: [PATCH 08/11] Revert "Buf fix fir issue #113 - Use static instead of self." This reverts commit f7c9c358e20768e9b2e812ef10d809bfa3c11a74. Signed-off-by: Ian Foulds --- src/ReflectionHydrator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ReflectionHydrator.php b/src/ReflectionHydrator.php index a94cc6c..9718743 100644 --- a/src/ReflectionHydrator.php +++ b/src/ReflectionHydrator.php @@ -24,7 +24,7 @@ class ReflectionHydrator extends AbstractHydrator public function extract(object $object): array { $result = []; - foreach (static::getReflProperties($object) as $property) { + foreach (self::getReflProperties($object) as $property) { $propertyName = $this->extractName($property->getName(), $object); if (! $this->getCompositeFilter()->filter($propertyName)) { continue; @@ -44,7 +44,7 @@ public function extract(object $object): array */ public function hydrate(array $data, object $object) { - $reflProperties = static::getReflProperties($object); + $reflProperties = self::getReflProperties($object); foreach ($data as $key => $value) { $name = $this->hydrateName($key, $data); if (isset($reflProperties[$name])) { From 29850d992fdb1c069818bdd7c2bcc3e66808d05e Mon Sep 17 00:00:00 2001 From: Ian Foulds Date: Sun, 1 Oct 2023 17:39:49 +0100 Subject: [PATCH 09/11] Fix for RFC #114 - Recursively add parent properties if specified. Signed-off-by: Ian Foulds --- src/ReflectionHydrator.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/ReflectionHydrator.php b/src/ReflectionHydrator.php index 9718743..e64e96e 100644 --- a/src/ReflectionHydrator.php +++ b/src/ReflectionHydrator.php @@ -21,10 +21,10 @@ class ReflectionHydrator extends AbstractHydrator * * {@inheritDoc} */ - public function extract(object $object): array + public function extract(object $object, bool $includeParentProperties = false): array { $result = []; - foreach (self::getReflProperties($object) as $property) { + foreach (self::getReflProperties($object, $includeParentProperties) as $property) { $propertyName = $this->extractName($property->getName(), $object); if (! $this->getCompositeFilter()->filter($propertyName)) { continue; @@ -42,9 +42,9 @@ public function extract(object $object): array * * {@inheritDoc} */ - public function hydrate(array $data, object $object) + public function hydrate(array $data, object $object, bool $includeParentProperties = false) { - $reflProperties = self::getReflProperties($object); + $reflProperties = self::getReflProperties($object, $includeParentProperties); foreach ($data as $key => $value) { $name = $this->hydrateName($key, $data); if (isset($reflProperties[$name])) { @@ -60,21 +60,23 @@ public function hydrate(array $data, object $object) * * @return ReflectionProperty[] */ - protected static function getReflProperties(object $input): array + protected static function getReflProperties(object $input, bool $includeParentProperties): array { - $class = $input::class; + $class = get_class($input); if (isset(static::$reflProperties[$class])) { return static::$reflProperties[$class]; } static::$reflProperties[$class] = []; - $reflClass = new ReflectionClass($class); - $reflProperties = $reflClass->getProperties(); + $reflClass = new ReflectionClass($class); - foreach ($reflProperties as $property) { - static::$reflProperties[$class][$property->getName()] = $property; - } + do { + foreach ($reflClass->getProperties() as $property) { + $property->setAccessible(true); + static::$reflProperties[$class][$property->getName()] = $property; + } + } while ($includeParentProperties === true && ($reflClass = $reflClass->getParentClass()) !== false); return static::$reflProperties[$class]; } From 4db52ca37044aef4713c1332e62d6084ec84707d Mon Sep 17 00:00:00 2001 From: Ian Foulds Date: Tue, 3 Oct 2023 15:58:11 +0100 Subject: [PATCH 10/11] Add tests for extended class extraction and hydration. Signed-off-by: Ian Foulds --- test/ReflectionHydratorTest.php | 50 +++++++++++++++++-- test/TestAsset/ReflectionHydratorTestData.php | 11 ++++ 2 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 test/TestAsset/ReflectionHydratorTestData.php diff --git a/test/ReflectionHydratorTest.php b/test/ReflectionHydratorTest.php index 4b2fff8..83f0f59 100644 --- a/test/ReflectionHydratorTest.php +++ b/test/ReflectionHydratorTest.php @@ -5,6 +5,7 @@ namespace LaminasTest\Hydrator; use Laminas\Hydrator\ReflectionHydrator; +use LaminasTest\Hydrator\TestAsset\ReflectionHydratorTestData; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use ReflectionProperty; @@ -61,10 +62,7 @@ public function testHydrateRaisesExceptionForInvalidArgument(): void public function testCanExtractFromAnonymousClass(): void { - $instance = new class { - private string $foo = 'bar'; - private string $bar = 'baz'; - }; + $instance = new ReflectionHydratorTestData(); $this->assertSame([ 'foo' => 'bar', 'bar' => 'baz', @@ -83,4 +81,48 @@ public function testCanHydrateAnonymousObject(): void $r = new ReflectionProperty($hydrated, 'foo'); $this->assertSame('bar', $r->getValue($hydrated)); } + + public function testCanExtractFromExtendedClass(): void + { + $instance = new class extends ReflectionHydratorTestData { + }; + $this->assertSame([ + 'foo' => 'bar', + 'bar' => 'baz', + ], $this->hydrator->extract($instance, true)); + } + + public function testFailToExtractFromExtendedClass(): void + { + $instance = new class extends ReflectionHydratorTestData { + }; + $this->assertNotSame([ + 'foo' => 'bar', + 'bar' => 'baz', + ], $this->hydrator->extract($instance, false)); + } + + public function testCanHydrateExtendedClass(): void + { + $instance = new class extends ReflectionHydratorTestData { + }; + + $hydrated = $this->hydrator->hydrate(['foo' => 'foo-foo'], $instance, true); + + $this->assertSame($instance, $hydrated); + $r = new ReflectionProperty(get_parent_class($hydrated), 'foo'); + $this->assertSame('foo-foo', $r->getValue($hydrated)); + } + + public function testFailToHydrateExtendedClass(): void + { + $instance = new class extends ReflectionHydratorTestData { + }; + + $hydrated = $this->hydrator->hydrate(['foo' => 'foo-foo'], $instance, false); + + $this->assertSame($instance, $hydrated); + $r = new ReflectionProperty(get_parent_class($hydrated), 'foo'); + $this->assertSame('bar', $r->getValue($hydrated)); + } } diff --git a/test/TestAsset/ReflectionHydratorTestData.php b/test/TestAsset/ReflectionHydratorTestData.php new file mode 100644 index 0000000..4be7d30 --- /dev/null +++ b/test/TestAsset/ReflectionHydratorTestData.php @@ -0,0 +1,11 @@ + Date: Tue, 3 Oct 2023 16:35:12 +0100 Subject: [PATCH 11/11] Fix phpcs and psalm issues. Signed-off-by: Ian Foulds --- src/ReflectionHydrator.php | 5 +++-- test/ReflectionHydratorTest.php | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ReflectionHydrator.php b/src/ReflectionHydrator.php index e64e96e..088ad91 100644 --- a/src/ReflectionHydrator.php +++ b/src/ReflectionHydrator.php @@ -62,17 +62,18 @@ public function hydrate(array $data, object $object, bool $includeParentProperti */ protected static function getReflProperties(object $input, bool $includeParentProperties): array { - $class = get_class($input); + $reflClass = new ReflectionClass($input); + $class = $reflClass->getName(); if (isset(static::$reflProperties[$class])) { return static::$reflProperties[$class]; } static::$reflProperties[$class] = []; - $reflClass = new ReflectionClass($class); do { foreach ($reflClass->getProperties() as $property) { + /** @psalm-suppress UnusedMethodCall - Bizarre, this is a void return!!! */ $property->setAccessible(true); static::$reflProperties[$class][$property->getName()] = $property; } diff --git a/test/ReflectionHydratorTest.php b/test/ReflectionHydratorTest.php index 83f0f59..03805c0 100644 --- a/test/ReflectionHydratorTest.php +++ b/test/ReflectionHydratorTest.php @@ -12,6 +12,8 @@ use stdClass; use TypeError; +use function get_parent_class; + #[CoversClass(ReflectionHydrator::class)] class ReflectionHydratorTest extends TestCase {