<?php
use Prophecy\Argument\Token\AnyValueToken;
use PHPUnit\Framework\TestCase;
class ProphecyTest extends TestCase
{
public function testMockInvocation() : void
{
$fooProphecy = $this->prophesize(Foo::CLASS);
// allow every argument for method Foo::bar()
$fooProphecy->bar(new AnyValueToken())
->willReturn(true)
->shouldBeCalledTimes(2);
// reveal the prophecy of Foo
// this is the mock for your tests to inject
$foo = $fooProphecy->reveal();
$this->assertTrue($foo->bar(null));
$this->assertTrue($foo->bar(1));
// Only 2 invocations of Foo::bar() are expected
$this->assertTrue($foo->bar('test'));
}
}
interface Foo
{
public function bar($value);
}