-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from mitrpaka/feature/phpstan-drupal
Add support for Drupal deprecation testing
- Loading branch information
Showing
11 changed files
with
207 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
parameters: | ||
customRulesetUsed: true | ||
reportUnmatchedIgnoredErrors: false | ||
# Ignore phpstan-drupal extension's rules. | ||
ignoreErrors: | ||
- '#\Drupal calls should be avoided in classes, use dependency injection instead#' | ||
- '#Plugin definitions cannot be altered.#' | ||
- '#Missing cache backend declaration for performance.#' | ||
- '#Plugin manager has cache backend specified but does not declare cache tags.#' | ||
includes: | ||
- vendor/mglaman/phpstan-drupal/extension.neon | ||
- vendor/phpstan/phpstan-deprecation-rules/rules.neon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
parameters: | ||
customRulesetUsed: true | ||
reportUnmatchedIgnoredErrors: false | ||
# Ignore phpstan-drupal extension's rules. | ||
ignoreErrors: | ||
- '#\Drupal calls should be avoided in classes, use dependency injection instead#' | ||
- '#Plugin definitions cannot be altered.#' | ||
- '#Missing cache backend declaration for performance.#' | ||
- '#Plugin manager has cache backend specified but does not declare cache tags.#' | ||
includes: | ||
- vendor/phpstan/phpstan-deprecation-rules/rules.neon |
12 changes: 12 additions & 0 deletions
12
src/Task/PhpstanCheckDeprecation/PhpstanCheckDeprecationExtensionLoader.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Wunderio\GrumPHP\Task\PhpstanCheckDeprecation; | ||
|
||
use Wunderio\GrumPHP\Task\AbstractExternalExtensionLoader; | ||
|
||
/** | ||
* Class PhpstanCheckDeprecationExtensionLoader. | ||
* | ||
* @package Wunderio\GrumPHP\Task | ||
*/ | ||
class PhpstanCheckDeprecationExtensionLoader extends AbstractExternalExtensionLoader {} |
38 changes: 38 additions & 0 deletions
38
src/Task/PhpstanCheckDeprecation/PhpstanCheckDeprecationTask.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Wunderio\GrumPHP\Task\PhpstanCheckDeprecation; | ||
|
||
use GrumPHP\Collection\ProcessArgumentsCollection; | ||
use Wunderio\GrumPHP\Task\AbstractMultiPathProcessingTask; | ||
|
||
/** | ||
* Class PhpstanCheckDeprecationTask. | ||
* | ||
* @package Wunderio\GrumPHP\Task | ||
*/ | ||
class PhpstanCheckDeprecationTask extends AbstractMultiPathProcessingTask { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildArguments(iterable $files): ProcessArgumentsCollection { | ||
$arguments = $this->processBuilder->createArgumentsForCommand('phpstan'); | ||
$config = $this->getConfiguration(); | ||
$arguments->add('analyse'); | ||
$arguments->addOptionalArgument('--autoload-file=%s', $config['autoload_file']); | ||
$arguments->addOptionalArgument('--configuration=%s', $config['configuration']); | ||
$arguments->addOptionalArgument('--memory-limit=%s', $config['memory_limit']); | ||
$arguments->addOptionalMixedArgument('--level=%s', $config['level']); | ||
$arguments->add('--no-ansi'); | ||
$arguments->add('--no-interaction'); | ||
$arguments->add('--no-progress'); | ||
|
||
foreach ($files as $file) { | ||
$arguments->add($file); | ||
} | ||
return $arguments; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# phpstan_check_deprecation | ||
|
||
Check Drupal code against deprecation rules. | ||
|
||
### grumphp.yml (with current defaults): | ||
````yml | ||
parameters: | ||
tasks: | ||
phpstan_check_deprecation: | ||
ignore_patterns: | ||
- '/vendor/' | ||
- '/node_modules/' | ||
- '/core/' | ||
- '/libraries/' | ||
extensions: ['php', 'inc', 'module', 'install', 'theme'] | ||
run_on: ['.'] | ||
autoload_file: | ||
defaults: ~ | ||
allowed_types: ['string', 'null'] | ||
configuration: | ||
defaults: 'phpstan.neon' | ||
allowed_types: ['string', 'null'] | ||
memory_limit: | ||
defaults: ~ | ||
allowed_types: ['string', 'null'] | ||
level: | ||
defaults: ~ | ||
allowed_types: ['string', 'null'] | ||
extensions: | ||
- Wunderio\GrumPHP\Task\PhpstanCheckDeprecation\PhpstanCheckDeprecationExtensionLoader | ||
```` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
tests/PhpstanCheckDeprecation/PhpstanCheckDeprecationTaskTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Tests covering PhpstanCheckDeprecationTask. | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
use GrumPHP\Collection\ProcessArgumentsCollection; | ||
use GrumPHP\Configuration\GrumPHP; | ||
use GrumPHP\Formatter\ProcessFormatterInterface; | ||
use GrumPHP\Process\ProcessBuilder; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Yaml\Yaml; | ||
use Wunderio\GrumPHP\Task\PhpstanCheckDeprecation\PhpstanCheckDeprecationTask; | ||
|
||
/** | ||
* Class PhpstanTaskTest. | ||
*/ | ||
final class PhpstanCheckDeprecationTaskTest extends TestCase { | ||
|
||
/** | ||
* Test building arguments. | ||
* | ||
* @covers \Wunderio\GrumPHP\Task\Phpstan\PhpstanDrupalCheckTask::buildArguments | ||
*/ | ||
public function testBuildsProcessArguments(): void { | ||
$processBuilder = $this->createMock(ProcessBuilder::class); | ||
$stub = $this->getMockBuilder(PhpstanCheckDeprecationTask::class)->setConstructorArgs([ | ||
$this->createMock(GrumPHP::class), | ||
$processBuilder, | ||
$this->createMock(ProcessFormatterInterface::class), | ||
]) | ||
->setMethodsExcept(['buildArguments'])->getMock(); | ||
$arguments = $this->createMock(ProcessArgumentsCollection::class); | ||
|
||
$files = ['file1.php', 'file2.php', 'dir1/']; | ||
$processBuilder->expects($this->once()) | ||
->method('createArgumentsForCommand') | ||
->willReturn($arguments); | ||
|
||
$arguments->expects($this->exactly(7))->method('add'); | ||
$config = []; | ||
foreach ($this->getConfigurations() as $name => $option) { | ||
$config[$name] = $option['defaults']; | ||
} | ||
$stub->expects($this->once())->method('getConfiguration')->willReturn($config); | ||
|
||
$actual = $stub->buildArguments($files); | ||
$this->assertInstanceOf(ProcessArgumentsCollection::class, $actual); | ||
} | ||
|
||
/** | ||
* Gets task configurations. | ||
* | ||
* @return array | ||
* Array of options. | ||
*/ | ||
protected function getConfigurations(): array { | ||
$tasks = Yaml::parseFile(__DIR__ . '/../../src/Task/tasks.yml'); | ||
return $tasks[PhpstanCheckDeprecationTask::class]['options']; | ||
} | ||
|
||
} |