-
Notifications
You must be signed in to change notification settings - Fork 29
Fix build failures in develop #59
Changes from 1 commit
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 |
---|---|---|
|
@@ -63,11 +63,14 @@ public function getPosition() : int | |
*/ | ||
public function getType() : ?string | ||
{ | ||
if ($this->reflection->hasType()) { | ||
return $this->reflection->getType()->getName(); | ||
if (! $this->reflection->hasType()) { | ||
return null; | ||
} | ||
|
||
return null; | ||
$type = $this->reflection->getType(); | ||
assert($type !== 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. it has no sense if we are checking first 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. Guess i was too slow. PHPstan does not infer it correctly. Not sure if an update will change this. Might try this as well- |
||
|
||
return $type->getName(); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,17 +187,9 @@ public function testConstructionWithoutContainerUsesDefaultContainer() | |
public function testFactoryIsCreatedFromClassNameString() | ||
{ | ||
$subject = $this->createTestSubject(function () { | ||
return ['SomeClass' => StdClassFactory::class ]; | ||
return ['SomeClass' => StdClassFactory::class]; | ||
}); | ||
|
||
$this->assertSame( | ||
StdClassFactory::class, | ||
self::readAttribute($subject, 'factories')['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. This and the other assertion check the internal state of the class, which is considered bad practice and Testing the result of |
||
$this->assertInstanceOf(stdClass::class, $subject->create('SomeClass')); | ||
$this->assertInstanceOf( | ||
StdClassFactory::class, | ||
self::readAttribute($subject, 'factoryInstances')['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.
PHPstan does not infer that the returned type is not null when
hasType()
istrue
. I guess asserting not-null is safe here.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.
In my opinion this should be added then to the exceptions in phpstan configuration.
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.
I'll try a more recent version of phpstan first. Adding ignores is also something I'd like to avoid when possible.
Maybe switching to psalm would also be an option. It feels a bit more reliable in comparison. At least it's type assertions and inference is quite powerful.
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.
Upgrading PHPStan does not fix it and it will result in a bigger PR.
I reverted the code change and added an exclude to phpstan.neon, but this is awful. I'd like to rewrite this method like this:
What do you think?