| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
@lookyman @ondrejmirtes Can you please review this as a bugfix for 0.10.x? Thanks. |
Sorry, something went wrong.
|
Hi, what about createMock? That one needs the same fix probably: https://github.com/phpstan/phpstan-phpunit/blob/master/src/Type/PHPUnit/CreateMockDynamicReturnTypeExtension.php |
Sorry, something went wrong.
|
According to this comment from Sebastian Bergmann, non-existent classes cannot be used with createMock() API, but can be used with Mock Builder API:
and
It's 2 years old commit though, it may've changed. |
Sorry, something went wrong.
|
Can you verify that with a quick test? |
Sorry, something went wrong.
|
Seems to still be valid: <?php
class NonExistentTest extends PHPUnit\Framework\TestCase
{
public function testCreateMock()
{
$mock = $this->createMock('NonExistent');
self::assertInstanceOf(PHPUnit\Framework\MockObject\MockObject::class, $mock);
}
public function testGetMockBuilder()
{
$mock = $this->getMockBuilder('NonExistent')->getMock();
self::assertInstanceOf(PHPUnit\Framework\MockObject\MockObject::class, $mock);
}
}$ vendor/bin/phpunit NonExistentTest.php PHPUnit 7.3.1 by Sebastian Bergmann and contributors. W. 2 / 2 (100%) Time: 56 ms, Memory: 4.00MB There was 1 warning: 1) NonExistentTest::testCreateMock Cannot stub or mock class or interface "NonExistent" which does not exist WARNINGS! Tests: 2, Assertions: 1, Warnings: 1. |
Sorry, something went wrong.
|
This is because it's explicitly disallowed in createMock(): |
Sorry, something went wrong.
|
Cool. Maybe we should modify https://github.com/phpstan/phpstan-phpunit/blob/master/src/Type/PHPUnit/MockBuilderDynamicReturnTypeExtension.php too to return a little bit different instance of MockBuilderType after calling disallowMockingUnknownTypes that would still complain about unknown class. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
TestCase::getMockBuilder() can be used with undefined classes as well. In this case, the mock system creates dummy empty class of the given name.
This is used in Doctrine on some places, i.e. for testing event listeners that are based on naming, not interface.
Without this patch, we were getting the following errors:
No tests for Type\PHPUnit - how to add some?