text: Writing proper tests can assist in writing better software. If you set up proper test cases you can eliminate most functional bugs and better maintain your software.
  If you don’t already have phpunit installed, you can do it by using the following composer command:
  composer require phpunit/phpunit
  or by manually adding it to composer.json:
  { "require-dev": { "phpunit/phpunit": "3.7.*" } }
  Or if you don’t have composer you can install phpunit via pear:
  pear config-set auto_discover 1 pear install pear.phpunit.de/PHPUnit
  Once phpunit is installed create a directory called ‘tests’ in your root directory:
  app/ public/ tests/
  Next, we need a ‘helper’ file to bootstrap the application for unit testing.
  A helper file is required to bootstrap the application for running the tests. We have prepared a sample file. Put the file in your tests/ directory as TestHelper.php.
  use Phalcon\DI, Phalcon\DI\FactoryDefault; ini_set('display_errors',1); error_reporting(E_ALL); define('ROOT_PATH', __DIR__); define('PATH_LIBRARY', __DIR__ . '/../app/library/'); define('PATH_SERVICES', __DIR__ . '/../app/services/'); define('PATH_RESOURCES', __DIR__ . '/../app/resources/');->registerDirs(array(": "dev-master" } }
  You can also clone the repository using the repo link above.
  Now, create a phpunit file:
  <:
  use Phalcon\DI,  = DI::getDefault(); // get any DI components here. If you have a config, be sure to pass it to the parent parent::setUp( ‘Test’. So create a file called testsTestUnitTest.php:
  namespace Test; /** * Class UnitTest */ class UnitTest extends \UnitTestCase { public function testTestCase() { $this->assertEquals('works', 'works', 'This is OK' ); $this->assertEquals('works', 'works1', 'This wil fail' ); } }
  Now when you execute ‘phpunit’ in your command-line from the tests directory you will get the following output:
  $ phpunit PHPUnit 3.7.23 by Sebastian Bergmann. Configuration read from /private/var/www/tests/phpunit.xml Time: 3 ms, Memory: 3.25Mb There was 1 failure: 1) Test\UnitTest::testTestCase This wil fail Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'works' +'works1' /private/var/www/tests/Test/UnitTest.php:25 FAILURES! Tests: 1, Assertions: 2, Failures: 1.
  Now you can start building your unit tests. You can view a good guide here (we also recommend reading the PHPunit documentation if you’re not familiar with PHPunit):
  © 2011–2016 Phalcon Framework Team
  Licensed under the Creative Commons Attribution License 3.0.