phpspec 2.0 ilustrated by examples
DESCRIPTION
An quick introduction to those wanting to get started with phpspecTRANSCRIPT
Illustrated by examples2.0.0-BETA1
http://phpspec.net
http://github.com/phpspec/phpspecMarcello Duarte | @_md
Konstantin Kudryashov | @everzet
generate or edit specs
run the specs
edit code generate code
Installation
Create a composer.json file:
Installation
Get composer, if you don’t have it already
Installation
Install
Generate Specs
$
Generated Specs
Edit the Spec
Run Specs
$
Generate Code
Generated Code
Edit Code
Run Specs
$
:)
Matchers
object expectation matcher
$result ->should->shouldNot->should
->shouldNot Be...()Be...()$result
Types of Matchers
Identity
Comparison
Throw
Type
Object State
Inline
Identity
$this->greet()->shouldReturn('Hello, World!');
$this->greet()->shouldBe('Hello, World!');
$this->greet()->shouldBeEqualTo('Hello, World!');
$this->greet()->shouldEqual('Hello, World!');
===
Comparison
$this->greet()->shouldBeLike('Hello, World!');
==
Throw
$this->shouldThrow('EndOfTheWorld')->duringGreet();
$this->shouldThrow('EndOfTheWorld')->during('greet');
$this->greet() ->shouldThrow(new \Exception('the end')) ->duringGreet('some argument');
$this->greet()->shouldThrow('EndOfTheWorld') ->during('greet', array('some argument'));
Type
$this->greet()->shouldBeAnInstanceOf('Greeting');
$this->greet()->returnAnInstanceOf('Greeting');
$this->greet()->haveType('Greeting');
Object State
class ShoppingCartSpec extends ObjectBehavior{ function it_is_created_empty() { $this->shouldNotHaveItems(); }}
class ShoppingCart{ public function hasItems() {}}
has -> have
Object State
class LifeSpec extends ObjectBehavior{ function it_is_simple() { $this->shouldBeSimple(); }}
class Life{ public function isSimple() {}}
is -> be
Inline
class NeoSpec extends ObjectBehavior { function it_should_be_the_one() { $this->shouldBeTheOne(); }
function getMatchers() { return [ 'beTheOne' => function($actual) { return $actual instanceof TheOne; } ]; }}
Formatters
Progress
$
Dot
$ -fdot
Pretty
$ -fpretty
Nyan
$ -fnyan
Let & Let go
Constructors
Stubbing
Mocking
More
github.com/phpspec/phpspec
phpspec.net
groups.google.com/forum/#!forum/phpspec-dev
twitter.com/phpspec