Browse Source

Merge pull request #13360 from schmunk42/feature/docker-testing

added dockerized test setup
tags/2.0.12
Carsten Brandt 8 years ago committed by GitHub
parent
commit
2339e2f7bb
  1. 3
      .dockerignore
  2. 1
      .gitignore
  3. 118
      .gitlab-ci.yml
  4. 8
      Dockerfile
  5. 109
      composer.lock
  6. 1
      framework/CHANGELOG.md
  7. 10
      tests/.env-dist
  8. 99
      tests/README.md
  9. 31
      tests/cubrid/Dockerfile
  10. 17
      tests/cubrid/docker-compose.yml
  11. 59
      tests/data/config-docker.php
  12. 14
      tests/data/cubrid.sql
  13. 13
      tests/docker-compose.caching.yml
  14. 15
      tests/docker-compose.mysql.yml
  15. 14
      tests/docker-compose.pgsql.yml
  16. 22
      tests/docker-compose.yml
  17. 2
      tests/framework/console/controllers/CacheControllerTest.php
  18. 3
      tests/framework/console/controllers/DbMessageControllerTest.php
  19. 1
      tests/framework/console/controllers/MigrateControllerTest.php
  20. 1
      tests/framework/mutex/MysqlMutexTest.php
  21. 1
      tests/framework/mutex/PgsqlMutexTest.php
  22. 3
      tests/framework/rbac/DbManagerTestCase.php
  23. 3
      tests/framework/rbac/MySQLManagerCacheTest.php
  24. 1
      tests/framework/rbac/MySQLManagerTest.php
  25. 1
      tests/framework/rbac/PgSQLManagerTest.php
  26. 56
      tests/mssql/Dockerfile
  27. 34
      tests/mssql/docker-compose.yml
  28. 65
      tests/test-local.sh

3
.dockerignore

@ -0,0 +1,3 @@
.git
vendor
docs

1
.gitignore vendored

@ -41,3 +41,4 @@ phpunit.phar
# NPM packages
/node_modules
.env

118
.gitlab-ci.yml

@ -0,0 +1,118 @@
before_script:
# set stack isolation
- export ISOLATION=buildpipeline${CI_PIPELINE_ID}${CI_BUILD_NAME}
- export COMPOSE_PROJECT_NAME=${ISOLATION}
- export TUPLE_C=$(expr ${CI_BUILD_ID} % 99)
- echo ${TUPLE_C}
# run docker-compose commands from tests environment
- cd tests
- cp .env-dist .env
- docker-compose config
after_script:
- export ISOLATION=buildpipeline${CI_PIPELINE_ID}${CI_BUILD_NAME}
- export COMPOSE_PROJECT_NAME=${ISOLATION}
# run docker-compose commands from tests environment
- cd tests
- cp .env-dist .env
- docker-compose down -v --remove-orphans
- docker ps -f name=${ISOLATION}
stages:
- travis
- test
- cleanup
test:
stage: test
script:
- docker-compose up --build -d
- docker-compose run --rm php vendor/bin/phpunit -v --exclude caching,db,data --log-junit tests/_junit/test.xml
caching:
stage: test
only:
- tests/caching
- tests/full
script:
- export COMPOSE_FILE=docker-compose.yml:docker-compose.${CI_BUILD_NAME}.yml
- docker-compose up --build -d
- docker-compose run --rm php vendor/bin/phpunit -v --group caching --exclude db
db:
stage: test
only:
- tests/mysql
- tests/full
script:
- docker-compose up --build -d
- docker-compose run --rm php vendor/bin/phpunit -v --group db --exclude caching,mysql,pgsql,mssql,cubrid,oci
mysql:
stage: test
only:
- tests/mysql
- tests/full
script:
- export COMPOSE_FILE=docker-compose.yml:docker-compose.${CI_BUILD_NAME}.yml
- docker-compose up --build -d
# wait for db (retry X times)
- docker-compose run --rm php bash -c "while ! curl mysql:3306; do ((c++)) && ((c==30)) && break; sleep 2; done"
- docker-compose run --rm php vendor/bin/phpunit -v --group mysql
pgsql:
stage: test
only:
- tests/pgsql
- tests/full
script:
- export COMPOSE_FILE=docker-compose.yml:docker-compose.${CI_BUILD_NAME}.yml
- docker-compose up --build -d
# wait for db (retry X times)
- docker-compose run --rm php bash -c 'while [ true ]; do curl postgres:5432; if [ $? == 52 ]; then break; fi; ((c++)) && ((c==25)) && break; sleep 2; done'
- docker-compose run --rm php vendor/bin/phpunit -v --group pgsql
cubrid:
stage: test
only:
- tests/cubrid
- tests/extra
script:
- cd cubrid
- docker-compose up --build -d
# wait for db (retry X times)
- docker-compose run --rm php bash -c 'while [ true ]; do curl cubrid:1523; if [ $? == 56 ]; then break; fi; ((c++)) && ((c==20)) && break; sleep 3; done'
- sleep 5
- docker-compose run --rm php /project/vendor/bin/phpunit -v --group cubrid
mssql:
stage: test
only:
- tests/mssql
- tests/extra
script:
- cd mssql
- docker-compose up --build -d
# wait for db (retry X times)
- docker-compose run --rm php bash -c 'while [ true ]; do curl mssql:1433; if [ $? == 52 ]; then break; fi; ((c++)) && ((c==15)) && break; sleep 5; done'
- sleep 3
# Note: Password has to be the last parameter
- docker-compose run --rm sqlcmd sh -c 'sqlcmd -S mssql -U sa -Q "CREATE DATABASE yii2test" -P Microsoft-12345'
- docker-compose run --rm php vendor/bin/phpunit -v --group mssql
travis:
stage: travis
only:
- travis
script:
- export COMPOSE_FILE=docker-compose.yml:docker-compose.mysql.yml:docker-compose.pgsql.yml
- docker-compose up --build -d
# wait for dbs ...
- sleep 10
- docker-compose run --rm php vendor/bin/phpunit -v --exclude mssql,cubrid,oci,wincache,xcache,zenddata,cubrid

