diff --git a/.gitignore b/.gitignore index 4154e11b..daea5f2f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .idea bin/.rr.* bin/rr +config/roadrunner/.pid build !docker/build composer.lock diff --git a/bin/test/run-api-tests.sh b/bin/test/run-api-tests.sh index 3f6e27e6..1f61b681 100755 --- a/bin/test/run-api-tests.sh +++ b/bin/test/run-api-tests.sh @@ -2,24 +2,36 @@ export APP_ENV=test export DB_DRIVER=postgres export TEST_ENV=api +export TEST_RUNTIME=${TEST_RUNTIME:-"openswoole"} export GENERATE_COVERAGE=${GENERATE_COVERAGE:-"no"} # Reset logs +OUTPUT_LOGS=data/log/api-tests/output.log rm -rf data/log/api-tests mkdir data/log/api-tests -touch data/log/api-tests/output.log +touch $OUTPUT_LOGS # Try to stop server just in case it hanged in last execution -vendor/bin/laminas mezzio:swoole:stop +[[ $TEST_RUNTIME == 'openswoole' ]] && vendor/bin/laminas mezzio:swoole:stop +[[ $TEST_RUNTIME == 'rr' ]] && bin/rr stop -f echo 'Starting server...' -vendor/bin/laminas mezzio:swoole:start -d -sleep 2 +[[ $TEST_RUNTIME == 'openswoole' ]] && vendor/bin/laminas mezzio:swoole:start -d +[[ $TEST_RUNTIME == 'rr' ]] && bin/rr serve -p -c=config/roadrunner/.rr.dev.yml \ + -o=http.address=0.0.0.0:9999 \ + -o=logs.encoding=json \ + -o=logs.channels.http.encoding=json \ + -o=logs.channels.server.encoding=json \ + -o=logs.output="${PWD}/${OUTPUT_LOGS}" \ + -o=logs.channels.http.output="${PWD}/${OUTPUT_LOGS}" \ + -o=logs.channels.server.output="${PWD}/${OUTPUT_LOGS}" & +sleep 2 # Let's give the server a couple of seconds to start vendor/bin/phpunit --order-by=random -c phpunit-api.xml --testdox --colors=always --log-junit=build/coverage-api/junit.xml $* testsExitCode=$? -vendor/bin/laminas mezzio:swoole:stop +[[ $TEST_RUNTIME == 'openswoole' ]] && vendor/bin/laminas mezzio:swoole:stop +[[ $TEST_RUNTIME == 'rr' ]] && bin/rr stop -c config/roadrunner/.rr.dev.yml -o=http.address=0.0.0.0:9999 # Exit this script with the same code as the tests. If tests failed, this script has to fail exit $testsExitCode diff --git a/composer.json b/composer.json index 0028e27f..54d180e3 100644 --- a/composer.json +++ b/composer.json @@ -122,6 +122,7 @@ "test:db:postgres": "DB_DRIVER=postgres composer test:db:sqlite", "test:db:ms": "DB_DRIVER=mssql composer test:db:sqlite", "test:api": "bin/test/run-api-tests.sh", + "test:api:rr": "TEST_RUNTIME=rr bin/test/run-api-tests.sh", "test:api:ci": "GENERATE_COVERAGE=yes composer test:api", "test:api:pretty": "GENERATE_COVERAGE=pretty composer test:api", "test:cli": "APP_ENV=test DB_DRIVER=maria TEST_ENV=cli php vendor/bin/phpunit --order-by=random --colors=always --testdox -c phpunit-cli.xml --log-junit=build/coverage-cli/junit.xml", diff --git a/config/roadrunner/.rr.dev.yml b/config/roadrunner/.rr.dev.yml index 23e9679f..7f06fc9f 100644 --- a/config/roadrunner/.rr.dev.yml +++ b/config/roadrunner/.rr.dev.yml @@ -43,7 +43,7 @@ logs: reload: interval: 1s - patterns: ['.php', '.yml', '.yaml'] + patterns: ['.php'] services: http: dirs: ['../../bin', '../../config', '../../data/migrations', '../../docker', '../../module', '../../vendor'] diff --git a/config/test/bootstrap_api_tests.php b/config/test/bootstrap_api_tests.php index 52c9d4fb..bc119284 100644 --- a/config/test/bootstrap_api_tests.php +++ b/config/test/bootstrap_api_tests.php @@ -10,8 +10,8 @@ use Psr\Container\ContainerInterface; use function register_shutdown_function; use function sprintf; -use const ShlinkioTest\Shlink\SWOOLE_TESTING_HOST; -use const ShlinkioTest\Shlink\SWOOLE_TESTING_PORT; +use const ShlinkioTest\Shlink\API_TESTS_HOST; +use const ShlinkioTest\Shlink\API_TESTS_PORT; /** @var ContainerInterface $container */ $container = require __DIR__ . '/../container.php'; @@ -24,7 +24,7 @@ $httpClient = $container->get('shlink_test_api_client'); register_shutdown_function(function () use ($httpClient): void { $httpClient->request( 'GET', - sprintf('http://%s:%s/api-tests/stop-coverage', SWOOLE_TESTING_HOST, SWOOLE_TESTING_PORT), + sprintf('http://%s:%s/api-tests/stop-coverage', API_TESTS_HOST, API_TESTS_PORT), ); }); diff --git a/config/test/constants.php b/config/test/constants.php index a2c880fc..c767abc9 100644 --- a/config/test/constants.php +++ b/config/test/constants.php @@ -4,5 +4,5 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink; -const SWOOLE_TESTING_HOST = '127.0.0.1'; -const SWOOLE_TESTING_PORT = 9999; +const API_TESTS_HOST = '127.0.0.1'; +const API_TESTS_PORT = 9999; diff --git a/config/test/test_config.global.php b/config/test/test_config.global.php index 8998dd22..9b338d7a 100644 --- a/config/test/test_config.global.php +++ b/config/test/test_config.global.php @@ -34,8 +34,8 @@ use function Shlinkio\Shlink\Config\env; use function sprintf; use function sys_get_temp_dir; -use const ShlinkioTest\Shlink\SWOOLE_TESTING_HOST; -use const ShlinkioTest\Shlink\SWOOLE_TESTING_PORT; +use const ShlinkioTest\Shlink\API_TESTS_HOST; +use const ShlinkioTest\Shlink\API_TESTS_PORT; $isApiTest = env('TEST_ENV') === 'api'; $isCliTest = env('TEST_ENV') === 'cli'; @@ -136,8 +136,8 @@ return [ 'mezzio-swoole' => [ 'enable_coroutine' => false, 'swoole-http-server' => [ - 'host' => SWOOLE_TESTING_HOST, - 'port' => SWOOLE_TESTING_PORT, + 'host' => API_TESTS_HOST, + 'port' => API_TESTS_PORT, 'process-name' => 'shlink_test', 'options' => [ 'pid_file' => sys_get_temp_dir() . '/shlink-test-swoole.pid', @@ -188,7 +188,7 @@ return [ 'dependencies' => [ 'services' => [ 'shlink_test_api_client' => new Client([ - 'base_uri' => sprintf('http://%s:%s/', SWOOLE_TESTING_HOST, SWOOLE_TESTING_PORT), + 'base_uri' => sprintf('http://%s:%s/', API_TESTS_HOST, API_TESTS_PORT), 'http_errors' => false, ]), ], diff --git a/indocker b/indocker index 789386ac..3dde53c4 100755 --- a/indocker +++ b/indocker @@ -1,8 +1,13 @@ #!/usr/bin/env bash # Run docker containers if they are not up yet -if ! [[ $(docker ps | grep shlink_swoole) ]]; then +if ! [[ $(docker ps | grep shlink) ]]; then docker-compose up -d fi -docker exec -it shlink_swoole /bin/sh -c "$*" +if [[ "$*" == *"test:api:rr"* ]]; then + # API tests should be run inside the RoadRunner container when the test runtime is RoadRunner + docker exec -it shlink_roadrunner /bin/sh -c "$*" +else + docker exec -it shlink_swoole /bin/sh -c "$*" +fi