Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move unit tests to docker #613

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
sudo: false
language: php

cache:
directories:
- $HOME/.composer/cache
- vendor

services:
- mysql

env:
global:
- COMPOSER_ARGS="--no-interaction"

matrix:
fast_finish: true
include:
Expand Down Expand Up @@ -46,26 +40,37 @@ matrix:
- DEPS=latest

before_install:
- mysql -e 'CREATE DATABASE `database`;'
- shopt -s expand_aliases
- alias docker="travis_retry docker-compose run --rm php"
- alias composer="travis_retry docker-compose run --rm php composer"
- alias php="travis_retry docker-compose run -e TRAVIS -e TRAVIS_JOB_ID --rm php php"
- docker-compose build --build-arg PHP_VERSION=${TRAVIS_PHP_VERSION} --build-arg XDEBUG=${TEST_COVERAGE:+1} --no-cache php
- composer --version
- php -v
- php -m

install:
- travis_retry composer install $COMPOSER_ARGS
- if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi
- php --info
- composer install --no-interaction --ignore-platform-reqs
- if [[ $DEPS == 'latest' ]]; then composer update --no-interaction ; fi
- if [[ $DEPS == 'lowest' ]]; then composer update --prefer-lowest --prefer-stable --no-interaction ; fi
- docker-compose start;
- sleep 10; # wait for mysql container to initialize itself
- docker-compose run --rm php mysql -h mysql -e 'CREATE DATABASE `database`;'
- docker stty cols 120 && composer show
- composer show

before_script:
- rm -Rf .travis/cache
- cp .travis/config/application.config.php config/application.config.php

script:
- docker cp .travis/config/application.config.php config/application.config.php
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then php build/coverage-checker.php build/clover.xml 70 ; fi
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi
- cat .travis/run-cli.sh | xargs -L 1 php
- .travis/run-cli.sh

after_script:
- rm -Rf config/application.config.php
- if [[ $TEST_COVERAGE == 'true' ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- docker rm -Rf config/application.config.php
- if [[ $TEST_COVERAGE == 'true' ]]; then docker wget https://scrutinizer-ci.com/ocular.phar; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then php ocular.phar code-coverage:upload --format=php-clover ./build/clover.xml; fi

4 changes: 3 additions & 1 deletion .travis/config/travis.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
'doctrine' => [
'connection' => [
'orm_default' => [
'driverClass' => 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver',
'params' => [
'user' => 'travis',
'user' => 'root',
'password' => '',
'dbname' => 'database',
'host' => 'mysql',
],
],
],
Expand Down
38 changes: 19 additions & 19 deletions .travis/run-cli.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
./vendor/bin/doctrine-module dbal:import .travis/dummy-import.sql
./vendor/bin/doctrine-module dbal:run-sql "SELECT 1"
./vendor/bin/doctrine-module orm:clear-cache:metadata
./vendor/bin/doctrine-module orm:clear-cache:query
./vendor/bin/doctrine-module orm:clear-cache:result
./vendor/bin/doctrine-module orm:generate-proxies
./vendor/bin/doctrine-module orm:ensure-production-settings
./vendor/bin/doctrine-module orm:info
./vendor/bin/doctrine-module orm:schema-tool:create
./vendor/bin/doctrine-module orm:schema-tool:update
./vendor/bin/doctrine-module orm:validate-schema
./vendor/bin/doctrine-module dbal:run-sql "SELECT COUNT(a.id) FROM entity a"
./vendor/bin/doctrine-module orm:run-dql "SELECT COUNT(a) FROM DoctrineORMModule\Travis\Entity\Entity a"
./vendor/bin/doctrine-module orm:schema-tool:drop --dump-sql
./vendor/bin/doctrine-module orm:schema-tool:drop --force
./vendor/bin/doctrine-module migrations:generate
./vendor/bin/doctrine-module migrations:diff
./vendor/bin/doctrine-module migrations:execute 20120714005702 -n
./vendor/bin/doctrine-module migrations:migrate --no-interaction
docker-compose run --rm php ./vendor/bin/doctrine-module dbal:import .travis/dummy-import.sql
docker-compose run --rm php ./vendor/bin/doctrine-module dbal:run-sql "SELECT 1"
docker-compose run --rm php ./vendor/bin/doctrine-module orm:clear-cache:metadata
docker-compose run --rm php ./vendor/bin/doctrine-module orm:clear-cache:query
docker-compose run --rm php ./vendor/bin/doctrine-module orm:clear-cache:result
docker-compose run --rm php ./vendor/bin/doctrine-module orm:generate-proxies
docker-compose run --rm php ./vendor/bin/doctrine-module orm:ensure-production-settings
docker-compose run --rm php ./vendor/bin/doctrine-module orm:info
docker-compose run --rm php ./vendor/bin/doctrine-module orm:schema-tool:create
docker-compose run --rm php ./vendor/bin/doctrine-module orm:schema-tool:update
docker-compose run --rm php ./vendor/bin/doctrine-module orm:validate-schema
docker-compose run --rm php ./vendor/bin/doctrine-module dbal:run-sql "SELECT COUNT(a.id) FROM entity a"
docker-compose run --rm php ./vendor/bin/doctrine-module orm:run-dql "SELECT COUNT(a) FROM DoctrineORMModule\Travis\Entity\Entity a"
docker-compose run --rm php ./vendor/bin/doctrine-module orm:schema-tool:drop --dump-sql
docker-compose run --rm php ./vendor/bin/doctrine-module orm:schema-tool:drop --force
docker-compose run --rm php ./vendor/bin/doctrine-module migrations:generate
docker-compose run --rm php ./vendor/bin/doctrine-module migrations:diff
docker-compose run --rm php ./vendor/bin/doctrine-module migrations:execute 20120714005702 -n
docker-compose run --rm php ./vendor/bin/doctrine-module migrations:migrate --no-interaction
39 changes: 39 additions & 0 deletions DEVELOP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Development
===========

Unit tests rely on a mysql installation so all unit tests are ran through
docker. To run all unit tests execute:

```
docker-compose run --rm php composer test
```

Running unit tests with code coverage requires you build the docker
composer with XDEBUG=1

```
docker-compose build --build-arg XDEBUG=1
```

To change docker to a different php version

```
docker-compose build --build-arg PHP_VERSION=7.3
```

then run the unit tests as

```
docker-compose run --rm php composer test-coverage
```

Run phpcs as
```
docker-compose run --rm php composer cs-check src test config
```


Console Commands
----------------

To run functional tests on console commands as found in `.travis/run-cli.sh` you must first copy `.travis/config/application.config.php` to `config/application.config.php`
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
"laminas/laminas-mvc-console": "^1.2",
"laminas/laminas-serializer": "^2.8",
"ocramius/proxy-manager": "^2.2",
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "^3.5"
"phpunit/phpunit": "^8.5"
},
"suggest": {
"laminas/laminas-form": "if you want to use form elements backed by Doctrine",
Expand Down
76 changes: 39 additions & 37 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading