At present phpspec does not appear to support anything equivalent to the 'constraint' functionality provided by phpunit but sometimes fuzzy matches are required when testing arguments passed to mocked methods.
As an example use case consider the regular expression example below or in a situation where multiple arguments are passed to a mocked method but you only need to verify one (in which case you would use the 'anything' constraint).
Here is an example of the constraints functionality.
<?php
class SomeObject
{
public function someMethod( $arg1, $arg2 )
{
}
}
class TestCase extends PHPUnit_Framework_TestCase
{
public function setup()
{
$this->mock = $this->getMock( 'SomeObject' );
$this->mock->expects( $this->any() )
->method( 'someMethod' )
->with(
$this->matchesRegularExpression( '/^abc.*/' ),
$this->greaterThan( 4 )
);
}
public function testConstraintPassExample()
{
$this->mock->someMethod( 'abc123', 5 );
}
public function testFirstArgConstraintFailExample()
{
$this->mock->someMethod( 'def456', 6 );
}
public function testSecondArgConstraintFailExample()
{
$this->mock->someMethod( 'abc456', 2 );
}
}