diff --git a/.gitignore b/.gitignore index fd3181fd..2a8d8538 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ vendor/ .vscode/ psysh .phpunit.result.cache -phpunit_var_*.xml \ No newline at end of file +phpunit_var_*.xml +coverage/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index ff31db18..dfe0af41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,6 @@ 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" @@ -19,10 +16,7 @@ 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) diff --git a/Dockerfile b/Dockerfile index a6727e03..a6512668 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ diff --git a/README.md b/README.md index 3f0fa9bb..d09f9aa7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/clover.xml b/clover.xml new file mode 100644 index 00000000..a5f1b9a4 --- /dev/null +++ b/clover.xml @@ -0,0 +1,592 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/composer.json b/composer.json index 6e55ab95..cdcbe6c8 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/test b/test index 67ce4feb..0d9f4044 100755 --- a/test +++ b/test @@ -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/") diff --git a/tests/TestCase.php b/tests/TestCase.php index e1659a8b..f9a67463 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -89,7 +89,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase '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,