From a7c39b26ba074a38d55cdad03231dd8147389002 Mon Sep 17 00:00:00 2001 From: Meritoo Date: Wed, 18 Sep 2019 14:51:09 +0200 Subject: [PATCH] Rename Collection class to BaseCollection. Add BaseCollection::isValidType() method to validate type of element before add it to collection. Add BaseCollection ::prepareElements() method to allow preparation of elements in custom way. --- CHANGELOG.md | 6 + VERSION | 2 +- src/Collection/BaseCollection.php | 81 ++++++++++ src/Collection/Collection.php | 36 ----- src/Collection/DateTimeCollection.php | 27 ++++ src/Collection/IntegerCollection.php | 25 +++ src/Collection/StringCollection.php | 25 +++ src/Collection/Templates.php | 10 +- src/Traits/Collection/AddTrait.php | 12 +- src/Utilities/Reflection.php | 14 +- ...lectionTest.php => BaseCollectionTest.php} | 144 +++++++++++++----- .../Collection/Collection/ArrayCollection.php | 30 ++++ tests/Collection/DateTimeCollectionTest.php | 86 +++++++++++ tests/Collection/IntegerCollectionTest.php | 85 +++++++++++ tests/Collection/StringCollectionTest.php | 86 +++++++++++ .../Reflection/ObjectsCollection.php | 34 +++++ tests/Utilities/ReflectionTest.php | 22 +-- 17 files changed, 627 insertions(+), 98 deletions(-) create mode 100644 src/Collection/BaseCollection.php delete mode 100644 src/Collection/Collection.php create mode 100644 src/Collection/DateTimeCollection.php create mode 100644 src/Collection/IntegerCollection.php create mode 100644 src/Collection/StringCollection.php rename tests/Collection/{CollectionTest.php => BaseCollectionTest.php} (79%) create mode 100644 tests/Collection/Collection/ArrayCollection.php create mode 100644 tests/Collection/DateTimeCollectionTest.php create mode 100644 tests/Collection/IntegerCollectionTest.php create mode 100644 tests/Collection/StringCollectionTest.php create mode 100644 tests/Utilities/Reflection/ObjectsCollection.php diff --git a/CHANGELOG.md b/CHANGELOG.md index f0876a2..daec50e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ Common and useful classes, methods, exceptions etc. +# 1.1.0 + +1. Rename Meritoo\Common\Collection\Collection class to Meritoo\Common\Collection\BaseCollection. +Add BaseCollection::isValidType() method to validate type of element before add it to collection. +Add BaseCollection ::prepareElements() method to allow preparation of elements in custom way. + # 1.0.6 1. Use `.env` instead of `.env.dist` diff --git a/VERSION b/VERSION index af0b7dd..9084fa2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.6 +1.1.0 diff --git a/src/Collection/BaseCollection.php b/src/Collection/BaseCollection.php new file mode 100644 index 0000000..293df6d --- /dev/null +++ b/src/Collection/BaseCollection.php @@ -0,0 +1,81 @@ + + * @copyright Meritoo + */ +abstract class BaseCollection implements Countable, ArrayAccess, IteratorAggregate +{ + use CollectionTrait; + + /** + * Class constructor + * + * @param array $elements (optional) The elements of collection + */ + public function __construct(array $elements = []) + { + $validated = $this->getElementsWithValidType($elements); + $this->elements = $this->prepareElements($validated); + } + + /** + * Prepares elements to initialize the collection. + * Feel free to override and prepare elements in your way. + * + * @param array $elements The elements of collection to prepare + * @return array + */ + protected function prepareElements(array $elements): array + { + return $elements; + } + + /** + * Returns elements of collection with valid types + * + * @param array $elements The elements of collection to verify + * @return array + */ + protected function getElementsWithValidType(array $elements): array + { + if (empty($elements)) { + return []; + } + + $result = []; + + foreach ($elements as $index => $element) { + if (!$this->isValidType($element)) { + continue; + } + + $result[$index] = $element; + } + + return $result; + } + + /** + * Returns information if given element has valid type + * + * @param mixed $element Element of collection + * @return bool + */ + abstract protected function isValidType($element): bool; +} diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php deleted file mode 100644 index 6206ce5..0000000 --- a/src/Collection/Collection.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @copyright Meritoo - */ -class Collection implements Countable, ArrayAccess, IteratorAggregate -{ - use CollectionTrait; - - /** - * Class constructor - * - * @param array $elements (optional) The elements of collection - */ - public function __construct(array $elements = []) - { - $this->elements = $elements; - } -} diff --git a/src/Collection/DateTimeCollection.php b/src/Collection/DateTimeCollection.php new file mode 100644 index 0000000..f31c4f1 --- /dev/null +++ b/src/Collection/DateTimeCollection.php @@ -0,0 +1,27 @@ + + * @copyright Meritoo + */ +class DateTimeCollection extends BaseCollection +{ + protected function isValidType($element): bool + { + return $element instanceof DateTime; + } +} diff --git a/src/Collection/IntegerCollection.php b/src/Collection/IntegerCollection.php new file mode 100644 index 0000000..d284f71 --- /dev/null +++ b/src/Collection/IntegerCollection.php @@ -0,0 +1,25 @@ + + * @copyright Meritoo + */ +class IntegerCollection extends BaseCollection +{ + protected function isValidType($element): bool + { + return is_int($element); + } +} diff --git a/src/Collection/StringCollection.php b/src/Collection/StringCollection.php new file mode 100644 index 0000000..2d9a191 --- /dev/null +++ b/src/Collection/StringCollection.php @@ -0,0 +1,25 @@ + + * @copyright Meritoo + */ +class StringCollection extends BaseCollection +{ + protected function isValidType($element): bool + { + return is_string($element); + } +} diff --git a/src/Collection/Templates.php b/src/Collection/Templates.php index 0ebe86c..dbda2d0 100644 --- a/src/Collection/Templates.php +++ b/src/Collection/Templates.php @@ -19,7 +19,7 @@ use Meritoo\Common\ValueObject\Template; * @author Meritoo * @copyright Meritoo */ -class Templates extends Collection +class Templates extends BaseCollection { /** * Finds and returns template with given index @@ -61,4 +61,12 @@ class Templates extends Collection return $result; } + + /** + * {@inheritdoc} + */ + protected function isValidType($element): bool + { + return $element instanceof Template; + } } diff --git a/src/Traits/Collection/AddTrait.php b/src/Traits/Collection/AddTrait.php index 0714ec9..1cda8b2 100644 --- a/src/Traits/Collection/AddTrait.php +++ b/src/Traits/Collection/AddTrait.php @@ -8,7 +8,7 @@ namespace Meritoo\Common\Traits\Collection; -use Meritoo\Common\Collection\Collection; +use Meritoo\Common\Collection\BaseCollection; /** * Trait for the Collection with add*() methods @@ -26,6 +26,10 @@ trait AddTrait */ public function add($element, $index = null): void { + if (!$this->isValidType($element)) { + return; + } + if (null === $index || '' === $index) { $this->elements[] = $element; @@ -38,9 +42,9 @@ trait AddTrait /** * Adds given elements (at the end of collection) * - * @param array|Collection $elements The elements to add - * @param bool|false $useIndexes (optional) If is set to true, indexes of given elements will be used in - * this collection. Otherwise - not. + * @param array|BaseCollection $elements The elements to add + * @param bool $useIndexes (optional) If is set to true, indexes of given elements will be used in + * this collection. Otherwise - not. */ public function addMultiple($elements, bool $useIndexes = false): void { diff --git a/src/Utilities/Reflection.php b/src/Utilities/Reflection.php index 96ccce7..9508ba2 100644 --- a/src/Utilities/Reflection.php +++ b/src/Utilities/Reflection.php @@ -10,7 +10,7 @@ namespace Meritoo\Common\Utilities; use Doctrine\Common\Inflector\Inflector; use Doctrine\Common\Persistence\Proxy; -use Meritoo\Common\Collection\Collection; +use Meritoo\Common\Collection\BaseCollection; use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException; use Meritoo\Common\Exception\Reflection\MissingChildClassesException; use Meritoo\Common\Exception\Reflection\NotExistingPropertyException; @@ -207,11 +207,11 @@ class Reflection * Returns values of given property for given objects. * Looks for proper getter for the property. * - * @param array|Collection|object $objects The objects that should contain given property. It may be also one - * object. - * @param string $property Name of the property that contains a value - * @param bool $force (optional) If is set to true, try to retrieve value even if the - * object does not have property. Otherwise - not. + * @param array|BaseCollection|object $objects The objects that should contain given property. It may be also one + * object. + * @param string $property Name of the property that contains a value + * @param bool $force (optional) If is set to true, try to retrieve value even if the + * object does not have property. Otherwise - not. * @return array */ public static function getPropertyValues($objects, string $property, bool $force = false): array @@ -224,7 +224,7 @@ class Reflection return []; } - if ($objects instanceof Collection) { + if ($objects instanceof BaseCollection) { $objects = $objects->toArray(); } diff --git a/tests/Collection/CollectionTest.php b/tests/Collection/BaseCollectionTest.php similarity index 79% rename from tests/Collection/CollectionTest.php rename to tests/Collection/BaseCollectionTest.php index 6eb469e..2906193 100644 --- a/tests/Collection/CollectionTest.php +++ b/tests/Collection/BaseCollectionTest.php @@ -10,9 +10,12 @@ namespace Meritoo\Test\Common\Collection; use ArrayIterator; use Generator; -use Meritoo\Common\Collection\Collection; +use Meritoo\Common\Collection\BaseCollection; +use Meritoo\Common\Collection\DateTimeCollection; +use Meritoo\Common\Collection\StringCollection; use Meritoo\Common\Test\Base\BaseTestCase; use Meritoo\Common\Type\OopVisibilityType; +use Meritoo\Test\Common\Collection\Collection\ArrayCollection; use ReflectionClass; /** @@ -22,21 +25,21 @@ use ReflectionClass; * @copyright Meritoo * * @internal - * @covers \Meritoo\Common\Collection\Collection + * @covers \Meritoo\Common\Collection\BaseCollection */ -class CollectionTest extends BaseTestCase +class BaseCollectionTest extends BaseTestCase { /** * An empty collection * - * @var Collection + * @var StringCollection */ private $emptyCollection; /** * Simple collection * - * @var Collection + * @var StringCollection */ private $simpleCollection; @@ -135,14 +138,14 @@ class CollectionTest extends BaseTestCase } /** - * @param mixed $element The element to add - * @param int $expectedCount Expected count of elements in collection - * @param int $expectedIndex Expected index of added element in collection - * @param Collection $collection The collection + * @param mixed $element The element to add + * @param int $expectedCount Expected count of elements in collection + * @param int $expectedIndex Expected index of added element in collection + * @param BaseCollection $collection The collection * * @dataProvider provideElementToAdd */ - public function testAddWithoutIndex($element, $expectedCount, $expectedIndex, Collection $collection) + public function testAddWithoutIndex($element, $expectedCount, $expectedIndex, BaseCollection $collection) { $collection->add($element); @@ -152,15 +155,15 @@ class CollectionTest extends BaseTestCase } /** - * @param mixed $element The element to add - * @param mixed $index Index of element to add - * @param int $expectedCount Expected count of elements in collection - * @param int $expectedIndex Expected index of added element in collection - * @param Collection $collection The collection + * @param mixed $element The element to add + * @param mixed $index Index of element to add + * @param int $expectedCount Expected count of elements in collection + * @param int $expectedIndex Expected index of added element in collection + * @param BaseCollection $collection The collection * * @dataProvider provideElementToAddWithIndex */ - public function testAddWithIndex($element, $index, $expectedCount, $expectedIndex, Collection $collection) + public function testAddWithIndex($element, $index, $expectedCount, $expectedIndex, BaseCollection $collection) { $collection->add($element, $index); @@ -328,7 +331,7 @@ class CollectionTest extends BaseTestCase public function testExistsVisibilityAndArguments() { - $reflectionClass = new ReflectionClass(Collection::class); + $reflectionClass = new ReflectionClass(BaseCollection::class); $method = $reflectionClass->getMethod('exists'); static::assertMethodVisibility($method, OopVisibilityType::IS_PRIVATE); @@ -336,18 +339,31 @@ class CollectionTest extends BaseTestCase } /** - * @param string $description Description of test - * @param Collection $collection Collection to search for element with given index - * @param mixed $index Index / key of the element - * @param mixed $expected Expected element with given index + * @param string $description Description of test + * @param BaseCollection $collection Collection to search for element with given index + * @param mixed $index Index / key of the element + * @param mixed $expected Expected element with given index * * @dataProvider provideElementGetByIndex */ - public function testGetByIndex($description, Collection $collection, $index, $expected) + public function testGetByIndex($description, BaseCollection $collection, $index, $expected) { static::assertEquals($expected, $collection->getByIndex($index), $description); } + /** + * @param string $description + * @param array $elements + * @param array $expected + * + * @dataProvider provideElementsToValidateType + */ + public function testGetElementsWithValidType(string $description, array $elements, array $expected): void + { + $collection = new ArrayCollection($elements); + static::assertSame($expected, $collection->toArray(), $description); + } + /** * Provides element to add to collection * @@ -359,14 +375,14 @@ class CollectionTest extends BaseTestCase 'This is test 1', 1, 0, - new Collection(), + new StringCollection(), ]; yield[ 'This is test 2', 2, 1, - new Collection([ + new StringCollection([ 'I am 1st', ]), ]; @@ -375,7 +391,7 @@ class CollectionTest extends BaseTestCase 'This is test 3', 3, 2, - new Collection([ + new StringCollection([ 'I am 1st', 'I am 2nd', ]), @@ -394,7 +410,7 @@ class CollectionTest extends BaseTestCase 'test1', 1, 'test1', - new Collection(), + new StringCollection(), ]; yield[ @@ -402,7 +418,7 @@ class CollectionTest extends BaseTestCase 'test2', 2, 'test2', - new Collection([ + new StringCollection([ 'test1' => 'I am 1st', ]), ]; @@ -412,7 +428,7 @@ class CollectionTest extends BaseTestCase null, 3, 0, - new Collection([ + new StringCollection([ 'test1' => 'I am 1st', 'test2' => 'I am 2nd', ]), @@ -423,7 +439,7 @@ class CollectionTest extends BaseTestCase '', 4, 1, - new Collection([ + new StringCollection([ 'test1' => 'I am 1st', 'test2' => 'I am 2nd', 'I am 3rd', @@ -435,7 +451,7 @@ class CollectionTest extends BaseTestCase 'test5', 5, 'test5', - new Collection([ + new StringCollection([ 'test1' => 'I am 1st', 'test2' => 'I am 2nd', 2 => 'I am 3rd', @@ -448,7 +464,7 @@ class CollectionTest extends BaseTestCase 'test2', 4, 'test2', - new Collection([ + new StringCollection([ 'test1' => 'I am 1st', 'test2' => 'I am 2nd', 2 => 'I am 3rd', @@ -461,21 +477,21 @@ class CollectionTest extends BaseTestCase { yield[ 'An empty collection and empty index', - new Collection(), + new StringCollection(), '', null, ]; yield[ 'An empty collection and non-empty index', - new Collection(), + new StringCollection(), 'test', null, ]; yield[ 'Non-empty collection and not existing index', - new Collection([ + new StringCollection([ 'lorem' => 'ipsum', 'dolor' => 'sit', ]), @@ -485,7 +501,7 @@ class CollectionTest extends BaseTestCase yield[ 'Collection with existing index', - new Collection([ + new StringCollection([ 'lorem' => 'ipsum', 'dolor' => 'sit', ]), @@ -495,7 +511,7 @@ class CollectionTest extends BaseTestCase yield[ 'Collection with existing index (collection of arrays)', - new Collection([ + new ArrayCollection([ [ 'lorem', 'ipsum', @@ -514,7 +530,7 @@ class CollectionTest extends BaseTestCase yield[ 'Collection with existing index (collection of objects)', - new Collection([ + new DateTimeCollection([ 'x' => new \DateTime(), 'y' => new \DateTime('2001-01-01'), 'z' => new \DateTime('yesterday'), @@ -524,6 +540,56 @@ class CollectionTest extends BaseTestCase ]; } + public function provideElementsToValidateType(): ?Generator + { + yield[ + 'An empty array', + [], + [], + ]; + + yield[ + 'Valid elements only', + [ + [], + [ + '123', + 456, + ], + ], + [ + [], + [ + '123', + 456, + ], + ], + ]; + + yield[ + 'Mixed elements', + [ + 1, + 'test', + '', + [], + 234, + 'test', + [ + '123', + 456, + ], + ], + [ + 3 => [], + 6 => [ + '123', + 456, + ], + ], + ]; + } + /** * {@inheritdoc} */ @@ -538,7 +604,7 @@ class CollectionTest extends BaseTestCase 345 => 'sit', ]; - $this->emptyCollection = new Collection(); - $this->simpleCollection = new Collection($this->simpleElements); + $this->emptyCollection = new StringCollection(); + $this->simpleCollection = new StringCollection($this->simpleElements); } } diff --git a/tests/Collection/Collection/ArrayCollection.php b/tests/Collection/Collection/ArrayCollection.php new file mode 100644 index 0000000..2ad9627 --- /dev/null +++ b/tests/Collection/Collection/ArrayCollection.php @@ -0,0 +1,30 @@ + + * @copyright Meritoo + * + * @internal + * @coversNothing + */ +class ArrayCollection extends BaseCollection +{ + protected function isValidType($element): bool + { + return is_array($element); + } +} diff --git a/tests/Collection/DateTimeCollectionTest.php b/tests/Collection/DateTimeCollectionTest.php new file mode 100644 index 0000000..f8cdd1c --- /dev/null +++ b/tests/Collection/DateTimeCollectionTest.php @@ -0,0 +1,86 @@ + + * @copyright Meritoo + * + * @internal + * @covers \Meritoo\Common\Collection\DateTimeCollection + */ +class DateTimeCollectionTest extends BaseTestCase +{ + public function testConstructor(): void + { + static::assertConstructorVisibilityAndArguments( + DateTimeCollection::class, + OopVisibilityType::IS_PUBLIC, + 1 + ); + } + + /** + * @param string $description + * @param array $elements + * @param array $expectedElements + * + * @dataProvider provideDifferentTypesOfElements + */ + public function testCreateWithDifferentTypesOfElements( + string $description, + array $elements, + array $expectedElements + ): void { + $collection = new DateTimeCollection($elements); + static::assertEquals($expectedElements, $collection->toArray(), $description); + } + + public function provideDifferentTypesOfElements(): ?Generator + { + yield[ + 'An empty array', + [], + [], + ]; + + yield[ + 'Valid elements only', + [ + new DateTime('2001-01-01'), + new DateTime('2001-01-02'), + ], + [ + new DateTime('2001-01-01'), + new DateTime('2001-01-02'), + ], + ]; + + yield[ + 'Mixed elements', + [ + 1, + 'test', + new DateTime('2001-01-01'), + '', + [], + 234, + new DateTime('2001-01-02'), + ], + [ + 2 => new DateTime('2001-01-01'), + 6 => new DateTime('2001-01-02'), + ], + ]; + } +} diff --git a/tests/Collection/IntegerCollectionTest.php b/tests/Collection/IntegerCollectionTest.php new file mode 100644 index 0000000..51d62be --- /dev/null +++ b/tests/Collection/IntegerCollectionTest.php @@ -0,0 +1,85 @@ + + * @copyright Meritoo + * + * @internal + * @covers \Meritoo\Common\Collection\IntegerCollection + */ +class IntegerCollectionTest extends BaseTestCase +{ + public function testConstructor(): void + { + static::assertConstructorVisibilityAndArguments( + IntegerCollection::class, + OopVisibilityType::IS_PUBLIC, + 1 + ); + } + + /** + * @param string $description + * @param array $elements + * @param array $expectedElements + * + * @dataProvider provideDifferentTypesOfElements + */ + public function testCreateWithDifferentTypesOfElements( + string $description, + array $elements, + array $expectedElements + ): void { + $collection = new IntegerCollection($elements); + static::assertSame($expectedElements, $collection->toArray(), $description); + } + + public function provideDifferentTypesOfElements(): ?\Generator + { + yield[ + 'An empty array', + [], + [], + ]; + + yield[ + 'Valid elements only', + [ + 1, + 2, + 3, + ], + [ + 1, + 2, + 3, + ], + ]; + + yield[ + 'Mixed elements', + [ + 1, + 'test', + '', + [], + 234, + 'test', + ], + [ + 0 => 1, + 4 => 234, + ], + ]; + } +} diff --git a/tests/Collection/StringCollectionTest.php b/tests/Collection/StringCollectionTest.php new file mode 100644 index 0000000..96101a5 --- /dev/null +++ b/tests/Collection/StringCollectionTest.php @@ -0,0 +1,86 @@ + + * @copyright Meritoo + * + * @internal + * @covers \Meritoo\Common\Collection\StringCollection + */ +class StringCollectionTest extends BaseTestCase +{ + public function testConstructor(): void + { + static::assertConstructorVisibilityAndArguments( + StringCollection::class, + OopVisibilityType::IS_PUBLIC, + 1 + ); + } + + /** + * @param string $description + * @param array $elements + * @param array $expectedElements + * + * @dataProvider provideDifferentTypesOfElements + */ + public function testCreateWithDifferentTypesOfElements( + string $description, + array $elements, + array $expectedElements + ): void { + $collection = new StringCollection($elements); + static::assertSame($expectedElements, $collection->toArray(), $description); + } + + public function provideDifferentTypesOfElements(): ?\Generator + { + yield[ + 'An empty array', + [], + [], + ]; + + yield[ + 'Valid elements only', + [ + '1', + 'test', + '', + ], + [ + '1', + 'test', + '', + ], + ]; + + yield[ + 'Mixed elements', + [ + 1, + 'test', + '', + [], + 234, + 'test', + ], + [ + 1 => 'test', + 2 => '', + 5 => 'test', + ], + ]; + } +} diff --git a/tests/Utilities/Reflection/ObjectsCollection.php b/tests/Utilities/Reflection/ObjectsCollection.php new file mode 100644 index 0000000..d51ea05 --- /dev/null +++ b/tests/Utilities/Reflection/ObjectsCollection.php @@ -0,0 +1,34 @@ + + * @copyright Meritoo + * + * @internal + * @coversNothing + */ +class ObjectsCollection extends BaseCollection +{ + protected function isValidType($element): bool + { + return $element instanceof A + || $element instanceof B + || $element instanceof C + || $element instanceof D + || $element instanceof F; + } +} diff --git a/tests/Utilities/ReflectionTest.php b/tests/Utilities/ReflectionTest.php index 5c5b6b1..1f9ff30 100644 --- a/tests/Utilities/ReflectionTest.php +++ b/tests/Utilities/ReflectionTest.php @@ -10,7 +10,8 @@ namespace Meritoo\Test\Common\Utilities; use DateTime; use Generator; -use Meritoo\Common\Collection\Collection; +use Meritoo\Common\Collection\BaseCollection; +use Meritoo\Common\Collection\Templates; use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException; use Meritoo\Common\Exception\Reflection\MissingChildClassesException; use Meritoo\Common\Exception\Reflection\NotExistingPropertyException; @@ -27,6 +28,7 @@ use Meritoo\Test\Common\Utilities\Reflection\G; use Meritoo\Test\Common\Utilities\Reflection\H; use Meritoo\Test\Common\Utilities\Reflection\I; use Meritoo\Test\Common\Utilities\Reflection\J; +use Meritoo\Test\Common\Utilities\Reflection\ObjectsCollection; use ReflectionProperty; use stdClass; @@ -83,13 +85,13 @@ class ReflectionTest extends BaseTestCase public function testGetClassWhileNamespaceContainsClassName(): void { self::assertEquals( - Collection::class, - Reflection::getClassName(Collection::class) + BaseCollection::class, + Reflection::getClassName(BaseCollection::class) ); self::assertEquals( - 'Collection', - Reflection::getClassName(Collection::class, true) + 'BaseCollection', + Reflection::getClassName(BaseCollection::class, true) ); } @@ -118,7 +120,7 @@ class ReflectionTest extends BaseTestCase { self::assertEquals( 'Meritoo\Common\Collection', - Reflection::getClassNamespace(Collection::class) + Reflection::getClassNamespace(BaseCollection::class) ); } @@ -320,7 +322,7 @@ class ReflectionTest extends BaseTestCase public function testGetPropertyValuesFromEmptySource(): void { self::assertEquals([], Reflection::getPropertyValues([], 'something')); - self::assertEquals([], Reflection::getPropertyValues(new Collection(), 'something')); + self::assertEquals([], Reflection::getPropertyValues(new Templates(), 'something')); } public function testGetPropertyValuesOfNotExistingPropertyFromSingleObject(): void @@ -344,7 +346,7 @@ class ReflectionTest extends BaseTestCase self::assertEquals([], Reflection::getPropertyValues($objects, 'something')); self::assertEquals([], Reflection::getPropertyValues($objects, 'something', true)); - $collection = new Collection($objects); + $collection = new ObjectsCollection($objects); self::assertEquals([], Reflection::getPropertyValues($collection, 'something')); self::assertEquals([], Reflection::getPropertyValues($collection, 'something', true)); @@ -373,7 +375,7 @@ class ReflectionTest extends BaseTestCase self::assertEquals($expected, Reflection::getPropertyValues($objects, 'city')); self::assertEquals($expected, Reflection::getPropertyValues($objects, 'city', true)); - $collection = new Collection($objects); + $collection = new ObjectsCollection($objects); self::assertEquals($expected, Reflection::getPropertyValues($collection, 'city')); self::assertEquals($expected, Reflection::getPropertyValues($collection, 'city', true)); @@ -408,7 +410,7 @@ class ReflectionTest extends BaseTestCase self::assertEquals($expected, Reflection::getPropertyValues($objects, 'g.firstName')); self::assertEquals($expected, Reflection::getPropertyValues($objects, 'g.firstName', true)); - $collection = new Collection($objects); + $collection = new ObjectsCollection($objects); self::assertEquals($expected, Reflection::getPropertyValues($collection, 'g.firstName')); self::assertEquals($expected, Reflection::getPropertyValues($collection, 'g.firstName', true));