O'Reilly logo

PHPUnit Essentials by Zdenek Machek

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required