method()->should…(Be, Return, Equal)
method()->shouldNot…(Be, Return, Equal)
class HelloWorldSpec extends ObjectBehavior
{
public function it_should_say_hello()
{
$this->helloWorld()->shouldBeEqualTo('Hello World!');
}
}
namespace Spec;
use PhPSpec\ObjectBehavior;
class ObjectStateSpec extends ObjectBehavior
{
public function it_should_has_a_valid_state()
{
$this->shouldBeAValidState();
}
}
class ObjectState
{
public function isAValidState()
{
return true;
}
}
class CustomMatcherSpec extends ObjectBehavior
{
public function it_should_say_hello()
{
$this->helloWorld()->shouldSayHello();
}
public function getMatchers()
{
return array(
'sayHello' => function($actual) {
return $actual == 'Hello World!';
}
);
}
}
class HelloWorldStubsSpec extends ObjectBehavior
{
public function it_should_say_hello(Greeter $greeter)
{
$greeter->sayHello()->willReturn('');
$this->helloWorld($greeter)->shouldSayHello();
}
}
class HelloWorldMockSpec extends ObjectBehavior
{
public function it_should_say_hello(Greeter $greeter)
{
$greeter->sayHello()->shouldBeCalled();
$this->helloWorld($greeter)->shouldSayHello();
}
}
code.tutsplus.com/tutorials/getting-started-with-phpspec--cms-20919