diff --git a/composer.json b/composer.json index d1f7404..1bf4ffc 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,9 @@ "phpstan/phpstan-deprecation-rules": "^1.2.1", "phpstan/phpstan-symfony": "^1.4.14", "phpunit/phpunit": "^11.5.15", - "thecodingmachine/safe": "^2 || ^3.0" + "thecodingmachine/safe": "^2 || ^3.0", + "mockery/mockery": "^1.6", + "phpstan/phpstan-mockery": "^1.1" }, "config": { "allow-plugins": { diff --git a/src/Library/LibraryBuilder.php b/src/Library/LibraryBuilder.php index 0509f0b..1476a57 100644 --- a/src/Library/LibraryBuilder.php +++ b/src/Library/LibraryBuilder.php @@ -61,6 +61,9 @@ public static function solveDeps(ResourceInterface $resource, PintoMapping $pint } } + // Regular is good for objects. + $deps = \array_unique($deps, \SORT_REGULAR); + if ([] === $deps) { return DependencyCollection::create([]); } diff --git a/tests/PintoDependenciesTest.php b/tests/PintoDependenciesTest.php index 31ed5a4..34c8832 100644 --- a/tests/PintoDependenciesTest.php +++ b/tests/PintoDependenciesTest.php @@ -11,9 +11,11 @@ use Pinto\Library\DependencyCollection; use Pinto\Library\LibraryBuilder; use Pinto\List\Resource\ObjectListEnumResource; +use Pinto\Resource\ResourceInterface; use Pinto\tests\fixtures\Lists\DependencyOn\PintoListDependencies; use Pinto\tests\fixtures\Lists\DependencyOn\PintoListDependenciesHierarchyChild; use Pinto\tests\fixtures\Lists\DependencyOn\PintoListDependenciesHierarchyParent; +use Pinto\tests\fixtures\Lists\PintoList; use Pinto\tests\fixtures\Objects\DependencyOn\PintoObjectDependencyOnChild; use Pinto\tests\fixtures\Objects\DependencyOn\PintoObjectDependencyOnParent; @@ -102,4 +104,28 @@ public function testDependencyOnParent(): void ObjectListEnumResource::createFromEnum(PintoListDependenciesHierarchyParent::Parent), ]), LibraryBuilder::solveDeps(PintoListDependenciesHierarchyChild::Child, $pintoMapping)); } + + public function testDeduplicateDependencies(): void + { + $objectListEnum = PintoList::Pinto_Object; + $resource = \Mockery::mock(ResourceInterface::class); + $resource->expects('dependencies')->andReturn([ + new DependencyOn(dependency: $objectListEnum), + new DependencyOn(dependency: $objectListEnum), + ]); + $pintoMapping = new \Pinto\PintoMapping( + resources: [ + 'untestedKey' => ObjectListEnumResource::createFromEnum($objectListEnum), + ], + definitions: [], + buildInvokers: [], + types: [], + lsbFactoryCanonicalObjectClasses: [], + ); + + $dependencyCollection = LibraryBuilder::solveDeps($resource, $pintoMapping); + static::assertEquals([ + ObjectListEnumResource::createFromEnum($objectListEnum), + ], \iterator_to_array($dependencyCollection)); + } }