Unit Testing


General:

Because the ApPHP Framework testing is built on top of PHPUnit, we strongly recommended that you go through the PHPUnit documentation first to get the basic understanding on how to write a unit test. We summarize in the following the basic principles of writing a unit test in ApPHP.


Installation and usage:

To install and run Unit test you have to perform following actions:

  1. Install composer on your server. https://getcomposer.org

  2. After Composer is installed, install PHPUnit by
    composer require phpunit/phpunit --dev

    you may also remove it and re-install again:
    composer remove phpunit/phpunit --dev
    composer update
    
  3. Make sure you added following to composer.json file:
    "scripts": {
        "tests-result": "phpunit --colors=always --log-junit test-results.xml",
        "tests": "phpunit --colors=always",
        "test": "phpunit --colors=always --filter"
    }
    
  4. Create test files in tests/protected directory and write your tests.

Running tests:

  1. To run all your tests use following command in command line:
    composer tests
  2. To run specific test use following command:
    composer test AbcTest
  3. To run specific test from the specific test file use following command (if it's placed in default directory):
    composer test AbcTest::testXyz
    or
    composer test AbcTest Tests\\Unit\\Entity\\User\\AbcTest.php
    where 2nd parameter is a path to test class