atoum/atoum — pull request #254 by jubianchi (2013-09-27 18:07:18+00:00)
Title: [RFC] Advanced arguments asserter API

While working on the phpunit bridge, I ran into a situation I can't handle with the current arguments asserter API on mocks.

Here is an example phpunit test that I can't support ATM:

```php
getMock('Symfony\Component\Validator\ConstraintValidatorFactoryInterface');
$validatorFactory
->expects($this->any())
->method('getInstance')
->with($this->isInstanceOf('Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity'))
->will($this->returnValue($uniqueValidator))
;

return $validatorFactory;
}
}
?>
```

The part that is responsible is the ```->with($this->isInstanceOf('\A\Class'))```. With atoum, when asserting on calls arguments, we can only check their values (```withArguments``` / ```withIdenticalArguments```). Here, we want to check that the argument was an instance of ```\A\Class```

I think the use case is valid, sometimes we only want to check that something was given as a parameter in a more lazy way.

I also tried to figure out a clean API and I came to something like:

```php
if($mock = new \mock\Something())
->and($sut = new testedClass($mock))
->then
->variable($sut->doSomething())->isNull()
->mock($mock)
->call('init')->withArguments
->at(0)->isInstanceOf('\\A\\Class')
->at(1)->isCallable()
->at(2)->isArray()->isEmpty()
->at(3)->isIdenticalTo('non_random_stuff')
->at(4)->isEqualTo('non_random_stuff')
->once()
;
```

I was just thinking about something like that... let me know what you think about that.