From b8db0695ce3c140e5b4fdff477f13bb4403fea15 Mon Sep 17 00:00:00 2001 From: Smoren Date: Fri, 16 Jun 2023 12:31:53 +0300 Subject: [PATCH] Proxy for writing and reading object properties. --- src/Components/NestedAccessor.php | 10 ++- src/Helpers/ContainerAccessHelper.php | 6 +- src/Helpers/ObjectAccessHelper.php | 8 ++- src/Interfaces/ProxyInterface.php | 20 ++++++ src/Structs/ObjectPropertyProxy.php | 54 ++++++++++++++++ .../unit/ContainerAccessHelper/DeleteTest.php | 12 ++-- .../unit/ContainerAccessHelper/ExistsTest.php | 6 +- .../unit/ContainerAccessHelper/GetRefTest.php | 4 +- tests/unit/ContainerAccessHelper/GetTest.php | 12 ++-- tests/unit/ContainerAccessHelper/SetTest.php | 6 +- .../ClassWithAccessibleProperties.php | 48 +++++++++----- .../NestedAccessorDeleteTest.php | 6 +- .../NestedAccessor/NestedAccessorSetTest.php | 37 +++++++++++ .../NestedAccessorUpdateTest.php | 63 ++++++++++++------- .../ObjectAccessHelper/GetPropertyRefTest.php | 58 +++++++++++++++-- .../GetPropertyValueTest.php | 12 ++-- .../unit/ObjectAccessHelper/HasMethodTest.php | 12 ++-- .../ObjectAccessHelper/HasPropertyTest.php | 6 +- .../HasPublicMethodTest.php | 12 ++-- .../HasPublicPropertyTest.php | 6 +- .../HasReadablePropertyTest.php | 6 +- .../HasWritablePropertyTest.php | 6 +- .../SetPropertyValueTest.php | 6 +- 23 files changed, 308 insertions(+), 108 deletions(-) create mode 100644 src/Interfaces/ProxyInterface.php create mode 100644 src/Structs/ObjectPropertyProxy.php diff --git a/src/Components/NestedAccessor.php b/src/Components/NestedAccessor.php index f1e8908..d15b54d 100644 --- a/src/Components/NestedAccessor.php +++ b/src/Components/NestedAccessor.php @@ -9,6 +9,7 @@ use Smoren\Schemator\Exceptions\PathNotWritableException; use Smoren\Schemator\Helpers\ContainerAccessHelper; use Smoren\Schemator\Interfaces\NestedAccessorInterface; +use Smoren\Schemator\Interfaces\ProxyInterface; /** * @implements NestedAccessorInterface @@ -86,7 +87,12 @@ public function get($path = null, bool $strict = true) public function set($path, $value): self { $source = &$this->getRef($this->getPathStack($path)); - $source = $value; + + if ($source instanceof ProxyInterface) { + $source->setValue($value); + } else { + $source = $value; + } return $this; } @@ -202,7 +208,7 @@ protected function cutPathTail($path): array * * @param string[] $pathStack * - * @return mixed + * @return mixed|ProxyInterface * * @throws PathNotWritableException when path is not writable. */ diff --git a/src/Helpers/ContainerAccessHelper.php b/src/Helpers/ContainerAccessHelper.php index 4217011..6455142 100644 --- a/src/Helpers/ContainerAccessHelper.php +++ b/src/Helpers/ContainerAccessHelper.php @@ -5,6 +5,8 @@ namespace Smoren\Schemator\Helpers; use ArrayAccess; +use Smoren\Schemator\Interfaces\ProxyInterface; +use Smoren\Schemator\Structs\ObjectPropertyProxy; use stdClass; /** @@ -51,7 +53,7 @@ public static function get($container, $key, $defaultValue = null) * @param TKey $key * @param TValue|null $defaultValue * - * @return TValue|null + * @return TValue|ProxyInterface|null * * @throws \InvalidArgumentException */ @@ -286,7 +288,7 @@ protected static function getFromObject(object $container, $key, $defaultValue) * @param TKey $key * @param TValue|null $defaultValue * - * @return TValue|null + * @return TValue|ProxyInterface|null * * @throws \InvalidArgumentException */ diff --git a/src/Helpers/ObjectAccessHelper.php b/src/Helpers/ObjectAccessHelper.php index 93ebb7f..2abadce 100644 --- a/src/Helpers/ObjectAccessHelper.php +++ b/src/Helpers/ObjectAccessHelper.php @@ -6,6 +6,8 @@ use ReflectionMethod; use ReflectionProperty; +use Smoren\Schemator\Interfaces\ProxyInterface; +use Smoren\Schemator\Structs\ObjectPropertyProxy; use stdClass; /** @@ -46,7 +48,7 @@ public static function getPropertyValue(object $object, string $propertyName) * @param string $propertyName * @param mixed $defaultValue * - * @return mixed + * @return mixed|ProxyInterface * * @throws \InvalidArgumentException */ @@ -61,8 +63,8 @@ public static function &getPropertyRef(object &$object, string $propertyName, $d return $object->{$propertyName}; } - $className = get_class($object); - throw new \InvalidArgumentException("Property '{$className}::{$propertyName}' is not readable"); + $proxy = new ObjectPropertyProxy($object, $propertyName); + return $proxy; } /** diff --git a/src/Interfaces/ProxyInterface.php b/src/Interfaces/ProxyInterface.php new file mode 100644 index 0000000..0052c10 --- /dev/null +++ b/src/Interfaces/ProxyInterface.php @@ -0,0 +1,20 @@ + + */ +class ObjectPropertyProxy implements ProxyInterface +{ + /** + * @var T + */ + protected object $object; + protected string $propertyName; + + /** + * @param T $object + * @param string $propertyName + */ + public function __construct(object $object, string $propertyName) + { + $this->object = $object; + $this->propertyName = $propertyName; + } + + /** + * @return mixed + */ + public function getValue() + { + if (!ObjectAccessHelper::hasReadableProperty($this->object, $this->propertyName)) { + $className = get_class($this->object); + throw new \BadMethodCallException("Property '{$className}::{$this->propertyName}' is not readable"); + } + return ObjectAccessHelper::getPropertyValue($this->object, $this->propertyName); + } + + /** + * @param mixed $value + * @return void + */ + public function setValue($value): void + { + if (!ObjectAccessHelper::hasWritableProperty($this->object, $this->propertyName)) { + $className = get_class($this->object); + throw new \BadMethodCallException("Property '{$className}::{$this->propertyName}' is not writable"); + } + ObjectAccessHelper::setPropertyValue($this->object, $this->propertyName, $value); + } +} diff --git a/tests/unit/ContainerAccessHelper/DeleteTest.php b/tests/unit/ContainerAccessHelper/DeleteTest.php index e4c98de..9df9ae1 100644 --- a/tests/unit/ContainerAccessHelper/DeleteTest.php +++ b/tests/unit/ContainerAccessHelper/DeleteTest.php @@ -123,16 +123,16 @@ public function errorDataProvider(): array [new ClassWithAccessibleProperties(), 'unknownProperty'], [new ClassWithAccessibleProperties(), 'publicProperty'], [new ClassWithAccessibleProperties(), 'publicProperty'], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess'], [new ClassWithAccessibleProperties(), 'protectedProperty'], [new ClassWithAccessibleProperties(), 'protectedProperty'], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess'], [new ClassWithAccessibleProperties(), 'privateProperty'], [new ClassWithAccessibleProperties(), 'privateProperty'], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess'], ]; } diff --git a/tests/unit/ContainerAccessHelper/ExistsTest.php b/tests/unit/ContainerAccessHelper/ExistsTest.php index 6914096..8f91bd6 100644 --- a/tests/unit/ContainerAccessHelper/ExistsTest.php +++ b/tests/unit/ContainerAccessHelper/ExistsTest.php @@ -139,11 +139,11 @@ public function objectDataProvider(): array [new ClassWithAccessibleProperties(), '0', false], [new ClassWithAccessibleProperties(), 'unknownProperty', false], [new ClassWithAccessibleProperties(), 'publicProperty', true], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess', true], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess', true], [new ClassWithAccessibleProperties(), 'protectedProperty', false], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess', true], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess', true], [new ClassWithAccessibleProperties(), 'privateProperty', false], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess', true], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess', true], ]; } diff --git a/tests/unit/ContainerAccessHelper/GetRefTest.php b/tests/unit/ContainerAccessHelper/GetRefTest.php index 77aa9bd..89f4fc0 100644 --- a/tests/unit/ContainerAccessHelper/GetRefTest.php +++ b/tests/unit/ContainerAccessHelper/GetRefTest.php @@ -184,8 +184,8 @@ public function fromObjectDataProvider(): array return [ [new ClassWithAccessibleProperties(), 'publicProperty', null, 1], [new ClassWithAccessibleProperties(), 'publicProperty', 42, 1], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess', null, 2], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess', 42, 2], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess', null, 2], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess', 42, 2], ]; } diff --git a/tests/unit/ContainerAccessHelper/GetTest.php b/tests/unit/ContainerAccessHelper/GetTest.php index b36cd38..9b08835 100644 --- a/tests/unit/ContainerAccessHelper/GetTest.php +++ b/tests/unit/ContainerAccessHelper/GetTest.php @@ -166,16 +166,16 @@ public function fromObjectDataProvider(): array [new ClassWithAccessibleProperties(), 'unknownProperty', 42, 42], [new ClassWithAccessibleProperties(), 'publicProperty', null, 1], [new ClassWithAccessibleProperties(), 'publicProperty', 42, 1], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess', null, 2], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess', 42, 2], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess', null, 2], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess', 42, 2], [new ClassWithAccessibleProperties(), 'protectedProperty', null, null], [new ClassWithAccessibleProperties(), 'protectedProperty', 42, 42], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess', null, 4], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess', 42, 4], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess', null, 4], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess', 42, 4], [new ClassWithAccessibleProperties(), 'privateProperty', null, null], [new ClassWithAccessibleProperties(), 'privateProperty', 42, 42], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess', null, 6], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess', 42, 6], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess', null, 6], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess', 42, 6], ]; } diff --git a/tests/unit/ContainerAccessHelper/SetTest.php b/tests/unit/ContainerAccessHelper/SetTest.php index 2302bc4..c0ca821 100644 --- a/tests/unit/ContainerAccessHelper/SetTest.php +++ b/tests/unit/ContainerAccessHelper/SetTest.php @@ -159,9 +159,9 @@ public function toObjectDataProvider(): array { return [ [new ClassWithAccessibleProperties(), 'publicProperty', 42], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess', 42], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess', 42], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess', 42], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess', 42], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess', 42], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess', 42], ]; } diff --git a/tests/unit/Fixtures/ClassWithAccessibleProperties.php b/tests/unit/Fixtures/ClassWithAccessibleProperties.php index e69782c..356bfd5 100644 --- a/tests/unit/Fixtures/ClassWithAccessibleProperties.php +++ b/tests/unit/Fixtures/ClassWithAccessibleProperties.php @@ -6,41 +6,59 @@ class ClassWithAccessibleProperties { + /** + * @var int + */ public int $publicProperty = 1; - public int $publicPropertyWithGetterAccess = 2; + /** + * @var int + */ protected int $protectedProperty = 3; - protected int $protectedPropertyWithGetterAccess = 4; + /** + * @var int + */ private int $privateProperty = 5; - private int $privatePropertyWithGetterAccess = 6; + /** + * @var int + */ + public int $publicPropertyWithMethodsAccess = 2; + /** + * @var int + */ + protected int $protectedPropertyWithMethodsAccess = 4; + /** + * @var int + */ + private int $privatePropertyWithMethodsAccess = 6; - public function getPublicPropertyWithGetterAccess(): int + public function getPublicPropertyWithMethodsAccess(): int { - return $this->publicPropertyWithGetterAccess; + return $this->publicPropertyWithMethodsAccess; } - public function setPublicPropertyWithGetterAccess(int $value): void + public function setPublicPropertyWithMethodsAccess(int $value): void { - $this->publicPropertyWithGetterAccess = $value; + $this->publicPropertyWithMethodsAccess = $value; } - public function getProtectedPropertyWithGetterAccess(): int + public function getProtectedPropertyWithMethodsAccess(): int { - return $this->protectedPropertyWithGetterAccess; + return $this->protectedPropertyWithMethodsAccess; } - public function setProtectedPropertyWithGetterAccess(int $value): void + public function setProtectedPropertyWithMethodsAccess(int $value): void { - $this->protectedPropertyWithGetterAccess = $value; + $this->protectedPropertyWithMethodsAccess = $value; } - public function getPrivatePropertyWithGetterAccess(): int + public function getPrivatePropertyWithMethodsAccess(): int { - return $this->privatePropertyWithGetterAccess; + return $this->privatePropertyWithMethodsAccess; } - public function setPrivatePropertyWithGetterAccess(int $value): void + public function setPrivatePropertyWithMethodsAccess(int $value): void { - $this->privatePropertyWithGetterAccess = $value; + $this->privatePropertyWithMethodsAccess = $value; } protected function protectedMethod(): int diff --git a/tests/unit/NestedAccessor/NestedAccessorDeleteTest.php b/tests/unit/NestedAccessor/NestedAccessorDeleteTest.php index f505c4a..073ed13 100644 --- a/tests/unit/NestedAccessor/NestedAccessorDeleteTest.php +++ b/tests/unit/NestedAccessor/NestedAccessorDeleteTest.php @@ -202,9 +202,9 @@ public function dataProviderForNotWritableError(): array { return [ [new ClassWithAccessibleProperties(), 'publicProperty'], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess'], ]; } } diff --git a/tests/unit/NestedAccessor/NestedAccessorSetTest.php b/tests/unit/NestedAccessor/NestedAccessorSetTest.php index e22f4b8..ba4fa95 100644 --- a/tests/unit/NestedAccessor/NestedAccessorSetTest.php +++ b/tests/unit/NestedAccessor/NestedAccessorSetTest.php @@ -5,6 +5,7 @@ namespace Smoren\Schemator\Tests\Unit\NestedAccessor; use Smoren\Schemator\Components\NestedAccessor; +use Smoren\Schemator\Tests\Unit\Fixtures\ClassWithAccessibleProperties; class NestedAccessorSetTest extends \Codeception\Test\Unit { @@ -223,4 +224,40 @@ public function dataProviderForStdClass(): array ], ]; } + + /** + * @dataProvider dataProviderForObject + */ + public function testObject($source, $path, $value) + { + // Given + $accessor = new NestedAccessor($source); + + // When + $accessor->set($path, $value); + + // Then + $this->assertEquals($value, $accessor->get($path)); + } + + public function dataProviderForObject(): array + { + return [ + [ + new ClassWithAccessibleProperties(), + 'protectedPropertyWithMethodsAccess', + 22, + ], + [ + ['a' => new ClassWithAccessibleProperties()], + 'a.protectedPropertyWithMethodsAccess', + 23, + ], + [ + ['a' => new ClassWithAccessibleProperties()], + 'a.privatePropertyWithMethodsAccess', + 24, + ], + ]; + } } diff --git a/tests/unit/NestedAccessor/NestedAccessorUpdateTest.php b/tests/unit/NestedAccessor/NestedAccessorUpdateTest.php index 429e737..335e891 100644 --- a/tests/unit/NestedAccessor/NestedAccessorUpdateTest.php +++ b/tests/unit/NestedAccessor/NestedAccessorUpdateTest.php @@ -101,6 +101,42 @@ public function dataProviderForStdClass(): array ]; } + /** + * @dataProvider dataProviderForObject + */ + public function testObject($source, $path, $value) + { + // Given + $accessor = new NestedAccessor($source); + + // When + $accessor->update($path, $value); + + // Then + $this->assertEquals($value, $accessor->get($path)); + } + + public function dataProviderForObject(): array + { + return [ + [ + new ClassWithAccessibleProperties(), + 'protectedPropertyWithMethodsAccess', + 22, + ], + [ + ['a' => new ClassWithAccessibleProperties()], + 'a.protectedPropertyWithMethodsAccess', + 23, + ], + [ + ['a' => new ClassWithAccessibleProperties()], + 'a.privatePropertyWithMethodsAccess', + 24, + ], + ]; + } + /** * @dataProvider dataProviderForPathNotExistError */ @@ -139,40 +175,19 @@ public function dataProviderForPathNotExistError(): array ['a', 'a', 'c'], 'value', ], - ]; - } - - /** - * @dataProvider dataProviderForPathNotWritableError - */ - public function testPathNotWritableError($source, $path, $value) - { - // Given - $accessor = new NestedAccessor($source); - - // Then - $this->expectException(PathNotWritableException::class); - - // When - $accessor->update($path, $value); - } - - public function dataProviderForPathNotWritableError(): array - { - return [ [ new ClassWithAccessibleProperties(), - 'protectedPropertyWithGetterAccess', + 'protectedProperty', 2, ], [ ['a' => new ClassWithAccessibleProperties()], - 'a.protectedPropertyWithGetterAccess', + 'a.protectedProperty', 2, ], [ ['a' => new ClassWithAccessibleProperties()], - 'a.privatePropertyWithGetterAccess', + 'a.privateProperty', 2, ], ]; diff --git a/tests/unit/ObjectAccessHelper/GetPropertyRefTest.php b/tests/unit/ObjectAccessHelper/GetPropertyRefTest.php index 8e5e7ba..7f6aa47 100644 --- a/tests/unit/ObjectAccessHelper/GetPropertyRefTest.php +++ b/tests/unit/ObjectAccessHelper/GetPropertyRefTest.php @@ -72,8 +72,8 @@ public function fromObjectSuccessDataProvider(): array return [ [new ClassWithAccessibleProperties(), 'publicProperty', 1], [new ClassWithAccessibleProperties(), 'publicProperty', 1], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess', 2], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess', 2], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess', 2], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess', 2], ]; } @@ -83,18 +83,40 @@ public function fromObjectSuccessDataProvider(): array * @return void * @dataProvider fromObjectFailDataProvider */ - public function testFromObjectFail(object $input, string $key): void + public function testFromObjectGetFail(object $input, string $key): void { + // When + $proxy = ObjectAccessHelper::getPropertyRef($input, $key); + try { - // When - ObjectAccessHelper::getPropertyRef($input, $key); + $proxy->getValue(); $this->fail(); - } catch (\InvalidArgumentException $e) { + } catch (\BadMethodCallException $e) { // Then $this->assertSame("Property '" . get_class($input) . "::{$key}' is not readable", $e->getMessage()); } } + /** + * @param object $input + * @param string $key + * @return void + * @dataProvider fromObjectFailDataProvider + */ + public function testFromObjectSetFail(object $input, string $key): void + { + // When + $proxy = ObjectAccessHelper::getPropertyRef($input, $key); + + try { + $proxy->setValue(150); + $this->fail(); + } catch (\BadMethodCallException $e) { + // Then + $this->assertSame("Property '" . get_class($input) . "::{$key}' is not writable", $e->getMessage()); + } + } + public function fromObjectFailDataProvider(): array { return [ @@ -110,4 +132,28 @@ public function fromObjectFailDataProvider(): array [new ClassWithAccessibleProperties(), 'privateProperty'], ]; } + + /** + * @param object $input + * @param string $key + * @param $expected + * @return void + * @dataProvider fromObjectProxySuccessDataProvider + */ + public function testFromObjectProxySuccess(object $input, string $key, $expected): void + { + // When + $proxy = ObjectAccessHelper::getPropertyRef($input, $key); + + // Then + $this->assertEquals($expected, $proxy->getValue()); + } + + public function fromObjectProxySuccessDataProvider(): array + { + return [ + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess', 4], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess', 6], + ]; + } } diff --git a/tests/unit/ObjectAccessHelper/GetPropertyValueTest.php b/tests/unit/ObjectAccessHelper/GetPropertyValueTest.php index 623a866..dcc032d 100644 --- a/tests/unit/ObjectAccessHelper/GetPropertyValueTest.php +++ b/tests/unit/ObjectAccessHelper/GetPropertyValueTest.php @@ -102,12 +102,12 @@ public function fromObjectSuccessDataProvider(): array return [ [new ClassWithAccessibleProperties(), 'publicProperty', 1], [new ClassWithAccessibleProperties(), 'publicProperty', 1], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess', 2], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess', 2], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess', 4], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess', 4], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess', 6], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess', 6], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess', 2], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess', 2], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess', 4], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess', 4], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess', 6], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess', 6], ]; } diff --git a/tests/unit/ObjectAccessHelper/HasMethodTest.php b/tests/unit/ObjectAccessHelper/HasMethodTest.php index 8788abd..d6b70eb 100644 --- a/tests/unit/ObjectAccessHelper/HasMethodTest.php +++ b/tests/unit/ObjectAccessHelper/HasMethodTest.php @@ -28,12 +28,12 @@ public function testFromObjectTrue(object $input, string $key): void public function fromObjectTrueDataProvider(): array { return [ - [new ClassWithAccessibleProperties(), 'getPublicPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'setPublicPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'getProtectedPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'setProtectedPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'getPrivatePropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'setPrivatePropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'getPublicPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'setPublicPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'getProtectedPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'setProtectedPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'getPrivatePropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'setPrivatePropertyWithMethodsAccess'], [new ClassWithAccessibleProperties(), 'privateMethod'], [new ClassWithAccessibleProperties(), 'privateMethod'], ]; diff --git a/tests/unit/ObjectAccessHelper/HasPropertyTest.php b/tests/unit/ObjectAccessHelper/HasPropertyTest.php index d7dfb72..9b85b1d 100644 --- a/tests/unit/ObjectAccessHelper/HasPropertyTest.php +++ b/tests/unit/ObjectAccessHelper/HasPropertyTest.php @@ -96,11 +96,11 @@ public function fromObjectTrueDataProvider(): array { return [ [new ClassWithAccessibleProperties(), 'publicProperty'], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess'], [new ClassWithAccessibleProperties(), 'protectedProperty'], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess'], [new ClassWithAccessibleProperties(), 'privateProperty'], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess'], ]; } diff --git a/tests/unit/ObjectAccessHelper/HasPublicMethodTest.php b/tests/unit/ObjectAccessHelper/HasPublicMethodTest.php index 1e88598..340b833 100644 --- a/tests/unit/ObjectAccessHelper/HasPublicMethodTest.php +++ b/tests/unit/ObjectAccessHelper/HasPublicMethodTest.php @@ -28,12 +28,12 @@ public function testFromObjectTrue(object $input, string $key): void public function fromObjectTrueDataProvider(): array { return [ - [new ClassWithAccessibleProperties(), 'getPublicPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'setPublicPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'getProtectedPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'setProtectedPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'getPrivatePropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'setPrivatePropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'getPublicPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'setPublicPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'getProtectedPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'setProtectedPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'getPrivatePropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'setPrivatePropertyWithMethodsAccess'], ]; } diff --git a/tests/unit/ObjectAccessHelper/HasPublicPropertyTest.php b/tests/unit/ObjectAccessHelper/HasPublicPropertyTest.php index 3ea4e1b..5d7bbcb 100644 --- a/tests/unit/ObjectAccessHelper/HasPublicPropertyTest.php +++ b/tests/unit/ObjectAccessHelper/HasPublicPropertyTest.php @@ -96,7 +96,7 @@ public function fromObjectTrueDataProvider(): array { return [ [new ClassWithAccessibleProperties(), 'publicProperty'], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess'], ]; } @@ -122,9 +122,9 @@ public function fromObjectFalseDataProvider(): array [new ClassWithAccessibleProperties(), '0'], [new ClassWithAccessibleProperties(), 'unknownProperty'], [new ClassWithAccessibleProperties(), 'protectedProperty'], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess'], [new ClassWithAccessibleProperties(), 'privateProperty'], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess'], ]; } } diff --git a/tests/unit/ObjectAccessHelper/HasReadablePropertyTest.php b/tests/unit/ObjectAccessHelper/HasReadablePropertyTest.php index dc13c51..41af44c 100644 --- a/tests/unit/ObjectAccessHelper/HasReadablePropertyTest.php +++ b/tests/unit/ObjectAccessHelper/HasReadablePropertyTest.php @@ -90,9 +90,9 @@ public function fromObjectTrueDataProvider(): array { return [ [new ClassWithAccessibleProperties(), 'publicProperty'], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess'], ]; } diff --git a/tests/unit/ObjectAccessHelper/HasWritablePropertyTest.php b/tests/unit/ObjectAccessHelper/HasWritablePropertyTest.php index e834575..8bd4328 100644 --- a/tests/unit/ObjectAccessHelper/HasWritablePropertyTest.php +++ b/tests/unit/ObjectAccessHelper/HasWritablePropertyTest.php @@ -96,9 +96,9 @@ public function toObjectTrueDataProvider(): array { return [ [new ClassWithAccessibleProperties(), 'publicProperty'], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess'], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess'], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess'], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess'], ]; } diff --git a/tests/unit/ObjectAccessHelper/SetPropertyValueTest.php b/tests/unit/ObjectAccessHelper/SetPropertyValueTest.php index 7a79823..41e20e3 100644 --- a/tests/unit/ObjectAccessHelper/SetPropertyValueTest.php +++ b/tests/unit/ObjectAccessHelper/SetPropertyValueTest.php @@ -75,9 +75,9 @@ public function toObjectSuccessDataProvider(): array { return [ [new ClassWithAccessibleProperties(), 'publicProperty', 42], - [new ClassWithAccessibleProperties(), 'publicPropertyWithGetterAccess', 42], - [new ClassWithAccessibleProperties(), 'protectedPropertyWithGetterAccess', 42], - [new ClassWithAccessibleProperties(), 'privatePropertyWithGetterAccess', 42], + [new ClassWithAccessibleProperties(), 'publicPropertyWithMethodsAccess', 42], + [new ClassWithAccessibleProperties(), 'protectedPropertyWithMethodsAccess', 42], + [new ClassWithAccessibleProperties(), 'privatePropertyWithMethodsAccess', 42], ]; }