Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Fix build failures in develop #59

Merged
merged 3 commits into from Dec 31, 2019

Conversation

tux-rampage
Copy link
Contributor

The Hotfix #56 introduced build failures on develop. This PR targets to fix them.

  • Is this related to quality assurance?

}

return null;
$type = $this->reflection->getType();
assert($type !== null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has no sense

if we are checking first hasType() then getType() can't be null

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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-

$this->assertInstanceOf(
StdClassFactory::class,
self::readAttribute($subject, 'factoryInstances')['SomeClass'] ?? null
);
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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....).

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
The question is: do we really need this kind of assertion, or could we do better with infection and benchmark testing here (two tools I'd like to be added anyways).

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

@tux-rampage tux-rampage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some info about the motivation of my changes

}

return null;
$type = $this->reflection->getType();
assert($type !== null);
Copy link
Contributor Author

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() is true. I guess asserting not-null is safe here.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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:

    public function getType() : ?string
    {
        $type = $this->reflection->getType();
        return $type !== null ? $type->getName() : null;
    }

What do you think?

$this->assertSame(
StdClassFactory::class,
self::readAttribute($subject, 'factories')['SomeClass'] ?? null
);
Copy link
Contributor Author

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.

@michalbundyra michalbundyra merged commit f3bf830 into zendframework:develop Dec 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants