PHPSpec is a development tool, designed to help you achieve clean and working PHP code by using a technique derived from test-first development called (spec) behaviour driven development, or SpecBDD.
The process of restructuring existing code without changing external behavior.
The difference is the language!
$this->assertEquals(0, $result); // PHPUnit
$result->shoulBe(0); // PHPSpec
$this->getRating()->shouldBe(5);
$this->getTitle()->shouldBeEqualTo("Star Wars");
$this->getReleaseDate()->shouldReturn(233366400);
$this->getRating()->shouldBeLike('5');
$this->shouldThrow('\InvalidArgumentException')->duringSetRating(-3);
$this->shouldThrow('\InvalidArgumentException')->during('setRating', array(-3));
$this->shouldThrow(new \InvalidArgumentException("Invalid rating"))->during('setRating', array(-3));
$this->shouldHaveType('Movie');
$this->shouldReturnAnInstanceOf('Movie');
$this->shouldBeAnInstanceOf('Movie');
$this->shouldImplement('Movie');
$this->shouldBeAvailableOnCinemas();
$this->shouldHaveSoundtrack();
$this->getItems()->shouldHaveCount(3);
$this->getTitle()->shouldBeString();
$this->getPrice()->shouldBeFloat();
$this->getItems()->shouldBeArray();
class MovieSpec extends ObjectBehavior
{
function it_should_have_some_specific_options_by_default()
{
$this->getOptions()->shouldHaveKey('username');
$this->getOptions()->shouldHaveValue('diegoholiveira');
}
public function getMatchers()
{
return [
'haveKey' => function($subject, $key) {
return array_key_exists($key, $subject);
},
'haveValue' => function($subject, $value) {
return in_array($value, $subject);
},
];
}
}
$converter
->convert(80, 'USD')
->willReturn(106.54621543)
;
$converter
->convert(80, 'USD')
->shouldBeCalled()
;
<?php
/**
* This file is part of the PHP Summer Camp workshop.
*
* @author PHPSpec developers
*/
namespace %namespace%;
class %name%
{
}
.phpspec/class.tpl
phpspec.yml
extensions:
- Cjm\PhpSpec\Extension\TypeHintedMethodsExtension