mgrechanik and samdark Fixes #16558: Added cloning `yii\data\ActiveDataProvider::query` prop…
…erty when ActiveDataProvider object is cloned
Latest commit e53fc0d Aug 5, 2018
Failed to load latest commit information.
assets Simplified tests directory structure a bit Apr 16, 2015
cubrid moved Dockerfile(s) to test folders Mar 6, 2017
data Fixes #16514: Fixed `yii\di\Container::resolveCallableDependencies` t… Jul 27, 2018
framework Fixes #16558: Added cloning `yii\data\ActiveDataProvider::query` prop… Aug 5, 2018
js Bug #15826: Fixed JavaScript compareValidator in `yii.validation.js` … Jul 19, 2018
mssql moved Dockerfile(s) to test folders Mar 6, 2017
runtime Fix self-ignored .gitignore files. Aug 20, 2017
.env-dist Build image in dockerized tests with BUILD_ARG (#15559) Feb 5, 2018
.gitignore Simplified tests directory structure a bit Apr 16, 2015
.hhconfig Added empty HHVM config to fix HHVM tests (#15533) Jan 21, 2018
IsOneOfAssert.php Fixes #13879: Added upsert support for `yii\db\QueryBuilder` and `yi… Feb 8, 2018 Feature/updated docker testing docs (#15346) [skip ci] Dec 14, 2017
ResultPrinter.php Fixes for PHP 7.2 compatibility (#14959) Oct 18, 2017
TestCase.php Enable `phpdoc_summary` rule in php-cs-fixer config (#14675) Aug 21, 2017
bootstrap.php improved dockerized tests (#15516) Jan 18, 2018
compatibility.php Code style fixes Oct 31, 2017
docker-compose.caching.yml updated build Jan 24, 2017
docker-compose.mysql.yml updated build Jan 24, 2017
docker-compose.pgsql.yml updated build Jan 24, 2017
docker-compose.yml Build image in dockerized tests with BUILD_ARG (#15559) Feb 5, 2018 Build image in dockerized tests with BUILD_ARG (#15559) Feb 5, 2018

Yii 2.0 Unit tests


data/            models, config and other test data
    config.php   this file contains configuration for database and caching backends
framework/       the framework unit tests
runtime/         the application runtime dir for the yii test app


Make sure you have PHPUnit installed and that you installed all composer dependencies (run composer update in the repo base directory).

Run PHPUnit in the yii repo base directory.


You can run tests for specific groups only:

phpunit --group=mysql,base,i18n

You can get a list of available groups via phpunit --list-groups.

A single test class could be run like the follwing:

phpunit tests/framework/base/ObjectTest.php


PHPUnit configuration is in phpunit.xml.dist in repository root folder. You can create your own phpunit.xml to override dist config.

Database and other backend system configuration can be found in tests/data/config.php adjust them to your needs to allow testing databases and caching in your environment. You can override configuration values by creating a config.local.php file and manipulate the $config variable. For example to change MySQL username and password your config.local.php should contain the following:

$config['databases']['mysql']['username'] = 'yiitest';
$config['databases']['mysql']['password'] = 'changeme';


Get started by going to the tests directory and copy the environment configuration.

cd tests
cp .env-dist .env

The newly created .env file defines the configuration files used by docker-compose. By default MySQL, Postgres and Caching services are enabled.

You can choose services available for testing by merging docker-compose.[...].yml files in .env. For example, if you only want to test with MySQL, you can modify the COMPOSE_FILE variable as follows


When starting the stack now, you get containers for databases and caching servers to test with.

docker-compose up -d

After all services have been initialized and the stack is fully up and running enter the PHP container

docker-compose exec php bash

Run a group of unit tests

$ vendor/bin/phpunit -v --group base --debug

Examples for running phpunit in a separate container

docker-compose run php vendor/bin/phpunit -v --group caching,db   
docker-compose run php vendor/bin/phpunit -v --exclude base,caching,db,i18n,log,mutex,rbac,validators,web
docker-compose run php vendor/bin/phpunit -v --exclude mssql,oci,wincache,xcache,zenddata,cubrid

Note: Documentation about installing additional extensions can be found at yiisoft/yii2-docker.


Note: Images for testing Cubrid are based on PHP 5, due to incompatibilities with PHP 7

cd tests/cubrid
docker-compose up -d
docker-compose run php vendor/bin/phpunit -v --group cubrid


Note: Images for testing MSSQL are based on bylexus/apache-php7 (Ubuntu) since drivers are not available for Debian or Alpine.


  • needs 3.5 GB RAM, Docker-host with >4.5 GB is recommended for testing
  • database CLI tsgkadot/mssql-tools

Example commands

cd tests/mssql

Using a shell

docker-compose run --rm sqlcmd sqlcmd -S mssql -U sa -P Microsoft-12345

Create database with sqlcmd

$ sqlcmd -S mssql -U sa -P Microsoft-12345 -Q "CREATE DATABASE yii2test"

Create database (one-liner)

docker-compose run --rm sqlcmd sqlcmd -S mssql -U sa -P Microsoft-12345 -Q "CREATE DATABASE yii2test"

Run MSSQL tests

docker-compose run php 
$ vendor/bin/phpunit --group mssql

Build triggers

curl -X POST \
     -F token=${TOKEN} \
     -F ref=travis \
     -F "variables[DOCKER_MYSQL_IMAGE]=mysql:5.6" \
     -F "variables[DOCKER_POSTGRES_IMAGE]=postgres:9.5" \

Run tests locally

Via shell script

cd tests
sh default

Via runner


docker-compose configuration

  image: schmunk42/gitlab-runner
  entrypoint: bash
  working_dir: /project
    - ../:/project
    - /var/run/docker.sock:/var/run/docker.sock
    - RUNNER_BUILDS_DIR=${PWD}/..    

Start runner bash

docker-compose -f docker-compose.runner.yml run runner

Execute jobs via shell runner (with docker-compose support)

$ gitlab-runner exec shell build
$ gitlab-runner exec shell test