Writing test

Getting started with writing phpspec tests requires grasping a few basic concepts, such as the following:

  • The it_*() and its_*() methods: This object behavior is made up of individual examples, each one being flagged with the it_*() or its_*() methods. We can have one or more of these methods defined per single specification. Each defined method gets triggered when a test is run.
  • Matchers methods: These are analogous to assertions in PHPUnit. They describe how an object should behave.
  • Object construction methods: Every object we describe in phpspec is not a separate variable, but is $this. Sometimes, however, getting the proper $this variable requires managing constructor parameters. This is where the beConstructedWith()

Get Mastering PHP 7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.