8
Dockerfile

@ -0,0 +1,8 @@
FROM dmstr/php-yii2:7.0-fpm-1.9-beta2-alpine-nginx
# Project source-code
WORKDIR /project
ADD composer.* /project/
RUN /usr/local/bin/composer install --prefer-dist
ADD ./ /project
ENV PATH /project/vendor/bin:${PATH}

109
composer.lock generated

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "30a97926034335c40273795ce316f36c",
"content-hash": "58ccdf60f6da90c6d1623d9755c0b830",
"hash": "db4e038c0e8ca747784fb195c82bfdad",
"content-hash": "cc4b01a602c948040169ebbc1ac30186",
"packages": [
{
"name": "bower-asset/jquery",
@ -44,12 +44,12 @@
"source": {
"type": "git",
"url": "https://github.com/RobinHerbots/jquery.inputmask.git",
"reference": "5a72c563b502b8e05958a524cdfffafe9987be38"
"reference": "ec7726993217ee7b01023ad4f7f1b6a51446a39d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/RobinHerbots/jquery.inputmask/zipball/5a72c563b502b8e05958a524cdfffafe9987be38",
"reference": "5a72c563b502b8e05958a524cdfffafe9987be38",
"url": "https://api.github.com/repos/RobinHerbots/jquery.inputmask/zipball/ec7726993217ee7b01023ad4f7f1b6a51446a39d",
"reference": "ec7726993217ee7b01023ad4f7f1b6a51446a39d",
"shasum": ""
},
"require": {
@ -114,16 +114,16 @@
},
{
"name": "bower-asset/yii2-pjax",
"version": "dev-master",
"version": "v2.0.6",
"source": {
"type": "git",
"url": "https://github.com/yiisoft/jquery-pjax.git",
"reference": "3f20897307cca046fca5323b318475ae9dac0ca0"
"reference": "60728da6ade5879e807a49ce59ef9a72039b8978"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yiisoft/jquery-pjax/zipball/3f20897307cca046fca5323b318475ae9dac0ca0",
"reference": "3f20897307cca046fca5323b318475ae9dac0ca0",
"url": "https://api.github.com/repos/yiisoft/jquery-pjax/zipball/60728da6ade5879e807a49ce59ef9a72039b8978",
"reference": "60728da6ade5879e807a49ce59ef9a72039b8978",
"shasum": ""
},
"require": {
@ -136,18 +136,15 @@
".travis.yml",
"Gemfile",
"Gemfile.lock",
"CONTRIBUTING.md",
"vendor/",
"script/",
"test/"
],
"branch-alias": {
"dev-master": "2.0.3-dev"
}
]
},
"license": [
"MIT"
],
"time": "2015-03-08 21:03:11"
]
},
{
"name": "cebe/markdown",
@ -255,21 +252,24 @@
},
{
"name": "yiisoft/yii2-composer",
"version": "2.0.4",
"version": "2.0.5",
"source": {
"type": "git",
"url": "https://github.com/yiisoft/yii2-composer.git",
"reference": "7452fd908a5023b8bb5ea1b123a174ca080de464"
"reference": "3f4923c2bde6caf3f5b88cc22fdd5770f52f8df2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yiisoft/yii2-composer/zipball/7452fd908a5023b8bb5ea1b123a174ca080de464",
"reference": "7452fd908a5023b8bb5ea1b123a174ca080de464",
"url": "https://api.github.com/repos/yiisoft/yii2-composer/zipball/3f4923c2bde6caf3f5b88cc22fdd5770f52f8df2",
"reference": "3f4923c2bde6caf3f5b88cc22fdd5770f52f8df2",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.0"
},
"require-dev": {
"composer/composer": "^1.0"
},
"type": "composer-plugin",
"extra": {
"class": "yii\\composer\\Plugin",
@ -298,7 +298,7 @@
"extension installer",
"yii2"
],
"time": "2016-02-06 00:49:24"
"time": "2016-12-20 13:26:02"
}
],
"packages-dev": [
@ -440,16 +440,16 @@
},
{
"name": "phpspec/prophecy",
"version": "v1.6.1",
"version": "v1.6.2",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
"reference": "58a8137754bc24b25740d4281399a4a3596058e0"
"reference": "6c52c2722f8460122f96f86346600e1077ce22cb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/58a8137754bc24b25740d4281399a4a3596058e0",
"reference": "58a8137754bc24b25740d4281399a4a3596058e0",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/6c52c2722f8460122f96f86346600e1077ce22cb",
"reference": "6c52c2722f8460122f96f86346600e1077ce22cb",
"shasum": ""
},
"require": {
@ -457,10 +457,11 @@
"php": "^5.3|^7.0",
"phpdocumentor/reflection-docblock": "^2.0|^3.0.2",
"sebastian/comparator": "^1.1",
"sebastian/recursion-context": "^1.0"
"sebastian/recursion-context": "^1.0|^2.0"
},
"require-dev": {
"phpspec/phpspec": "^2.0"
"phpspec/phpspec": "^2.0",
"phpunit/phpunit": "^4.8 || ^5.6.5"
},
"type": "library",
"extra": {
@ -498,7 +499,7 @@
"spy",
"stub"
],
"time": "2016-06-07 08:13:47"
"time": "2016-11-21 14:58:47"
},
{
"name": "phpunit/php-code-coverage",
@ -564,16 +565,16 @@
},
{
"name": "phpunit/php-file-iterator",
"version": "1.4.1",
"version": "1.4.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git",
"reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0"
"reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0",
"reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5",
"reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5",
"shasum": ""
},
"require": {
@ -607,7 +608,7 @@
"filesystem",
"iterator"
],
"time": "2015-06-21 13:08:43"
"time": "2016-10-03 07:40:28"
},
{
"name": "phpunit/php-text-template",
@ -696,16 +697,16 @@
},
{
"name": "phpunit/php-token-stream",
"version": "1.4.8",
"version": "1.4.9",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
"reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da"
"reference": "3b402f65a4cc90abf6e1104e388b896ce209631b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da",
"reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3b402f65a4cc90abf6e1104e388b896ce209631b",
"reference": "3b402f65a4cc90abf6e1104e388b896ce209631b",
"shasum": ""
},
"require": {
@ -741,20 +742,20 @@
"keywords": [
"tokenizer"
],
"time": "2015-09-15 10:49:45"
"time": "2016-11-15 14:06:22"
},
{
"name": "phpunit/phpunit",
"version": "4.8.27",
"version": "4.8.31",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "c062dddcb68e44b563f66ee319ddae2b5a322a90"
"reference": "98b2b39a520766bec663ff5b7ff1b729db9dbfe3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c062dddcb68e44b563f66ee319ddae2b5a322a90",
"reference": "c062dddcb68e44b563f66ee319ddae2b5a322a90",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/98b2b39a520766bec663ff5b7ff1b729db9dbfe3",
"reference": "98b2b39a520766bec663ff5b7ff1b729db9dbfe3",
"shasum": ""
},
"require": {
@ -770,7 +771,7 @@
"phpunit/php-text-template": "~1.2",
"phpunit/php-timer": "^1.0.6",
"phpunit/phpunit-mock-objects": "~2.3",
"sebastian/comparator": "~1.1",
"sebastian/comparator": "~1.2.2",
"sebastian/diff": "~1.2",
"sebastian/environment": "~1.3",
"sebastian/exporter": "~1.2",
@ -813,7 +814,7 @@
"testing",
"xunit"
],
"time": "2016-07-21 06:48:14"
"time": "2016-12-09 02:45:31"
},
{
"name": "phpunit/phpunit-mock-objects",
@ -873,22 +874,22 @@
},
{
"name": "sebastian/comparator",
"version": "1.2.0",
"version": "1.2.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "937efb279bd37a375bcadf584dec0726f84dbf22"
"reference": "6a1ed12e8b2409076ab22e3897126211ff8b1f7f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22",
"reference": "937efb279bd37a375bcadf584dec0726f84dbf22",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/6a1ed12e8b2409076ab22e3897126211ff8b1f7f",
"reference": "6a1ed12e8b2409076ab22e3897126211ff8b1f7f",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"sebastian/diff": "~1.2",
"sebastian/exporter": "~1.2"
"sebastian/exporter": "~1.2 || ~2.0"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
@ -933,7 +934,7 @@
"compare",
"equality"
],
"time": "2015-07-26 15:48:44"
"time": "2016-11-19 09:18:40"
},
{
"name": "sebastian/diff",
@ -1245,16 +1246,16 @@
},
{
"name": "symfony/yaml",
"version": "v2.8.13",
"version": "v2.8.16",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "396784cd06b91f3db576f248f2402d547a077787"
"reference": "dbe61fed9cd4a44c5b1d14e5e7b1a8640cfb2bf2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/396784cd06b91f3db576f248f2402d547a077787",
"reference": "396784cd06b91f3db576f248f2402d547a077787",
"url": "https://api.github.com/repos/symfony/yaml/zipball/dbe61fed9cd4a44c5b1d14e5e7b1a8640cfb2bf2",
"reference": "dbe61fed9cd4a44c5b1d14e5e7b1a8640cfb2bf2",
"shasum": ""
},
"require": {
@ -1290,7 +1291,7 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2016-10-21 20:59:10"
"time": "2017-01-03 13:49:52"
}
],
"aliases": [],

