sebastianbergmann/phpunit-mock-objects — pull request #179 by phramz (2014-06-25 15:02:49+00:00)
Title: implemented evaluated-flag to avoid extra evaluation

Hey there!

Picture the following scenario:
```php
class PhpUnitTest extends \PHPUnit_Framework_TestCase
{
public function testDblEval()
{
$bar = $this->getMockBuilder('Bar')
->setMethods(array('handle'))
->getMock();

$args = array ('foo', 'bar', 'bazz');
$bar->expects($this->exactly(count($args)))
->method('handle')
->with(
$this->callback(
function ($arg) use (& $args) {
return $arg === array_shift($args);
}
)
);

$test = new Foo();
$test->dispatch($bar);
}
}

class Foo
{
public function dispatch(Bar $handler)
{
$handler->handle('foo');
$handler->handle('bar');
$handler->handle('bazz');
}
}

class Bar
{
public function handle($value)
{
// do something
}
}
```

This test will fail due to the very last method-call gets invoked twice:
```
vagrant@precise64:/vagrant$ bin/phpunit PhpUnitTest.php
PHPUnit 4.1.3 by Sebastian Bergmann.

Configuration read from /vagrant/phpunit.xml.dist

F

Time: 245 ms, Memory: 9.75Mb

There was 1 failure:

1) PhpUnitTest::testDblEval
Expectation failed for method name is equal to when invoked 3 time(s).
Parameter 0 for invocation Bar::handle('bazz') does not match expected value.
Failed asserting that 'bazz' is accepted by specified callback.

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
```
The last - 4th method-call - is triggered by the `verify()` method which is made here:
https://github.com/sebastianbergmann/phpunit-mock-objects/blob/2.1/src/Framework/MockObject/Matcher.php#L289

This PR fixes that issue although it is kind of a workaround and probably there will be better ways to solve this issue.