You can simply install PHPUnit to run commands (https://github.com/sebastianbergmann/phpunit/#php-archive-phar):

  1. wget https://phar.phpunit.de/phpunit.phar
  2. chmod +x phpunit.phar
  3. mv phpunit.phar /usr/local/bin/phpunit
  4. Run single test

And then run PHPunit test:

phpunit test.php
Content of test file is following:

  1. <?php
  2. class StackTest extends PHPUnit_Framework_TestCase
  3. {
  4. protected function setUp()
  5. {
  6. }
  7. public function testSave()
  8. {
  9. }
  10. }

Run test suite

Configuration of test suite: demosuite.xml. demo is directory containing all tests. Test files must be named as *_test.php (suffix).

  1. <testsuites>
  2. <testsuite name="DemoTestSuite">
  3. <directory suffix="test.php">demo</directory>
  4. </testsuite>
  5. </testsuites>

Test suite runs with following commands:

  1. phpunit -c demosuite.xml --testsuite DemoTestSuite

分类: web

标签:   php