<?php
use Prophecy\Prophet;
use Prophecy\Argument\Token\TypeToken;
use Prophecy\Argument\ArgumentsWildcard;
interface Foo
{
public function bar($value);
}
// Creating a stub for Foo interface
$prophet = new Prophet();
$fooProphecy = $prophet->prophesize('Foo');
// if argument is 5, method bar returns 10
$fooProphecy->bar(5)->willReturn(10);
// if argument is any kind of string, method bar returns 'string'
$argToken = new TypeToken('string');
$fooProphecy->bar($argToken)->willReturn('string');
// now get your Foo instance and use it
$foo = $fooProphecy->reveal();
// different invokations of Foo::bar() method
dump($foo->bar(5));
dump($foo->bar('foobar'));
// Argument 4 was not expected
try {
$foo->bar(4);
} catch(Exception $e) {
dump($e->getMessage());
}
^ 10
^ "string"