-
Notifications
You must be signed in to change notification settings - Fork 46
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
getMockBuilder() should also work with non-existent classes #28
base: 1.1.x
Are you sure you want to change the base?
getMockBuilder() should also work with non-existent classes #28
Conversation
@lookyman @ondrejmirtes Can you please review this as a bugfix for 0.10.x? Thanks. |
Hi, what about |
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. |
Can you verify that with a quick test? |
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);
}
}
|
This is because it's explicitly disallowed in |
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 |
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?