Chapter 4. Isolated Component Testing with PHPUnit

In this chapter, we will take a closer look at PHPUnit and how it is handled by Codeception.

We will start with a brief introduction of the changes that we need to perform before getting into the actual tests, and from there, go through the red, green, and refactor phases to implement the tests and our code and refactor where needed.

We will introduce basic topics such as testing in isolation, integration tests of the components, and more advanced topics such as data providers.

The following topics are covered in this chapter:

  • Understanding the work to be done
  • Using the User model
  • Implementing the first unit test
  • Component testing of the model
  • Implementing the ActiveRecord class and its methods
  • Seeing test passing

Understanding the work to be done

In the scope of our work, we're going to introduce PHPUnit by first discussing the User model, how the authentication method works in Yii, and how it's going to be used in our specific case.

After that, we will sketch our tests to cover all possible uses of the User class, refactor the model, and then aim to get the test passed.

The current state of the framework that we have installed is not good enough for the features we want to implement.

As underlined in the previous chapters, we're going to follow a TDD approach for this first part.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset