Handling dependencies

In our case, the cleanest method to solve the dependency problem would be to separate the User class from database access and the Mail class usage. The logic is that the User class is an entity, but then we will have a second UserManager class that will allow us to persist (store) the objects of the User class in the database. To test the User class, we will use unit tests, and to test UserManager, we will use integration testing. In our case, we will move sendActivationEmail() and createUser() to the UserManager class.

The User class then becomes a lightweight class, as shown in the following code snippet:

<?php namespace Application; /** * Class User * @package Application */ class User { public $userId; public $firstName; ...

Get PHPUnit Essentials now with O’Reilly online learning.

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