New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Built-in assertion and mock type definitions #3708
Built-in assertion and mock type definitions #3708
Conversation
@weirdan can you give this a skim, since you worked on a lot of this stuff? |
I've used Codeception gherkin tests (with custom modules) in plugins, however using it here would introduce potential dependency problems (Codeception depends on PHPUnit). PHPT runner extracts the code from Another point to consider is what Psalm's target version is going to be. Psalm is moving fast, and the code used to be passing with flying colors yesterday not necessarily will pass today. Error messages also change sometimes. Unfortunately composer does not allow specifying version constraints on suggested packages, so there's no good way to declare peer dependency constraints (as npm calls it). |
I'm sorry if I ask dumb questions, but what are the benefits of coupling this goals with a specific tool? Until now I've successfully used @phpstan phpunit extension, which requires zero modification of this library and, AFAIK, provides the same functionalities. Is this intended to be used with Roave/you-are-using-it-wrong? If yes, again, what would be the benefits? @vimeo Psalm is a great tool, but I'm worried when I see tool-specific edits to libraries, look such a huge burden from a maintainer perspective, even if they are just docblocks 😟 |
@Slamdunk no dependencies to be added here: this would just make type checks work OOTB (without any plugins) downstream for those using psalm. Phpstan is working on supporting these annotations too, but isn't quite there yet. I strongly believe that no plugin should be needed for what is to be provided by clear declarations in the upstream sources. Similar discussion to doctrine/collections#177 |
I can get behind generics, but I don't understand why PHPUnit's code needs to be littered with |
Sources dictate types, not external runtime extensions. I've already explained it at #3708 (comment) Besides that, no explicit dependency, since prefixed annotations are ignored by tooling ;-) |
Also, PHPStan plans to support generics with exactly this syntax (
If I didn't know what |
I get it it's not a technical dependency, but if only Psalm can (and will ever) benefit from these annotations, should they really be maintained as part of PHPUnit source code? |
I think so, yes. It is a win-win from a technical/engineering perspective:
Note that the |
@ondrejmirtes if you build equivalent support for I absolutely believe they should be part of the codebase, though. TypeScript has the concept of type predicates which essentially do the same thing. |
Yeah, I can also do that (it would be doable even with the current public API - TypeSpecifyingExtension - anyone could build an extension that reads and interprets |
|
I've mentioned that in #3708 (comment) - will get rid of most of these internal specs as I go forward and write tests ;-) |
OK :) |
Each file verifies that the type can be correctly inferred
…cenarios This is a temporary file location, since the project has its own conventions
…lasses Suppressing the error here.
Traits are no real types, therefore we cannot support their usage in templated types.
The Here's an updated report:
|
This is a workaround to not require vimeo/psalm#1743 to be fixed first
Fixed all \o/
|
@sebastianbergmann how do you feel about fixing |
`master` was being used instead, but no such version is present in the build matrix.
Psalm didn’t find any errors! |
Annotations such as `@return numeric` are not recognized by this tooling, so for now this test suite is off-limits for `php-cs-fixer`.
Green! @sebastianbergmann up to you now - need also opinion on #3708 (comment) |
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.
Looks awesome!
</projectFiles> | ||
|
||
<issueHandlers> | ||
<LessSpecificReturnType errorLevel="error" /> |
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.
you can remove all of these - error
is the default level
I would leave |
Merged, thanks! |
\o/ |
As discussed briefly with @sebastianbergmann, adding a few type declarations to the codebase.
The final aim (not sure if fully to be reached in this PR) is to:
self::assertTrue(true);
should likely become some sort of type check errorout of current patch scopeif (! $a instanceof B) { self::fail(); } typeMismatch($a /* requires B */);
MockObject
instances wherever an explicit class name is givenNotes:
Prophecy
instance templated.phpt
filesUpstream issues currently causing false positives here:
@method
annotations not properly when formatted@method ReturnType methodName()
vimeo/psalm#1692@psalm-assert empty $value
inferred$value
type does not seem to be checked against constants vimeo/psalm#1743avoided via different test designscalar
cannot be used as type hint vimeo/psalm#1744