mirror of
https://github.com/danog/psalm-plugin-phpunit.git
synced 2024-11-30 04:29:08 +01:00
Merge pull request #12 from weirdan/typed-expectException
Stubbed expectException()
This commit is contained in:
commit
af65a1095a
@ -10,8 +10,8 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"phpunit/phpunit": "^5.0 || ^6.0 || ^7.0",
|
||||
"vimeo/psalm": "^3.0 || dev-master",
|
||||
"phpunit/phpunit": "^6.0 || ^7.0 || ^8.0",
|
||||
"vimeo/psalm": "^3.0.8 || dev-master",
|
||||
"composer/semver": "^1.4",
|
||||
"muglug/package-versions-56": "^1.2"
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php // phpcs:ignoreFile
|
||||
namespace PHPUnit\Framework;
|
||||
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
@ -30,4 +30,9 @@ abstract class TestCase extends Assert implements Test, SelfDescribing
|
||||
* @return ObjectProphecy<T>
|
||||
*/
|
||||
public function prophesize($classOrInterface): ObjectProphecy {}
|
||||
/**
|
||||
* @param class-string<\Throwable> $exception
|
||||
* @return void
|
||||
*/
|
||||
public function expectException(string $exception) {}
|
||||
}
|
||||
|
43
tests/acceptance/TestCase.feature
Normal file
43
tests/acceptance/TestCase.feature
Normal file
@ -0,0 +1,43 @@
|
||||
Feature: TestCase
|
||||
In order to have typed TestCases
|
||||
As a Psalm user
|
||||
I need Psalm to typecheck my test cases
|
||||
|
||||
Background:
|
||||
Given I have the following code preamble
|
||||
"""
|
||||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
"""
|
||||
|
||||
Scenario: TestCase::expectException() rejects non-throwables
|
||||
Given I have Psalm newer than "3.0.12" (because of "missing functionality")
|
||||
Given I have the following code
|
||||
"""
|
||||
class MyTestCase extends TestCase
|
||||
{
|
||||
/** @return void */
|
||||
public function testSomething() {
|
||||
$this->expectException(MyTestCase::class);
|
||||
}
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see these errors
|
||||
| Type | Message |
|
||||
| InvalidArgument | Argument 1 of PHPUnit\Framework\TestCase::expectException expects class-string<Throwable>, MyTestCase::class provided |
|
||||
|
||||
Scenario: TestCase::expectException() accepts throwables
|
||||
Given I have the following code
|
||||
"""
|
||||
class MyTestCase extends TestCase
|
||||
{
|
||||
/** @return void */
|
||||
public function testSomething() {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
}
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
Loading…
Reference in New Issue
Block a user