Writing test

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

  • The setUp() method: Analogous to the constructor, this is where we create the objects against which we will perform the test.
  • The tearDown() method: Analogous to the destructor, this is where we clean up objects against which we performed the test.
  • The test*() methods: Every public method whose name begins with test, for example, testSomething(), testItAgain(), and so on, is considered a single test. The same effect can be achieved by adding the @test annotation in a method's docblock; although, this seems to be a less used case.
  • The @depends annotation: This allows expressing dependencies between the test methods.
  • Assertions ...

Get Mastering PHP 7 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.