Skip to content

Commit

Permalink
Added tests for methods with variadic arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelHartmann authored and sebastianbergmann committed Sep 8, 2018
1 parent a2fb124 commit e87699c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/_files/ClassWithVariadicArgumentMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* A class with a method that takes a variadic argument.
*/
class ClassWithVariadicArgumentMethod
{
public function foo(...$args)
{
return $args;
}
}
40 changes: 40 additions & 0 deletions tests/unit/Framework/MockObject/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,44 @@ public function testMockingOfThrowable(): void
$this->assertInstanceOf(Exception::class, $stub);
$this->assertInstanceOf(MockObject::class, $stub);
}

public function testVariadicArgumentsArePassedToOriginalMethod()
{
/** @var ClassWithVariadicArgumentMethod|MockObject $mock */
$mock = $this->generator->getMock(
ClassWithVariadicArgumentMethod::class,
[],
[],
'',
true,
false,
true,
false,
true
);

$arguments = [1, 'foo', false];
$this->assertSame($arguments, $mock->foo(...$arguments));
}

public function testVariadicArgumentsArePassedToMockedMethod()
{
/** @var ClassWithVariadicArgumentMethod|MockObject $mock */
$mock = $this->generator->getMock(
ClassWithVariadicArgumentMethod::class,
[],
[],
'',
true,
false,
true,
false,
false
);

$arguments = [1, 'foo', false];
$mock->expects($this->once())
->method('foo')
->with(...$arguments);
}
}

0 comments on commit e87699c

Please sign in to comment.