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.
AbcTest which extends from TestCase,
where AbcTest stands for the class being tested.
For example, to test the CArray class, we would name the corresponding unit test as CArrayTest by convention.
The base class TestCase is meant for generic unit tests. Because PHPUnit_Framework_TestCase
is the ancestor class for these classes, we can use all methods inherited from this class.
AbcTest.php.
It may be stored under the directory tests/framework for framework tests or
tests/protected for application tests.
testAbc, where Abc is
often the name of the class method to be tested.
To install and run Unit test you have to perform following actions:
composer require phpunit/phpunit --dev
composer remove phpunit/phpunit --dev composer update
"scripts": {
"tests-result": "phpunit --colors=always --log-junit test-results.xml",
"tests": "phpunit --colors=always",
"test": "phpunit --colors=always --filter"
}
tests/protected directory and write your tests.
composer tests
composer test AbcTest
composer test AbcTest::testXyz