-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
feature/test-doublesTest Stubs and Mock ObjectsTest Stubs and Mock Objectstype/bugSomething is brokenSomething is broken
Description
| Q | A |
|---|---|
| PHPUnit version | 9.2.3 |
| PHP version | 7.4.7 |
| Installation Method | Composer |
Summary
In a project that uses PHPUnit and Psalm, Psalm detects the issue in PHPUnit that cannot be fixed in the project and therefore has to be suppressed.
Current behavior
ERROR: InternalMethod - tests/ExampleTest.php:17:12 - The method
PHPUnit\Framework\MockObject\Builder\InvocationMocker::method has been marked as internal
(see https://psalm.dev/175)
)->method('test');
The above is caused by the interface returning a class marked as @internal:
public function expects(InvocationOrder $invocationRule): BuilderInvocationMocker; phpunit/src/Framework/MockObject/Builder/InvocationMocker.php
Lines 29 to 32 in cb13599
/** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class InvocationMocker implements InvocationStubber, MethodNameMatch
This issue was already brought up in #3742 (comment).
How to reproduce
<?php declare(strict_types=1);
namespace Test;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/**
* @test
*/
public function testExample() : void
{
$t = $this->createMock(T::class);
$t->expects(
$this->never()
)->method('test');
}
}
interface T
{
public function test() : void;
}See the full demo project in the gist:
$ composer install
$ vendor/bin/psalm
Since the project's tests extend and use the PHPUnit test classes, suppressing errors in the vendor/ directory doesn't help.
Expected behavior
PHPUnit doesn't expose the internal parts of its API to the userland.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feature/test-doublesTest Stubs and Mock ObjectsTest Stubs and Mock Objectstype/bugSomething is brokenSomething is broken