1
framework/CHANGELOG.md

@ -37,6 +37,7 @@ Yii Framework 2 Change Log
- Bug #13649: Fixes issue where `['uncheck' => false]` and `['label' => false]` options for `ActiveRadio` and `ActiveCheckbox` were ignored (Alex-Code)
- Enh #13221: Make `\yii\db\QueryTrait::limit()` and `\yii\db\QueryTrait::offset()` methods work with `\yii\db\Expression` (Ni-san)
- Enh #13144: Refactored `yii\db\Query::queryScalar()` (Alex-Code)
- Enh #13360: Added Dockerized test setup for the framework tests (schmunk42)
- Bug #13379: Fixed `applyFilter` function in `yii.gridView.js` to work correctly when params in `filterUrl` are indexed (SilverFire, arogachev)
- Enh #13650: Improved `yii\base\Security::hkdf()` to take advantage of native `hash_hkdf()` implementation in PHP >= 7.1.2 (charlesportwoodii)
- Bug #13379: Fixed `applyFilter` function in `yii.gridView.js` to work correctly when params in `filterUrl` are indexed (SilverFire)

10
tests/.env-dist

@ -0,0 +1,10 @@
# docker-compose test environment
# Choose a flavour
#COMPOSE_FILE=docker-compose.yml:docker-compose.caching.yml
#COMPOSE_FILE=docker-compose.yml:docker-compose.mysql.yml
#COMPOSE_FILE=docker-compose.yml:docker-compose.postgres.yml
# Choose a version
DOCKER_MYSQL_IMAGE=percona:5.7
DOCKER_POSTGRES_IMAGE=postgres

