-
Notifications
You must be signed in to change notification settings - Fork 29
Fix build failures in develop #59
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ parameters: | |
level: 7 | ||
paths: | ||
- src/ | ||
ignoreErrors: | ||
- '#Cannot call method getName\(\) on ReflectionType\|null.#' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
use Prophecy\Argument; | ||
use Prophecy\Prophecy\ObjectProphecy; | ||
use Psr\Container\ContainerInterface; | ||
use ReflectionProperty; | ||
use stdClass; | ||
use Zend\Di\CodeGenerator\AbstractInjector; | ||
use Zend\Di\CodeGenerator\FactoryInterface; | ||
|
@@ -187,17 +188,22 @@ public function testConstructionWithoutContainerUsesDefaultContainer() | |
public function testFactoryIsCreatedFromClassNameString() | ||
{ | ||
$subject = $this->createTestSubject(function () { | ||
return ['SomeClass' => StdClassFactory::class ]; | ||
return ['SomeClass' => StdClassFactory::class]; | ||
}); | ||
|
||
$factoryInstancesProperty = new ReflectionProperty(AbstractInjector::class, 'factoryInstances'); | ||
$factoriesProperty = new ReflectionProperty(AbstractInjector::class, 'factories'); | ||
$factoryInstancesProperty->setAccessible(true); | ||
$factoriesProperty->setAccessible(true); | ||
|
||
$this->assertSame( | ||
StdClassFactory::class, | ||
self::readAttribute($subject, 'factories')['SomeClass'] ?? null | ||
$factoriesProperty->getValue($subject)['SomeClass'] ?? null | ||
); | ||
$this->assertInstanceOf(stdClass::class, $subject->create('SomeClass')); | ||
$this->assertInstanceOf( | ||
StdClassFactory::class, | ||
self::readAttribute($subject, 'factoryInstances')['SomeClass'] ?? null | ||
$factoryInstancesProperty->getValue($subject)['SomeClass'] ?? null | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the reason of removing these assertions? I know that probably these are not the best, as these checks attributes and we really shouldn't do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my Review comment. The test should not check the internal state and it will stop working with PHPUnit 9 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I agree it should not. The problem is that there was no any other way to check it, that's why it was done that way (and we have it in many components....). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know, and it was me who added them. We could use Reflection directly, but it still feels kinda hacky and bad. What do we want to test here? A factory class name should be accepted or more? If more: does it really add value? That's some topic where I'd like to hear @Ocramius opinion, if he could spend a minute There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michalbundyra I re-added the assertions with reflection, but I still don't think that they add any real value to the test. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the other assertion check the internal state of the class, which is considered bad practice and
readAttribute()
has been removed from phpunit (see sebastianbergmann/phpunit#3338).Testing the result of
create()
should be sufficient.