-
Notifications
You must be signed in to change notification settings - Fork 33
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
request: suppress MissingThrowsDocblock when preceding code invokes TestCase::expectException
#48
Labels
more info needed
There's no enough information provided to address the issue
Comments
Do you have a test case for this? |
weirdan
added
the
more info needed
There's no enough information provided to address the issue
label
Jan 12, 2020
not a proper one at the moment (presently at the dayjob, will see if I can dig one out), but it's something like this: first, configure psalm to require <?php
class FooTest extends TestCase {
public function testThing() : void {
static::expectException(InvalidArgumentException::class);
// do thing that throws InvalidArgumentException
}
} |
Feature: TestCase @throws
In order to have TestCases have relaxed @throws requirements
As a Psalm user
I need Psalm to typecheck my testcases
Background:
Given I have the following config
"""
<?xml version="1.0"?>
<psalm checkForThrowsDocblock="true">
<projectFiles>
<directory name="."/>
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
</psalm>
"""
And I have the following code preamble
"""
<?php
namespace NS;
use PHPUnit\Framework\TestCase;
"""
Scenario: uncaught exception triggers error
Given I have the following code
"""
class MyTestCase extends TestCase
{
/** @return void */
public function testSomething() {
throw new \InvalidArgumentException('foo');
}
}
"""
When I run Psalm
Then I see these errors
| Type | Message |
| MissingThrowsDocblock | InvalidArgumentException is thrown but not caught - please either catch or add a @throws annotation |
And I see no other errors
Scenario: expected exception triggers no errors
Given I have the following code
"""
class MyTestCase extends TestCase
{
/** @return void */
public function testSomething() {
$this->expectException(\InvalidArgumentException::class);
throw new \InvalidArgumentException('foo');
}
}
"""
When I run Psalm
Then I see no errors
Scenario: expected exception called statically triggers no errors
Given I have the following code
"""
class MyTestCase extends TestCase
{
/** @return void */
public function testSomething() {
static::expectException(\InvalidArgumentException::class);
throw new \InvalidArgumentException('foo');
}
}
"""
When I run Psalm
Then I see no errors
|
possibly related: https://youtrack.jetbrains.com/issue/WI-39461 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MissingThrowsDocblock<T>
currently bubbles up when preceding code invokesTestCase::expectException(T::class)
I'm reasonably certain phpunit doesn't let
InvalidArgumentException
bubble up if I'm callingstatic::expectException(InvalidArgumentException::class)
The text was updated successfully, but these errors were encountered: