diff --git a/CHANGELOG.md b/CHANGELOG.md index 17d1799f..97cf925c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this ### Changed * [#1036](https://github.com/shlinkio/shlink/issues/1036) Updated to `happyr/doctrine-specification` 2.0. * [#1039](https://github.com/shlinkio/shlink/issues/1039) Updated to `endroid/qr-code` 4.0. +* [#1008](https://github.com/shlinkio/shlink/issues/1008) Ensured all logs are sent to the filesystem while running API tests, which helps debugging the reason for tests to fail. ### Deprecated * *Nothing* diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eec7b0fb..837f7593 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -96,12 +96,14 @@ In order to ensure stability and no regressions are introduced while developing The project provides some tooling to run them against any of the supported database engines. -* **API tests**: These are E2E tests that spin up an instance of the app and test it from the outside, by interacting with the REST API. +* **API tests**: These are E2E tests that spin up an instance of the app with swoole, and test it from the outside by interacting with the REST API. These are the best tests to catch regressions, and to verify everything behaves as expected. They use Postgres as the database engine, and include some fixtures that ensure the same data exists at the beginning of the execution. + Since the app instance is run on a process different from the one running the tests, when a test fails it might not be obvious why. To help debugging that, the app will dump all its logs inside `data/log/api-tests`, where you will find the `shlink.log` and `access.log` files. + * **CLI tests**: *TBD. Once included, its purpose will be the same as API tests, but running through the command line* Depending on the kind of contribution, maybe not all kinds of tests are needed, but the more you provide, the better. diff --git a/bin/test/run-api-tests.sh b/bin/test/run-api-tests.sh index 07b36881..dbd87a84 100755 --- a/bin/test/run-api-tests.sh +++ b/bin/test/run-api-tests.sh @@ -3,6 +3,8 @@ export APP_ENV=test export DB_DRIVER=postgres export TEST_ENV=api +rm -rf data/log/api-tests + # Try to stop server just in case it hanged in last execution vendor/bin/laminas mezzio:swoole:stop diff --git a/composer.json b/composer.json index 53acdf0a..89764118 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "laminas/laminas-stdlib": "^3.2", "lcobucci/jwt": "^4.0", "league/uri": "^6.2", - "lstrojny/functional-php": "^1.15", + "lstrojny/functional-php": "^1.17", "mezzio/mezzio": "^3.3", "mezzio/mezzio-fastroute": "^3.1", "mezzio/mezzio-problem-details": "^1.3", diff --git a/config/test/test_config.global.php b/config/test/test_config.global.php index 3608257e..c6d90e39 100644 --- a/config/test/test_config.global.php +++ b/config/test/test_config.global.php @@ -9,6 +9,8 @@ use Laminas\ConfigAggregator\ConfigAggregator; use Laminas\Diactoros\Response\EmptyResponse; use Laminas\ServiceManager\Factory\InvokableFactory; use Laminas\Stdlib\Glob; +use Monolog\Handler\StreamHandler; +use Monolog\Logger; use PDO; use PHPUnit\Runner\Version; use SebastianBergmann\CodeCoverage\CodeCoverage; @@ -80,6 +82,18 @@ $buildDbConnection = function (): array { return $driverConfigMap[$driver] ?? []; }; +$buildTestLoggerConfig = fn (string $handlerName, string $filename) => [ + 'handlers' => [ + $handlerName => [ + 'name' => StreamHandler::class, + 'params' => [ + 'level' => Logger::DEBUG, + 'stream' => sprintf('data/log/api-tests/%s', $filename), + ], + ], + ], +]; + return [ 'debug' => true, @@ -163,4 +177,9 @@ return [ ], ], + 'logger' => [ + 'Shlink' => $buildTestLoggerConfig('shlink_handler', 'shlink.log'), + 'Access' => $buildTestLoggerConfig('access_handler', 'access.log'), + ], + ];