PhpSpec 2.0 ilustrated by examples

  • 5,805 views
Uploaded on

An quick introduction to those wanting to get started with phpspec

An quick introduction to those wanting to get started with phpspec

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
5,805
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
41
Comments
0
Likes
17

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Illustrated by examples 2.0.0-BETA1 http://phpspec.net http://github.com/phpspec/phpspec Marcello Duarte | @_md Konstantin Kudryashov | @everzet
  • 2. generate or edit specs run the specs edit code generate code
  • 3. Installation Create a composer.json file:
  • 4. Installation Get composer, if you don’t have it already
  • 5. Installation Install
  • 6. Generate Specs $
  • 7. Generated Specs
  • 8. Edit the Spec
  • 9. Run Specs $
  • 10. Generate Code
  • 11. Generated Code
  • 12. Edit Code
  • 13. Run Specs $
  • 14. :)
  • 15. Matchers object expectation matcher $result ->should ->shouldNot ->should ->shouldNot Be...()Be...()$result
  • 16. Types of Matchers Identity Comparison Throw Type Object State Inline
  • 17. Identity $this->greet()->shouldReturn('Hello, World!'); $this->greet()->shouldBe('Hello, World!'); $this->greet()->shouldBeEqualTo('Hello, World!'); $this->greet()->shouldEqual('Hello, World!'); ===
  • 18. Comparison $this->greet()->shouldBeLike('Hello, World!'); ==
  • 19. 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'));
  • 20. Type $this->greet()->shouldBeAnInstanceOf('Greeting'); $this->greet()->returnAnInstanceOf('Greeting'); $this->greet()->haveType('Greeting');
  • 21. Object State class ShoppingCartSpec extends ObjectBehavior { function it_is_created_empty() { $this->shouldNotHaveItems(); } } class ShoppingCart { public function hasItems() {} } has -> have
  • 22. Object State class LifeSpec extends ObjectBehavior { function it_is_simple() { $this->shouldBeSimple(); } } class Life { public function isSimple() {} } is -> be
  • 23. Inline class NeoSpec extends ObjectBehavior { function it_should_be_the_one() { $this->shouldBeTheOne(); } function getMatchers() { return [ 'beTheOne' => function($actual) { return $actual instanceof TheOne; } ]; } }
  • 24. Formatters
  • 25. Progress $
  • 26. Dot $ -fdot
  • 27. Pretty $ -fpretty
  • 28. Nyan $ -fnyan
  • 29. Let & Let go
  • 30. Constructors
  • 31. Stubbing
  • 32. Mocking
  • 33. More github.com/phpspec/phpspec phpspec.net groups.google.com/forum/#!forum/phpspec-dev twitter.com/phpspec