Skip to content

Commit de2ef15

Browse files
committed
Test calling a prophecy wihout optional parameter
This commit adds a test to reproduce the reported regression. The test builds a prophecy for a method which has an optional parameter. The prophecy doesn't expect that the optional parameter will be called. Calling this mock without the optional parameter (as expected) will result in an unexpected call with the optional parameter: 1) phpmock\prophecy\RegressionTest::expectingWithoutOptionalParameter Prophecy\Exception\Call\UnexpectedCallException: Method call: - call("arg1", "optional") on Double\phpmock\prophecy\OptionalParameterHolder\P15 was not expected, expected calls were: - call(exact("arg1")) See also #1
1 parent 57ba64e commit de2ef15

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/RegressionTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace phpmock\prophecy;
4+
5+
use \Prophecy\Prophet;
6+
7+
/**
8+
* Regression tests for Prophecy.
9+
*
10+
* @author Markus Malkusch <[email protected]>
11+
* @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
12+
* @license http://www.wtfpl.net/txt/copying/ WTFPL
13+
*/
14+
class RegressionTest extends \PHPUnit_Framework_TestCase
15+
{
16+
17+
/**
18+
* Calling no optional parameter
19+
*
20+
* @test
21+
* @see https://github.com/php-mock/php-mock-prophecy/issues/1
22+
*/
23+
public function expectingWithoutOptionalParameter()
24+
{
25+
$prophet = new Prophet();
26+
$prophecy = $prophet->prophesize(OptionalParameterHolder::class);
27+
$prophecy->call("arg1")->willReturn("mocked");
28+
$mock = $prophecy->reveal();
29+
30+
$this->assertEquals("mocked", $mock->call("arg1"));
31+
$prophet->checkPredictions();
32+
}
33+
}
34+
35+
// @codingStandardsIgnoreStart
36+
class OptionalParameterHolder
37+
{
38+
39+
public function call($arg1, $optional = "optional")
40+
{
41+
return $arg1 . $optional;
42+
}
43+
}
44+
// @codingStandardsIgnoreEnd

0 commit comments

Comments
 (0)