Skip to content

Commit

Permalink
add phpunit.xml variations
Browse files Browse the repository at this point in the history
  • Loading branch information
stancl committed Aug 4, 2019
1 parent 7c598ae commit 8999079
Show file tree
Hide file tree
Showing 8 changed files with 628 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ vendor/
.vscode/
psysh
.phpunit.result.cache
phpunit_var_*.xml
phpunit_var_*.xml
coverage/
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@ php:
services:
- docker

before_install:
- docker-compose up -d

install:
- travis_retry docker-compose exec test composer require --no-interaction "laravel/framework:$LARAVEL_VERSION" "orchestra/testbench:$TESTBENCH_VERSION"

before_script:
- export DB_USERNAME=root DB_PASSWORD="" DB_DATABASE=tenancy CODECOV_TOKEN="24382d15-84e7-4a55-bea4-c4df96a24a9b"
- cat vendor/laravel/framework/src/Illuminate/Foundation/Application.php| grep 'const VERSION'

script: docker-compose exec test vendor/bin/phpunit -v --coverage-clover=coverage.xml

after_script:
- docker-compose down
script: ./test

after_success:
- bash <(curl -s https://codecov.io/bash)
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ RUN apt-get update \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& mkdir /run/php

RUN apt-get install php7.2-redis
RUN apt-get install -y php7.2-redis

RUN apt-get install -y python3

RUN apt-get install -y php7.2-dev php-pear
RUN pecl install xdebug
# RUN echo '' > /etc/php/7.2/cli/conf.d/20-xdebug.ini
# RUN echo 'zend_extension=/usr/lib/php/20170718/xdebug.so' >> /etc/php/7.2/cli/php.ini
RUN echo 'zend_extension=/usr/lib/php/20170718/xdebug.so' > /etc/php/7.2/cli/conf.d/20-xdebug.ini

RUN apt-get -y autoremove \
&& apt-get clean \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ However, you still need to reload nginx configuration to apply the changes to co

### With Docker

If you have Docker installed, simply run `docker-compose exec test vendor/bin/phpunit -v`. If you need to run the tests multiple times during development, run `./test` to run the tests. This script runs `docker-compose up -d` and phpunit via the `test` container. When you're done testing, run `docker-compose down` to shut down the containers.
If you have Docker installed, simply run `./test`. When you're done testing, run `docker-compose down` to shut down the containers.

### Without Docker

Expand Down
592 changes: 592 additions & 0 deletions clover.xml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"psy/psysh": "@stable",
"laravel/framework": "5.8.*||5.7.*",
"orchestra/testbench": "~3.7||~3.8",
"league/flysystem-aws-s3-v3": "~1.0"
"league/flysystem-aws-s3-v3": "~1.0",
"phpunit/phpcov": "^6.0"
},
"autoload": {
"psr-4": {
Expand Down
42 changes: 20 additions & 22 deletions test
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
#!/bin/bash
#!/usr/bin/env python3
from os import system
import argparse

# for development
docker-compose up -d
system('docker-compose up -d')

# Specify variant using `export VARIANT=1`
if [[ -z "${VARIANT}" ]]; then
variants=(1 2)
else
variants=( $VARIANT )
fi
parser = argparse.ArgumentParser()
parser.add_argument("--variants", default='1,2',
help="Comma-separated values. Which test variants should be run.")
args, other = parser.parse_known_args()

for variant in "${variants[@]}"
do
export filename_base="phpunit_var_$variant"

(cat phpunit.xml | sed -e "s/\"STANCL_TENANCY_TEST_VARIANT\" value=\"1\"/\"STANCL_TENANCY_TEST_VARIANT\" value=\"$variant\"/g") > "$filename_base.xml"

printf "Test variant: $variant\n\n"
variants = args.variants.split(',')

docker-compose exec test vendor/bin/phpunit \
--configuration "$filename_base.xml" \
--coverage-php "$filename_base.cov" \
"$@"
done
for variant in variants:
filename_base = "phpunit_var_" + variant
with open('phpunit.xml', 'r') as inp, open(filename_base + '.xml', 'w') as out:
out.write(inp.read().replace('"STANCL_TENANCY_TEST_VARIANT" value="1"',
'"STANCL_TENANCY_TEST_VARIANT" value="%s"' % variant))

# todo merge cov reports
print("Test variant: %s\n" % variant)

system('docker-compose exec test vendor/bin/phpunit --configuration "%s" --coverage-php %s %s'
% (filename_base + '.xml', 'coverage/' + filename_base + '.cov', ' '.join(other)))

system("docker-compose exec test vendor/bin/phpcov merge --clover clover.xml coverage/")
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function getEnvironmentSetUp($app)
'tenancy.migrations_directory' => database_path('../migrations'),
]);

switch((string) env('STANCL_TENANCY_TEST_VARIANT', '1')) {
switch ((string) env('STANCL_TENANCY_TEST_VARIANT', '1')) {
case '2':
$app['config']->set([
'tenancy.redis.tenancy' => true,
Expand Down

0 comments on commit 8999079

Please sign in to comment.