99
tests/README.md

@ -53,3 +53,102 @@ contain the following:
$config['databases']['mysql']['username'] = 'yiitest';
$config['databases']['mysql']['password'] = 'changeme';
```
DOCKERIZED TESTING
------------------
*This section is under construction*
Start test stack and enter PHP container
cd tests
docker-compose up -d
docker-compose run --rm php bash
Run a group of unit tests
$ vendor/bin/phpunit -v --group base --debug
Run phpunit directly
cd tests
docker-compose run --rm php vendor/bin/phpunit -v --group caching,db
docker-compose run --rm php vendor/bin/phpunit -v --exclude base,caching,db,i18n,log,mutex,rbac,validators,web
### Cubrid
cd tests
docker-compose -f docker-compose.cubrid.yml up -d
docker-compose -f docker-compose.cubrid.yml run --rm php vendor/bin/phpunit -v --group cubrid
### MSSQL
**experimental**
- needs 3.5 GB RAM, Docker-host with >4.5 GB is recommended for testing
- database CLI `tsgkadot/mssql-tools`
Example commands
cd tests
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 --rm 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" \
${TRIGGER_URL}
### Run tests locally
#### Via shell script
cd tests
sh test-local.sh default
#### Via runner
**experimental**
docker-compose configuration
runner:
image: schmunk42/gitlab-runner
entrypoint: bash
working_dir: /project
volumes:
- ../:/project
- /var/run/docker.sock:/var/run/docker.sock
environment:
- 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

31
tests/cubrid/Dockerfile

@ -0,0 +1,31 @@
FROM php:5-fpm
# /usr/local/lib/php/extensions/no-debug-non-zts-20131226/cubrid.so
RUN pecl install pdo_cubrid-9.3.0.0001
RUN echo "extension=pdo_cubrid.so" > /usr/local/etc/php/conf.d/cubrid.ini
# Install system packages for composer (git)
RUN apt-get update && \
apt-get -y install \
git \
--no-install-recommends && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Register the COMPOSER_HOME environment variable
ENV COMPOSER_HOME /composer
# Add global binary directory to PATH and make sure to re-export it
ENV PATH /usr/local/bin:$PATH
# Allow Composer to be run as root
ENV COMPOSER_ALLOW_SUPERUSER 1
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- \
--filename=composer.phar \
--install-dir=/usr/local/bin
# Project source-code
WORKDIR /project
ADD composer.* /project/
RUN /usr/local/bin/composer.phar install --prefer-dist
ADD ./ /project

17
tests/cubrid/docker-compose.yml

@ -0,0 +1,17 @@
version: '2'
services:
php:
build:
context: ../..
dockerfile: tests/cubrid/Dockerfile
ports:
- 80
#volumes:
# - ../..:/project
depends_on:
- cubrid
cubrid:
image: lighthopper/cubrid:9.3.6.0002
command: ./create-start-demodb.sh

59
tests/data/config-docker.php

@ -0,0 +1,59 @@
<?php
/**
* This is the configuration file for the Yii 2 unit tests.
* 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:
*
<?php
$config['databases']['mysql']['username'] = 'yiitest';
$config['databases']['mysql']['password'] = 'changeme';
*/
$config = [
'databases' => [
'cubrid' => [
'dsn' => 'cubrid:dbname=demodb;host=cubrid;port=33000',
'username' => 'dba',
'password' => '',
'fixture' => __DIR__ . '/cubrid.sql',
],
'mysql' => [
'dsn' => 'mysql:host=mysql;dbname=yiitest',
'username' => 'travis',
'password' => 'travis',
'fixture' => __DIR__ . '/mysql.sql',
],
'sqlite' => [
'dsn' => 'sqlite::memory:',
'fixture' => __DIR__ . '/sqlite.sql',
],
'sqlsrv' => [
'dsn' => 'sqlsrv:Server=mssql;Database=yii2test',
'username' => 'sa',
'password' => 'Microsoft-12345',
'fixture' => __DIR__ . '/mssql.sql',
],
'pgsql' => [
'dsn' => 'pgsql:host=postgres;dbname=yiitest;port=5432;',
'username' => 'postgres',
'password' => 'postgres',
'fixture' => __DIR__ . '/postgres.sql',
],
'oci' => [
'dsn' => 'oci:dbname=LOCAL_XE;charset=AL32UTF8;',
'username' => '',
'password' => '',
'fixture' => __DIR__ . '/oci.sql',
],
],
];
if (is_file(__DIR__ . '/config.local.php')) {
include(__DIR__ . '/config.local.php');
}
return $config;

14
tests/data/cubrid.sql

@ -55,7 +55,7 @@ CREATE TABLE "item" (
"name" varchar(128) NOT NULL,
"category_id" int(11) NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "FK_item_category_id" FOREIGN KEY ("category_id") REFERENCES "category" ("id") ON DELETE CASCADE
CONSTRAINT "FK_item_category_id" FOREIGN KEY ("category_id") REFERENCES "category" ("id")
);
CREATE TABLE "order" (
@ -64,7 +64,7 @@ CREATE TABLE "order" (
"created_at" int(11) NOT NULL,
"total" decimal(10,0) NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "FK_order_customer_id" FOREIGN KEY ("customer_id") REFERENCES "customer" ("id") ON DELETE CASCADE
CONSTRAINT "FK_order_customer_id" FOREIGN KEY ("customer_id") REFERENCES "customer" ("id")
);
CREATE TABLE "order_with_null_fk" (
@ -81,8 +81,8 @@ CREATE TABLE "order_item" (
"quantity" int(11) NOT NULL,
"subtotal" decimal(10,0) NOT NULL,
PRIMARY KEY ("order_id","item_id"),
CONSTRAINT "FK_order_item_order_id" FOREIGN KEY ("order_id") REFERENCES "order" ("id") ON DELETE CASCADE,
CONSTRAINT "FK_order_item_item_id" FOREIGN KEY ("item_id") REFERENCES "item" ("id") ON DELETE CASCADE
CONSTRAINT "FK_order_item_order_id" FOREIGN KEY ("order_id") REFERENCES "order" ("id"),
CONSTRAINT "FK_order_item_item_id" FOREIGN KEY ("item_id") REFERENCES "item" ("id")
);
CREATE TABLE "order_item_with_null_fk" (
@ -134,7 +134,7 @@ CREATE TABLE "composite_fk" (
"order_id" int(11) NOT NULL,
"item_id" int(11) NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "FK_composite_fk_order_item" FOREIGN KEY ("order_id","item_id") REFERENCES "order_item" ("order_id","item_id") ON DELETE CASCADE
CONSTRAINT "FK_composite_fk_order_item" FOREIGN KEY ("order_id","item_id") REFERENCES "order_item" ("order_id","item_id")
);
CREATE TABLE "animal" (
@ -204,12 +204,12 @@ INSERT INTO "document" (title, content, version) VALUES ('Yii 2.0 guide', 'This
/* bit test, see https://github.com/yiisoft/yii2/issues/9006 */
DROP TABLE IF EXISTS `bit_values` CASCADE;
DROP TABLE IF EXISTS `bit_values`;
CREATE TABLE `bit_values` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`val` bit(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
);
INSERT INTO `bit_values` (id, val) VALUES (1, b'0'), (2, b'1');

13
tests/docker-compose.caching.yml

@ -0,0 +1,13 @@
version: '2'
services:
php:
depends_on:
- redis
- memcached
redis:
image: redis
memcached:
image: memcached

15
tests/docker-compose.mysql.yml

@ -0,0 +1,15 @@
version: '2'
services:
php:
depends_on:
- mysql
mysql:
image: ${DOCKER_MYSQL_IMAGE}
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=yiitest
- MYSQL_USER=travis
- MYSQL_PASSWORD=travis

14
tests/docker-compose.pgsql.yml

@ -0,0 +1,14 @@
version: '2'
services:
php:
depends_on:
- postgres
postgres:
image: ${DOCKER_POSTGRES_IMAGE}
environment:
- POSTGRES_DB=yiitest
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres

22
tests/docker-compose.yml

@ -0,0 +1,22 @@
version: '2'
services:
php:
build: ..
working_dir: /project
volumes:
- ../tests/data/config-docker.php:/project/tests/data/config.php
# Enable for debugging, enabling tests might be slow for file access (data) on host-volume
#- ../tests:/project/tests
# - ../framework:/project/framework
# Tmpfs volume (experimental, asset tests may fail)
#tmpfs:
# - /project/tests/runtime
networks:
default:
ipam:
driver: default
config:
# prevent overlapping/duplicated networks, since docker assigns /16 subnets by default ranging from 10.x over 172.x to 192.168.x
- subnet: 10.100.1${TUPLE_C}.1/24

2
tests/framework/console/controllers/CacheControllerTest.php

@ -11,6 +11,8 @@ use yii\console\controllers\CacheController;
* @see CacheController
*
* @group console
* @group db
* @group mysql
*/
class CacheControllerTest extends TestCase
{

3
tests/framework/console/controllers/DbMessageControllerTest.php

@ -6,6 +6,9 @@ use yii\db\Connection;
/**
* Tests that [[\yii\console\controllers\MessageController]] works as expected with DB message format.
*
* @group db
* @group mysql
*/
class DbMessageControllerTest extends BaseMessageControllerTest
{

1
tests/framework/console/controllers/MigrateControllerTest.php

@ -13,6 +13,7 @@ use yiiunit\TestCase;
* @see MigrateController
*
* @group console
* @group db
*/
class MigrateControllerTest extends TestCase
{

1
tests/framework/mutex/MysqlMutexTest.php

@ -9,6 +9,7 @@ use yiiunit\framework\db\DatabaseTestCase;
* Class MysqlMutexTest
*
* @group mutex
* @group db
* @group mysql
*
* @package yiiunit\framework\mutex

1
tests/framework/mutex/PgsqlMutexTest.php

@ -9,6 +9,7 @@ use yiiunit\framework\db\DatabaseTestCase;
* Class PgsqlMutexTest
*
* @group mutex
* @group db
* @group pgsql
*
* @package yiiunit\framework\mutex

3
tests/framework/rbac/DbManagerTestCase.php

@ -10,6 +10,9 @@ use yiiunit\framework\console\controllers\EchoMigrateController;
/**
* DbManagerTestCase
* @group db
* @group rbac
* @group mysql
*/
abstract class DbManagerTestCase extends ManagerTestCase
{

3
tests/framework/rbac/MySQLManagerCacheTest.php

@ -6,8 +6,9 @@ use yii\rbac\DbManager;
/**
* MySQLManagerCacheTest
* @group db
* @group rbac
* @group db
* @group mysql
*/
class MySQLManagerCacheTest extends MySQLManagerTest
{

1
tests/framework/rbac/MySQLManagerTest.php

@ -5,6 +5,7 @@ namespace yiiunit\framework\rbac;
* MySQLManagerTest
* @group db
* @group rbac
* @group mysql
*/
class MySQLManagerTest extends DbManagerTestCase
{

1
tests/framework/rbac/PgSQLManagerTest.php

@ -5,6 +5,7 @@ namespace yiiunit\framework\rbac;
* PgSQLManagerTest
* @group db
* @group rbac
* @group pgsql
*/
class PgSQLManagerTest extends DbManagerTestCase
{

56
tests/mssql/Dockerfile

@ -0,0 +1,56 @@
FROM bylexus/apache-php7
# https://www.microsoft.com/en-us/sql-server/developer-get-started/php-ubuntu
RUN apt-get update
RUN apt-get install -y curl apt-transport-https
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update \
&& apt-get install -y unixodbc-dev-utf16 php-dev \
&& pecl install sqlsrv pdo_sqlsrv
RUN echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
RUN echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
RUN echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/php/7.0/cli/php.ini
RUN echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/php/7.0/cli/php.ini
# IMPORTANT NOTICE! Install `msodbcsql` after `unixodbc-dev-utf16` and `pdo_sqlsrv`, due to dependency & build issues
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql
# Install system packages for composer (git)
RUN apt-get update && \
apt-get -y install \
git \
php-curl \
--no-install-recommends && \
rm -rf /tmp/* /var/tmp/*
# Register the COMPOSER_HOME environment variable
ENV COMPOSER_HOME /composer
# Add global binary directory to PATH and make sure to re-export it
ENV PATH /usr/local/bin:$PATH
# Allow Composer to be run as root
ENV COMPOSER_ALLOW_SUPERUSER 1
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- \
--filename=composer.phar \
--install-dir=/usr/local/bin
RUN composer.phar global require --optimize-autoloader \
"hirak/prestissimo"
# Project source-code
WORKDIR /project
ADD composer.* /project/
RUN /usr/local/bin/composer.phar install --prefer-dist
ADD ./ /project
# https://github.com/Microsoft/msphpsql/issues/161
RUN apt-get install -y locales \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& locale-gen
# Debug installation
RUN dpkg -L msodbcsql

34
tests/mssql/docker-compose.yml

@ -0,0 +1,34 @@
version: '2'
services:
php:
build:
context: ../..
dockerfile: tests/mssql/Dockerfile
# Alternative pre-built image (TODO: evaluate)
#image: ppoffice/apache-php-mssql-odbc
ports:
- 80
# Enable for debugging, Note: File-cache tests may be VERY slow or fail
#volumes:
# - ../../..:/project
depends_on:
- mssql
# Enable for debugging
#entrypoint: ['bash']
mssql:
image: microsoft/mssql-server-linux
# Alternative pre-built image (TODO: evaluate)
#image: microsoft/mssql-server-windows
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=Microsoft-12345
sqlcmd:
image: tsgkadot/mssql-tools
# Mount project for accessing SQL dump (TODO)
volumes:
- ../..:/project
# Enable for debugging
#entrypoint: ['bash']

65
tests/test-local.sh

@ -0,0 +1,65 @@
#!/usr/bin/env bash
# Generate a "hash" from 0-99 for subnet tuple (10, 11, ..., 199) - it's a hack
echo "Creating CI_BUILD_ID and CI_PIPELINE_ID from first argument..."
export CI_BUILD_ID=$(expr $((32#${1})) % 99)
export CI_PIPELINE_ID=${1}
# Copy snippets from https://git.hrzg.de/ci/lint
case $1 in
'default')
export ISOLATION=buildpipeline${CI_PIPELINE_ID}
export COMPOSE_PROJECT_NAME=${ISOLATION}
export TUPLE_C=$(expr ${CI_BUILD_ID} % 255)
echo ${TUPLE_C}
docker-compose up -d
docker-compose run --rm php vendor/bin/phpunit -v --exclude caching,db
docker-compose down -v
;;
'caching')
export ISOLATION=buildpipeline${CI_PIPELINE_ID}
export COMPOSE_PROJECT_NAME=${ISOLATION}
export TUPLE_C=$(expr ${CI_BUILD_ID} % 255)
echo ${TUPLE_C}
export COMPOSE_PROJECT_NAME=${ISOLATION}caching
docker-compose up -d
docker-compose run --rm php bash -c "while ! curl mysql:3306; do ((c++)) && ((c==30)) && break; sleep 2; done"
docker-compose run --rm php vendor/bin/phpunit -v --group caching
docker-compose down -v
;;
'mssql')
export ISOLATION=buildpipeline${CI_PIPELINE_ID}
export COMPOSE_PROJECT_NAME=${ISOLATION}
export TUPLE_C=$(expr ${CI_BUILD_ID} % 255)
echo ${TUPLE_C}
cd mssql
docker-compose up --build -d
docker-compose run --rm php bash -c 'while [ true ]; do curl mssql:1433; if [ $? == 52 ]; then break; fi; ((c++)) && ((c==15)) && break; sleep 5; done'
sleep 10
docker-compose run --rm sqlcmd sh -c 'sqlcmd -S mssql -U sa -Q "CREATE DATABASE yii2test" -P Microsoft-12345'
sleep 10
docker-compose logs mssql
docker-compose config
pwd
docker-compose ps
docker-compose run --rm php php -i
docker-compose run --rm php vendor/bin/phpunit -v --group mssql
docker-compose down -v --remove-orphans
;;
'pgsql')
export ISOLATION=buildpipeline${CI_PIPELINE_ID}
export COMPOSE_PROJECT_NAME=${ISOLATION}
export TUPLE_C=$(expr ${CI_BUILD_ID} % 255)
echo ${TUPLE_C}
export COMPOSE_PROJECT_NAME=${ISOLATION}pgsql
docker-compose up -d
docker-compose run --rm php bash -c 'while [ true ]; do curl postgres:5432; if [ $? == 52 ]; then break; fi; ((c++)) && ((c==25)) && break; sleep 2; done'
docker-compose run --rm php vendor/bin/phpunit -v --group pgsql
docker-compose down -v
;;
*)
echo "Warning: No job argument specified"
;;
esac
echo "Done."
Loading…
Cancel
Save