From 1b5b4a670e1808448e6bf9ddbfa26b0890d14671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 31 May 2017 12:49:29 +0200 Subject: [PATCH 1/2] Enhancement: Assert that definitions with private constructors are ignored --- .../PrivateConstructor/UserDefinition.php | 30 +++++++++++++++++++ test/Unit/DefinitionsTest.php | 11 +++++++ 2 files changed, 41 insertions(+) create mode 100644 test/Unit/Asset/Definition/PrivateConstructor/UserDefinition.php diff --git a/test/Unit/Asset/Definition/PrivateConstructor/UserDefinition.php b/test/Unit/Asset/Definition/PrivateConstructor/UserDefinition.php new file mode 100644 index 0000000..d5d1848 --- /dev/null +++ b/test/Unit/Asset/Definition/PrivateConstructor/UserDefinition.php @@ -0,0 +1,30 @@ +defineEntity('Foo'); + } +} diff --git a/test/Unit/DefinitionsTest.php b/test/Unit/DefinitionsTest.php index b650b1d..3480495 100644 --- a/test/Unit/DefinitionsTest.php +++ b/test/Unit/DefinitionsTest.php @@ -73,6 +73,17 @@ public function testInIgnoresClassesWhichAreAbstract() Definitions::in(__DIR__ . '/Asset/Definition/IsAbstract')->registerWith($fixtureFactory); } + public function testInIgnoresClassesWhichHavePrivateConstructors() + { + $fixtureFactory = $this->createFixtureFactoryMock(); + + $fixtureFactory + ->expects($this->never()) + ->method($this->anything()); + + Definitions::in(__DIR__ . '/Asset/Definition/PrivateConstructor')->registerWith($fixtureFactory); + } + public function testInAcceptsClassesWhichAreAcceptable() { $fixtureFactory = $this->createFixtureFactoryMock(); From b2750d0cf0574f954aa035f8e73666939d2d0062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 31 May 2017 12:54:13 +0200 Subject: [PATCH 2/2] Fix: Ignore classes with private constructors --- src/Definitions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Definitions.php b/src/Definitions.php index 9ac86e5..2864110 100644 --- a/src/Definitions.php +++ b/src/Definitions.php @@ -58,7 +58,7 @@ public static function in($directory) continue; } - if (!$reflection->isSubclassOf(Definition::class) || $reflection->isAbstract()) { + if (!$reflection->isSubclassOf(Definition::class) || !$reflection->isInstantiable()) { continue; }