3

Summary

Adding PHPUnitA PHP Library for Code Test Automation to the project to automate unit and integration testing which will become a part of the DevOps process.

Overview

Purpose To automate code testing as part of a devops deployment strategy.
Goals
  • Automate unit and integration testing.
  • Refactor code to make it easier to test.
Technology PHPUnitA PHP Library for Code Test Automation, HomebrewApplication used to install XDebug and NodeJS on Macbook., Auryn InjectorA PHP Dependency Injector library to support Inversion of Control design pattern., XDebugA PHP extension which provides debugging and profiling capabilities.
Resources Udemy class "Introduction to Testing with PHPUnitA PHP Library for Code Test Automation" taught by Trevor Sawler, Ph.D.
(This class was a great introduction to automated testing principles using PHPUnitA PHP Library for Code Test Automation but not necessarily novice friendly.)

Implementation

  1. Install PHPUnitA PHP Library for Code Test Automation

    Use ComposerUsed to manage the installation of third-party PHP libraries. to install PHPUnitA PHP Library for Code Test Automation:

    composer require phpunit/phpunit --dev

  2. Create Directories for Test Classes

    In the Document Root create directory Test. Inside this directory other directories should be created to mirror the locations of the classes to be tested. (For examples tests for App/Controllers/User.php should be in Test/App/Controllers.

  3. Create Test Database

    This was done by exporting the orginal database into a copy called tbd_test.

  4. Create PHPUnitA PHP Library for Code Test Automation Configuration File

    Create phpunit.xml in the Document Root which specifies the location of the test classes, directories of the classes to be tested and environmental variables to be used during testing. Note: parameters to log into the database should point to the new tbd_test database.

  5. Install HomebrewApplication used to install XDebug and NodeJS on Macbook. and XDebugA PHP extension which provides debugging and profiling capabilities.

    XDebugA PHP extension which provides debugging and profiling capabilities. is an application that works with PHPUnitA PHP Library for Code Test Automation to analyze test coverage. It calculates the percentage of the code that is tested and shows the lines that are untested. In order to install XDebugA PHP extension which provides debugging and profiling capabilities., HomebrewApplication used to install XDebug and NodeJS on Macbook. a package management application was first installed.

  6. Install PHPServer-side scripting language for web development. Dependency Injector

    In order to make the code easier to test code was refactored to use a dependency injection design pattern. To facilitate this effort the PHPServer-side scripting language for web development. package rdlowrey/auryn was installed via ComposerUsed to manage the installation of third-party PHP libraries.:

    composer require rdlowrey/auryn

  7. Modify Front Controller to Use Dependency Injector

    The public/index.php was modified to establish the shared objects and initialize the Router by injecting these dependencies.

  8. Modify PHPServer-side scripting language for web development. Class Constructors

    Almost all of the the PHPServer-side scripting language for web development. classes had to modified to accept the dependent objects passed into the constructor instead of creating instances of the dependent objects inside the class.

  9. Create Unit and Integration Test Classes

    For each classes in the App and Core directories two PHPServer-side scripting language for web development. class files were created, one for unit tests where all dependencies on other classes were mocked and one for integration test where the classes were allowed to interact. For example App/Home.php would have /Tests/App/Home_UnitTest.php and /Tests/App/Home_IntegrationTest.php

  10. Execute PHPUnitA PHP Library for Code Test Automation Test