Find file History
Latest commit b7e3378 Dec 27, 2018

Phalcon Unit Tests

Welcome to the Phalcon Testing Suite.

This folder contains all the tests for the Phalcon Framework.

Getting Started

This testing suite uses Travis CI for each run. Every commit pushed to this repository will queue a build into the continuous integration service and will run all tests to ensure that everything is going well and the project is stable.

The testing suite can be run on your own machine. The only dependencies for running the testing suite are nanobox and Codeception. Nanobox can also be used for developing Phalcon, and its installation instructions can be found in the Nanobox documentation. Codeception can be installed using Composer:

# run this command from project root
composer install --dev --prefer-source

You can read more about installing and configuring Codeception from the following resources:

The container based environment contains all the services you need to write and run your tests. These services are:

  • Beanstalkd
  • Memcached
  • Mongodb
  • Mysql
  • Postgresql
  • Redis

The PHP extensions enabled are:

  • apcu
  • ctype
  • curl
  • dom
  • fileinfo
  • gd
  • gmp
  • gettext
  • imagick
  • iconv
  • igbinary
  • json
  • memcached
  • mbstring
  • mongodb
  • opcache
  • phar
  • pdo
  • pdo_mysql
  • pdo_pgsql
  • pdo_sqlite
  • redis
  • session
  • simplexml
  • tokenizer
  • yaml
  • zephir_parser
  • xdebug
  • xml
  • xmlwriter
  • zip
  • zlib

Start the environment

We will need a terminal window, so open one if you don't have one already and navigate to the folder where you have cloned the repository (or a fork of it)

Nanobox reads its configuration, so as to start the environment, from a file called boxfile.yml located at the root of your folder. By default the file is not there to allow for more flexibility. We have two setup files, one for PHP 7.2 and one for PHP 7.3. If you wish to set up an environment for Phalcon using PHP 7.2, you can copy the relevant file at the root of your folder:

cp -v ./tests/_ci/nanobox/boxfile.7.2.yml ./boxfile.yml

You can also create a 7.3 environment by copying the relevant file.


nanobox run

The process will take a while (for the first time) and once it is done you will be inside the environment. The prompt of your terminal will be:

Preparing environment :


                          ::    *********    ::
                             ::    ***    ::
                           ++   :::   :::   ++
                              ++   :::   ++
                                 ++   ++
                    _  _ ____ _  _ ____ ___  ____ _  _
                    |\ | |__| |\ | |  | |__) |  |  \/
                    | \| |  | | \| |__| |__) |__| _/\_

+ You are in a Linux container
+ Your local source code has been mounted into the container
+ Changes to your code in either the container or desktop will be mirrored
+ If you run a server, access it at >>

/app $

Now that zephir is in your environment, you can check it by typing:

/app $ zephir

This should show you the help screen. You can now compile the extension:

/app $ zephir fullclean
/app $ zephir build

After the compilation is completed, you can check if the extension is loaded:

/app $ php -m | grep phalcon

Setup databases

The SQL dump files are located under tests/_data/assets/db/schemas. When importing your Postgresql database, please make sure you use the file suffixed with *nanobox. You can run the following commands from your nanobox environment

/app $ cat ./tests/_data/assets/db/schemas/mysql_schema.sql | mysql -u root gonano

/app $ psql -U nanobox gonano -q -f ./tests/_data/assets/db/schemas/postgresql_schema.sql

/app $ sqlite3 ./tests/_output/phalcon_test.sqlite < ./tests/_data/assets/db/schemas/sqlite_schema.sql
/app $ sqlite3 ./tests/_output/translations.sqlite < ./tests/_data/assets/db/schemas/sqlite_translations_schema.sql

Run tests

First you need to re-generate base classes for all suites:

/app $ codecept build

Once the database is created, run the tests on a terminal:

/app $ codecept run
# OR
/app $ codecept run --debug # Detailed output

Execute unit test with run unit command:

/app $ codecept run unit

Execute all tests from a folder:

/app $ codecept run tests/unit/some/folder/

Execute single test:

/app $ codecept run tests/unit/some/folder/some/test/file.php


  • Add more information in this readme
  • Write tests for the skipped ones in the suite
  • Tests for foreign keys cascade in the ORM
  • Tests for many-to-many relations
  • Tests for +=, -=, *=, /=, ++, -- in Volt
  • Tests for Alc::allow('*', '*', 'index')
  • Tests for Alc::allow('*', '*', '*')
  • Tests for Alc::deny('user', '*', '*') - should deny all resources


Note: Cache-related tests are slower than others tests because they use wait states (sleep command) to expire generated caches.

Please report any issue if you find out bugs or memory leaks.


<3 Phalcon Framework Team