Run PHPStan for unit tests

[MAILPOET-2429]
This commit is contained in:
Jan Jakeš
2019-10-16 13:13:00 +02:00
committed by Jack Kitterhing
parent 078223cd64
commit 39932e9846
3 changed files with 43 additions and 13 deletions

View File

@@ -453,22 +453,32 @@ class RoboFile extends \Robo\Tasks {
}
function qaPhpstan() {
$dir = __DIR__;
$task = implode(' ', [
'WP_ROOT="' . getenv('WP_ROOT') . '"',
'php -d memory_limit=2G',
"$dir/tasks/phpstan/vendor/bin/phpstan analyse ",
'--level 5',
]);
// PHPStan must be run out of main plugin directory to avoid its autoloading
// from vendor/autoload.php where some dev dependencies cause conflicts.
$dir = __DIR__;
return $this->collectionBuilder()
->taskExec('rm -rf ' . __DIR__ . '/vendor/goaop')
->taskExec('rm -rf ' . __DIR__ . '/vendor/nikic')
->taskExec('cd ' . __DIR__ . ' && ./tools/vendor/composer.phar dump-autoload')
->taskExec(
'WP_ROOT="' . getenv('WP_ROOT') . '" ' .
'php -d memory_limit=2G ' .
"$dir/tasks/phpstan/vendor/bin/phpstan analyse " .
"--configuration $dir/tasks/phpstan/phpstan.neon " .
'--level 5 ' .
"$dir/lib"
)
// lib
->taskExec($task)
->arg("$dir/lib")
->dir(__DIR__ . '/tasks/phpstan')
// tests
->taskExec($task)
->rawArg('--configuration=phpstan-tests.neon')
->arg("$dir/tests/unit")
->dir(__DIR__ . '/tasks/phpstan')
->taskExec('cd ' . __DIR__ . ' && ./tools/vendor/composer.phar install')
->run();
}

View File

@@ -0,0 +1,13 @@
parameters:
mailpoetDir: %rootDir%/../../../../..
tmpDir: ../../temp/phpstan
bootstrap: bootstrap.php
autoload_files:
- %mailpoetDir%/vendor/autoload.php
- %mailpoetDir%/vendor/codeception/codeception/autoload.php
- %mailpoetDir%/vendor/codeception/verify/src/Codeception/function.php
- %mailpoetDir%/vendor/codeception/verify/src/Codeception/Verify.php
autoload_directories:
- %mailpoetDir%/tests/unit
dynamicConstantNames:
- WP_DEBUG

View File

@@ -1,7 +1,9 @@
<?php
function __($text) {
return $text;
if (!function_exists('__')) {
function __($text) {
return $text;
}
}
// Fix for mocking WPFunctions
@@ -10,8 +12,13 @@ if (!defined('OBJECT')) {
define( 'OBJECT', 'OBJECT' );
}
define('ABSPATH', '/');
define('WP_DEBUG', false);
if (!defined('ABSPATH')) {
define('ABSPATH', '/');
}
if (!defined('WP_DEBUG')) {
define('WP_DEBUG', false);
}
$console = new \Codeception\Lib\Console\Output([]);