chg: upgrade to phpunit9, add pcov for coverage in docker build

pull/9143/head
Luciano Righetti 2023-06-15 16:46:22 +02:00
parent c3ec5a791f
commit 9a54a81969
5 changed files with 48 additions and 33 deletions

1
.gitignore vendored
View File

@ -10,6 +10,7 @@ webroot/scss/*.css
.vscode .vscode
docker/run/ docker/run/
.phpunit.result.cache .phpunit.result.cache
.phpunit.cache
config.json config.json
phpunit.xml phpunit.xml
docker-compose.override.yml docker-compose.override.yml

View File

@ -9,7 +9,7 @@
"admad/cakephp-social-auth": "^1.1", "admad/cakephp-social-auth": "^1.1",
"cakephp/authentication": "^2.0", "cakephp/authentication": "^2.0",
"cakephp/authorization": "^2.0", "cakephp/authorization": "^2.0",
"cakephp/cakephp": "^4.3", "cakephp/cakephp": "^4.4",
"cakephp/migrations": "^3.0", "cakephp/migrations": "^3.0",
"cakephp/plugin-installer": "^1.2", "cakephp/plugin-installer": "^1.2",
"erusev/parsedown": "^1.7", "erusev/parsedown": "^1.7",
@ -25,7 +25,7 @@
"josegonzalez/dotenv": "^3.2", "josegonzalez/dotenv": "^3.2",
"league/openapi-psr7-validator": "^0.17", "league/openapi-psr7-validator": "^0.17",
"phpstan/phpstan": "^1.10", "phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^8.5", "phpunit/phpunit": "^9.5",
"psy/psysh": "@stable", "psy/psysh": "@stable",
"wiremock-php/wiremock-php": "^2.33" "wiremock-php/wiremock-php": "^2.33"
}, },
@ -78,6 +78,5 @@
"dealerdirect/phpcodesniffer-composer-installer": true, "dealerdirect/phpcodesniffer-composer-installer": true,
"cakephp/plugin-installer": true "cakephp/plugin-installer": true
} }
}, }
"minimum-stability": "dev"
} }

View File

@ -65,8 +65,8 @@ RUN usermod --uid $UID --gid $GID www-data
COPY . /var/www/html/ COPY . /var/www/html/
# Install development dependencies # Install development dependencies
RUN pecl install -f xdebug \ RUN pecl install -f xdebug pcov \
&& docker-php-ext-enable xdebug && docker-php-ext-enable xdebug pcov
# Install additional packages # Install additional packages
RUN apt-get update \ RUN apt-get update \

View File

@ -1,16 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" processIsolation="false" stopOnFailure="false" bootstrap="tests/bootstrap.php"> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<php> xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
<ini name="memory_limit" value="-1" /> bootstrap="tests/bootstrap.php"
<ini name="apc.enable_cli" value="1" /> cacheResultFile=".phpunit.cache/test-results"
<env name="WIREMOCK_HOST" value="localhost" /> executionOrder="depends,defects"
<env name="WIREMOCK_PORT" value="8080" /> forceCoversAnnotation="false"
<env name="OPENAPI_SPEC" value="webroot/docs/openapi.yaml" /> beStrictAboutCoversAnnotation="true"
<env name="SKIP_DB_MIGRATIONS" value="0" /> beStrictAboutOutputDuringTests="true"
</php> beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
<!-- Add any additional test suites you want to run here --> failOnRisky="true"
failOnWarning="false"
colors="true"
verbose="true">
<testsuites> <testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
<testsuite name="app"> <testsuite name="app">
<directory>tests/TestCase/</directory> <directory>tests/TestCase/</directory>
</testsuite> </testsuite>
@ -21,19 +27,22 @@
<directory>./tests/TestCase/Api</directory> <directory>./tests/TestCase/Api</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<php>
<extensions> <ini name="memory_limit" value="-1" />
<extension class="\Cake\TestSuite\Fixture\PHPUnitExtension" /> <ini name="apc.enable_cli" value="1" />
</extensions> <env name="WIREMOCK_HOST" value="localhost" />
<env name="WIREMOCK_PORT" value="8080" />
<!-- Ignore vendor tests in code coverage reports --> <env name="OPENAPI_SPEC" value="webroot/docs/openapi.yaml" />
<filter> <env name="SKIP_DB_MIGRATIONS" value="0" />
<whitelist> </php>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory> <directory suffix=".php">src/</directory>
<directory suffix=".php">plugins/*/src/</directory> <directory suffix=".php">plugins/*/src/</directory>
</include>
<exclude> <exclude>
<file>src/Console/Installer.php</file> <file>src/Console/Installer.php</file>
</exclude> </exclude>
</whitelist> </coverage>
</filter>
</phpunit> </phpunit>

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/** /**
@ -14,6 +15,7 @@ declare(strict_types=1);
* @since 3.3.0 * @since 3.3.0
* @license https://opensource.org/licenses/mit-license.php MIT License * @license https://opensource.org/licenses/mit-license.php MIT License
*/ */
namespace App\Test\TestCase; namespace App\Test\TestCase;
use App\Application; use App\Application;
@ -21,19 +23,23 @@ use Cake\Error\Middleware\ErrorHandlerMiddleware;
use Cake\Http\MiddlewareQueue; use Cake\Http\MiddlewareQueue;
use Cake\Routing\Middleware\AssetMiddleware; use Cake\Routing\Middleware\AssetMiddleware;
use Cake\Routing\Middleware\RoutingMiddleware; use Cake\Routing\Middleware\RoutingMiddleware;
use Cake\TestSuite\IntegrationTestCase;
use InvalidArgumentException; use InvalidArgumentException;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/** /**
* ApplicationTest class * ApplicationTest class
*/ */
class ApplicationTest extends IntegrationTestCase class ApplicationTest extends TestCase
{ {
/** /**
* testBootstrap * testBootstrap
* *
* @return void * @return void
*/ */
use IntegrationTestTrait;
public function testBootstrap() public function testBootstrap()
{ {
$app = new Application(dirname(dirname(__DIR__)) . '/config'); $app = new Application(dirname(dirname(__DIR__)) . '/config');
@ -60,7 +66,7 @@ class ApplicationTest extends IntegrationTestCase
$app = $this->getMockBuilder(Application::class) $app = $this->getMockBuilder(Application::class)
->setConstructorArgs([dirname(dirname(__DIR__)) . '/config']) ->setConstructorArgs([dirname(dirname(__DIR__)) . '/config'])
->setMethods(['addPlugin']) ->onlyMethods(['addPlugin'])
->getMock(); ->getMock();
$app->method('addPlugin') $app->method('addPlugin')