Skip to content

Commit

Permalink
Do not ignore constructor arguments based on type being mocked
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov authored and sebastianbergmann committed May 17, 2019
1 parent de00854 commit b961563
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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

0 comments on commit b961563

Please sign in to comment.