Skip to content
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

Do not ignore constructor arguments based on type being mocked #3694

Merged
merged 1 commit into from May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Framework/MockObject/Generator.php
Expand Up @@ -593,9 +593,7 @@ private function getObject($code, $className, $type = '', $callOriginalConstruct
{
$this->evalClass($code, $className);

if ($callOriginalConstructor &&
\is_string($type) &&
!\interface_exists($type, $callAutoload)) {
if ($callOriginalConstructor) {
if (\count($arguments) === 0) {
$object = new $className;
} else {
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/Framework/MockObject/GeneratorTest.php
Expand Up @@ -220,6 +220,12 @@ public function testMockingOfThrowable(): void
$this->assertInstanceOf(MockObject::class, $stub);
}

public function testMockingOfThrowableConstructorArguments(): void
{
$mock = $this->generator->getMock(Throwable::class, null, ['It works']);
$this->assertSame('It works', $mock->getMessage());
}

public function testVariadicArgumentsArePassedToOriginalMethod()
{
/** @var ClassWithVariadicArgumentMethod|MockObject $mock */
Expand Down