Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit 287455d

Browse files
asgrimXerkus
authored andcommitted
Additional test case for canCreate when no constructor for class
1 parent 6a231ee commit 287455d

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/AbstractFactory/ReflectionBasedAbstractFactory.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,7 @@ private function canCallConstructor(string $requestedName) : bool
141141
{
142142
$constructor = (new ReflectionClass($requestedName))->getConstructor();
143143

144-
if ($constructor === null) {
145-
return true;
146-
}
147-
148-
return $constructor->isPublic();
144+
return $constructor === null || $constructor->isPublic();
149145
}
150146

151147
/**

test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ public function testCanCreateReturnsFalseWhenConstructorIsPrivate()
5151
);
5252
}
5353

54+
public function testCanCreateReturnsTrueWhenClassHasNoConstructor() : void
55+
{
56+
self::assertTrue(
57+
(new ReflectionBasedAbstractFactory())->canCreate(
58+
$this->container->reveal(),
59+
TestAsset\ClassWithNoConstructor::class
60+
),
61+
'ReflectionBasedAbstractFactory should be able to instantiate a class without a constructor'
62+
);
63+
}
64+
5465
public function testFactoryInstantiatesClassDirectlyIfItHasNoConstructor()
5566
{
5667
$factory = new ReflectionBasedAbstractFactory();

0 commit comments

Comments
 (0)