Merge pull request #12 from weirdan/typed-expectException

Stubbed expectException()
This commit is contained in:
Bruce Weirdan 2019-02-16 19:16:01 +02:00 committed by GitHub
commit af65a1095a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 3 deletions

View File

@ -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"
},

View File

@ -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) {}
}

View 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