Enhance PHP Unit Testing And Mocking Framework improve the quality

Quick Start Guide

Installing Enhance PHP and writing your first test is really, really easy. It is probably the easiest unit testing framework to install for PHP, but this hasn't been clinically verified.

Installation

Download and unzip EnhanceTestFramework.php and put it somewhere so you can include it in your project.

Your First Test

Here is an example for your first test, with lots of comments to help you get started. You can copy this example into a .php file to try it out.

// Include the test framework
include_once('EnhanceTestFramework.php');

// Include your classes and test fixtures - they can be in separate files, just use include() statements for them!
class ExampleClass
{
    public function addTwoNumbers($a, $b)
    {
        return $a + $b;
    }
}

// Naming: By using "extends \Enhance\TestFixture" you signal that the public methods in
// your class are tests.
class ExampleClassTests extends \Enhance\TestFixture
{

    // SetUp
    // Naming: The method is optional, but if present you must call it "SetUp".
    // Usage: You can use the SetUp method to pre-configure things you want to use in all your tests.
    public function setUp() 
    {

    }
    
    // TearDown
    // Naming: The method is optional, but if present you must call it "TearDown".
    // Usage: You can use the TearDown method to re-set things after all you tests.
    public function tearDown()
    {
    
    }

    // Test
    // You can name tests as you like, but they must be public.
    // All public methods other than setUp and tearDown are treated as tests.
    public function addTwoNumbersWith3and2Expect5Test() 
    {
        // Arrange
        $target = \Enhance\Core::getCodeCoverageWrapper('ExampleClass');

        // Act
        $result = $target->addTwoNumbers(3, 2);

        // Assert
        \Enhance\Assert::areIdentical(5, $result);
    }
}

// Run the tests
\Enhance\Core::runTests();