diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c011d1c0..a80a4d400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 1. [](#new) * Added phpstan: PHP Static Analysis Tool [#2393](https://github.com/getgrav/grav/pull/2393) + * Added `composer test-plugins` to test plugin issues with the current version of Grav * Grav 1.6: Renamed `$grav['users']` service to `$grav['accounts']` * Added `Flex::getObjects()` and `Flex::getMixedCollection()` methods for co-mingled collections * Added support to use single Flex key parameter in `Flex::getObject()` method diff --git a/composer.json b/composer.json index 487c9a16c..608072f5c 100644 --- a/composer.json +++ b/composer.json @@ -91,6 +91,7 @@ "post-create-project-cmd": "bin/grav install", "phpstan": "vendor/bin/phpstan analyse -l 2 -c ./tests/phpstan/phpstan.neon system/src --memory-limit=256M", "phpstan-framework": "vendor/bin/phpstan analyse -l 5 -c ./tests/phpstan/phpstan.neon system/src/Grav/Framework --memory-limit=256M", + "test-plugins": "vendor/bin/phpstan analyse -l 0 -c ./tests/phpstan/plugins.neon user/plugins --memory-limit=256M", "test": "vendor/bin/codecept run unit", "test-windows": "vendor\\bin\\codecept run unit" }, diff --git a/tests/phpstan/plugins-bootstrap.php b/tests/phpstan/plugins-bootstrap.php new file mode 100644 index 000000000..8d5492971 --- /dev/null +++ b/tests/phpstan/plugins-bootstrap.php @@ -0,0 +1,41 @@ + $autoload)); +$grav->setup('tests'); +$grav['config']->init(); + +// Find all plugins in Grav installation and autoload their classes. + +/** @var UniformResourceLocator $locator */ +$locator = Grav::instance()['locator']; +$iterator = $locator->getIterator('plugins://'); +foreach($iterator as $directory) { + if (!$directory->isDir()) { + continue; + } + $autoloader = $directory->getPathname() . '/vendor/autoload.php'; + if (file_exists($autoloader)) { + require $autoloader; + } +} diff --git a/tests/phpstan/plugins.neon b/tests/phpstan/plugins.neon new file mode 100644 index 000000000..f2f500120 --- /dev/null +++ b/tests/phpstan/plugins.neon @@ -0,0 +1,19 @@ +includes: + #- vendor/phpstan/phpstan-strict-rules/rules.neon +parameters: + fileExtensions: + - php + excludes_analyse: + - %currentWorkingDirectory%/user/plugins/*/vendor/* + - %currentWorkingDirectory%/user/plugins/*/tests/* + bootstrap: tests/phpstan/plugins-bootstrap.php + reportUnmatchedIgnoredErrors: true + universalObjectCratesClasses: + - Grav\Common\Config\Config + - Grav\Common\Config\Languages + - Grav\Common\Config\Setup + - Grav\Common\Data\Data + - Grav\Common\GPM\Common\Package + - Grav\Common\GPM\Local\Package + - Grav\Common\GPM\Remote\Package + - Grav\Common\Session