From 92ae07dbca6181f60a6f6248c2e09d00781355f9 Mon Sep 17 00:00:00 2001 From: Antonio de la Vega Date: Tue, 14 May 2024 13:21:28 +0200 Subject: [PATCH 1/6] feat: Add task for twig-cs-fixer --- composer.json | 3 +- doc/tasks.md | 2 + doc/tasks/twigcsfixer.md | 37 ++++++++ resources/config/tasks.yml | 7 ++ src/Task/TwigCsFixer.php | 81 ++++++++++++++++++ test/Unit/Task/TwigCsFixerTest.php | 132 +++++++++++++++++++++++++++++ 6 files changed, 261 insertions(+), 1 deletion(-) create mode 100644 doc/tasks/twigcsfixer.md create mode 100644 src/Task/TwigCsFixer.php create mode 100644 test/Unit/Task/TwigCsFixerTest.php diff --git a/composer.json b/composer.json index c1ab2875..00d9b0e1 100644 --- a/composer.json +++ b/composer.json @@ -80,7 +80,8 @@ "sstalle/php7cc": "Lets GrumPHP check PHP 5.3 - 5.6 code compatibility with PHP 7.", "symfony/phpunit-bridge": "Lets GrumPHP run your unit tests with the phpunit-bridge of Symfony.", "symplify/easy-coding-standard": "Lets GrumPHP check coding standard.", - "vimeo/psalm": "Lets GrumPHP discover errors in your code without running it." + "vimeo/psalm": "Lets GrumPHP discover errors in your code without running it.", + "vincentlanglet/twig-cs-fixer": "Lets GrumPHP check and fix twig coding standard." }, "autoload": { "psr-4": { diff --git a/doc/tasks.md b/doc/tasks.md index bc618fad..4a92e9c0 100644 --- a/doc/tasks.md +++ b/doc/tasks.md @@ -63,6 +63,7 @@ grumphp: stylelint: ~ tester: ~ twigcs: ~ + twigcsfixer: ~ xmllint: ~ yamllint: ~ ``` @@ -129,6 +130,7 @@ Every task has its own default configuration. It is possible to overwrite the pa - [Stylelint](tasks/stylelint.md) - [Tester](tasks/tester.md) - [TwigCs](tasks/twigcs.md) +- [TwigCsFixer](tasks/twigcsfixer.md) - [XmlLint](tasks/xmllint.md) - [YamlLint](tasks/yamllint.md) diff --git a/doc/tasks/twigcsfixer.md b/doc/tasks/twigcsfixer.md new file mode 100644 index 00000000..bb17d258 --- /dev/null +++ b/doc/tasks/twigcsfixer.md @@ -0,0 +1,37 @@ +# TwigCs + +Check and fix Twig coding standard using [VincentLanglet/Twig-CS-Fixer](https://github.com/VincentLanglet/Twig-CS-Fixer). +You can check config file [here](https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/docs/configuration.md). + +***Composer*** + +``` +composer require --dev "vincentlanglet/twig-cs-fixer:>=2" +``` + +***Config*** + +The task lives under the `twigcsfixer` namespace and has following configurable parameters: + +```yaml +# grumphp.yml +grumphp: + tasks: + twigcsfixer: + path: '.' + triggered_by: ['twig'] +``` + +**path** + +*Default: null* + +By default `.` (current folder) will be used. +On precommit the path will not be used, changed files will be passed as arguments instead. +You can specify an alternate location by changing this option. If the path doesn't exist or is not accessible an exception will be thrown. + +**triggered_by** + +*Default: [twig]* + +This option will specify which file extensions will trigger this task. diff --git a/resources/config/tasks.yml b/resources/config/tasks.yml index c1d5aafe..318dbe8d 100644 --- a/resources/config/tasks.yml +++ b/resources/config/tasks.yml @@ -401,6 +401,13 @@ services: tags: - {name: grumphp.task, task: twigcs} + GrumPHP\Task\TwigCsFixer: + arguments: + - '@process_builder' + - '@formatter.raw_process' + tags: + - {name: grumphp.task, task: twigcsfixer} + GrumPHP\Task\XmlLint: arguments: - '@linter.xmllint' diff --git a/src/Task/TwigCsFixer.php b/src/Task/TwigCsFixer.php new file mode 100644 index 00000000..a8b81e6e --- /dev/null +++ b/src/Task/TwigCsFixer.php @@ -0,0 +1,81 @@ + + */ +class TwigCsFixer extends AbstractExternalTask +{ + public static function getConfigurableOptions(): ConfigOptionsResolver + { + $resolver = new OptionsResolver(); + $resolver->setDefaults([ + 'path' => '.', + 'triggered_by' => ['twig'], + ]); + + $resolver->addAllowedTypes('path', ['string']); + + return ConfigOptionsResolver::fromOptionsResolver($resolver); + } + + public function canRunInContext(ContextInterface $context): bool + { + return $context instanceof GitPreCommitContext || $context instanceof RunContext; + } + + public function run(ContextInterface $context): TaskResultInterface + { + $config = $this->getConfig()->getOptions(); + + $files = $context->getFiles()->extensions($config['triggered_by']); + if (0 === \count($files)) { + return TaskResult::createSkipped($this, $context); + } + + $arguments = $this->processBuilder->createArgumentsForCommand('twig-cs-fixer'); + $arguments->add('lint'); + $arguments->add('--report=text'); + + if ($context instanceof GitPreCommitContext) { + $arguments->addFiles($files); + } + + if ($context instanceof RunContext) { + $arguments->add($config['path']); + } + + $process = $this->processBuilder->buildProcess($arguments); + + $process->run(); + + $process = $this->processBuilder->buildProcess($arguments); + $process->run(); + + if (!$process->isSuccessful()) { + return FixableProcessResultProvider::provide( + TaskResult::createFailed($this, $context, $this->formatter->format($process)), + function () use ($arguments): Process { + $arguments->add('--fix'); + return $this->processBuilder->buildProcess($arguments); + } + ); + } + + return TaskResult::createPassed($this, $context); + } +} diff --git a/test/Unit/Task/TwigCsFixerTest.php b/test/Unit/Task/TwigCsFixerTest.php new file mode 100644 index 00000000..39491c15 --- /dev/null +++ b/test/Unit/Task/TwigCsFixerTest.php @@ -0,0 +1,132 @@ +processBuilder->reveal(), + $this->formatter->reveal() + ); + } + + public function provideConfigurableOptions(): iterable + { + yield 'defaults' => [ + [], + [ + 'triggered_by' => ['twig'], + 'path' => '.', + ] + ]; + } + + public function provideRunContexts(): iterable + { + yield 'run-context' => [ + true, + $this->mockContext(RunContext::class) + ]; + + yield 'pre-commit-context' => [ + true, + $this->mockContext(GitPreCommitContext::class) + ]; + + yield 'other' => [ + false, + $this->mockContext() + ]; + } + + public function provideFailsOnStuff(): iterable + { + yield 'exitCode1' => [ + [], + $this->mockContext(RunContext::class, ['hello.twig']), + function () { + $this->mockProcessBuilder('twig-cs-fixer', $process = $this->mockProcess(1)); + $this->formatter->format($process)->willReturn('nope'); + }, + 'nope', + FixableTaskResult::class + ]; + } + + public function providePassesOnStuff(): iterable + { + yield 'exitCode0' => [ + [], + $this->mockContext(RunContext::class, ['hello.twig']), + function () { + $this->mockProcessBuilder('twig-cs-fixer', $this->mockProcess(0)); + } + ]; + } + + public function provideSkipsOnStuff(): iterable + { + yield 'no-files' => [ + [], + $this->mockContext(RunContext::class), + function () {} + ]; + yield 'no-files-after-triggered-by' => [ + [], + $this->mockContext(RunContext::class, ['notatwigfile.php']), + function () {} + ]; + } + + public function provideExternalTaskRuns(): iterable + { + yield 'defaults' => [ + [], + $this->mockContext(RunContext::class, ['hello.twig', 'hello2.twig']), + 'twig-cs-fixer', + [ + 'lint', + '--report=text', + '.', + ] + ]; + + yield 'path' => [ + [ + 'path' => 'src', + ], + $this->mockContext(RunContext::class, ['hello.twig', 'hello2.twig']), + 'twig-cs-fixer', + [ + 'lint', + '--report=text', + 'src', + ] + ]; + + yield 'precommit' => [ + [ + 'path' => 'src', + ], + $this->mockContext(GitPreCommitContext::class, ['hello.twig', 'hello2.twig']), + 'twig-cs-fixer', + [ + 'lint', + '--report=text', + 'hello.twig', + 'hello2.twig', + ] + ]; + } +} From e58e060442aabb4fc1e6b8811f3f5e0715711698 Mon Sep 17 00:00:00 2001 From: Antonio de la Vega Date: Tue, 14 May 2024 13:47:53 +0200 Subject: [PATCH 2/6] doc: Fix md header --- doc/tasks/twigcsfixer.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tasks/twigcsfixer.md b/doc/tasks/twigcsfixer.md index bb17d258..8dbf5c9d 100644 --- a/doc/tasks/twigcsfixer.md +++ b/doc/tasks/twigcsfixer.md @@ -1,4 +1,4 @@ -# TwigCs +# Twig CS Fixer Check and fix Twig coding standard using [VincentLanglet/Twig-CS-Fixer](https://github.com/VincentLanglet/Twig-CS-Fixer). You can check config file [here](https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/docs/configuration.md). From 85f4fa190853edad3b5df67eaec3d1bc4629df5b Mon Sep 17 00:00:00 2001 From: Antonio de la Vega Date: Tue, 14 May 2024 21:18:22 +0200 Subject: [PATCH 3/6] Update doc/tasks.md Co-authored-by: Vincent Langlet --- doc/tasks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tasks.md b/doc/tasks.md index 4a92e9c0..e2ebba68 100644 --- a/doc/tasks.md +++ b/doc/tasks.md @@ -130,7 +130,7 @@ Every task has its own default configuration. It is possible to overwrite the pa - [Stylelint](tasks/stylelint.md) - [Tester](tasks/tester.md) - [TwigCs](tasks/twigcs.md) -- [TwigCsFixer](tasks/twigcsfixer.md) +- [Twig-CS-Fixer](tasks/twigcsfixer.md) - [XmlLint](tasks/xmllint.md) - [YamlLint](tasks/yamllint.md) From 0897abf93617d3614811e41b10b477b1079e1136 Mon Sep 17 00:00:00 2001 From: Antonio de la Vega Date: Tue, 14 May 2024 21:21:43 +0200 Subject: [PATCH 4/6] Update doc/tasks/twigcsfixer.md --- doc/tasks/twigcsfixer.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tasks/twigcsfixer.md b/doc/tasks/twigcsfixer.md index 8dbf5c9d..4cef54ec 100644 --- a/doc/tasks/twigcsfixer.md +++ b/doc/tasks/twigcsfixer.md @@ -1,4 +1,4 @@ -# Twig CS Fixer +# Twig-CS-Fixer Check and fix Twig coding standard using [VincentLanglet/Twig-CS-Fixer](https://github.com/VincentLanglet/Twig-CS-Fixer). You can check config file [here](https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/docs/configuration.md). From 9650c894ddbe5f9cef8dfb1010144e8dc876e29b Mon Sep 17 00:00:00 2001 From: Antonio de la Vega Date: Wed, 15 May 2024 17:12:01 +0200 Subject: [PATCH 5/6] feat: Improve file filtering and add missing config --- doc/tasks/twigcsfixer.md | 105 +++++++++++++++++++++++++++-- src/Task/TwigCsFixer.php | 55 ++++++++++++--- test/Unit/Task/TwigCsFixerTest.php | 48 +++++++++---- 3 files changed, 181 insertions(+), 27 deletions(-) diff --git a/doc/tasks/twigcsfixer.md b/doc/tasks/twigcsfixer.md index 4cef54ec..fbd6036a 100644 --- a/doc/tasks/twigcsfixer.md +++ b/doc/tasks/twigcsfixer.md @@ -1,7 +1,6 @@ # Twig-CS-Fixer Check and fix Twig coding standard using [VincentLanglet/Twig-CS-Fixer](https://github.com/VincentLanglet/Twig-CS-Fixer). -You can check config file [here](https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/docs/configuration.md). ***Composer*** @@ -18,17 +17,111 @@ The task lives under the `twigcsfixer` namespace and has following configurable grumphp: tasks: twigcsfixer: - path: '.' + paths: ['.'] + level: 'NOTICE' + config: ~ + report: 'text' + fix: false + no-cache: false + debug: false + quiet: false + version: false + ansi: false + no-ansi: false + no-interaction: false + verbose: false triggered_by: ['twig'] ``` -**path** +**paths** *Default: null* -By default `.` (current folder) will be used. -On precommit the path will not be used, changed files will be passed as arguments instead. -You can specify an alternate location by changing this option. If the path doesn't exist or is not accessible an exception will be thrown. +By default [`.`] (current folder) will be used. +On precommit only changed files that live in the paths will be passed as arguments. + + +**level** + +*Default: 'NOTICE'* + +The level of the messages to display (possibles values are : 'NOTICE', 'WARNING', 'ERROR'). + +**config** + +*Default: null* + +Path to a `.twig-cs-fixer.php` config file. If not set, the default config will be used. + +You can check config file [here](https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/docs/configuration.md). + +**report** + +*Default: 'text'* + +The `--report` option allows to choose the output format for the linter report. + +Supported formats are: +- `text` selected by default. +- `checkstyle` following the common checkstyle XML schema. +- `github` if you want annotations on GitHub actions. +- `junit` following JUnit schema XML from Jenkins. +- `null` if you don't want any reporting. + + +**fix** + +*Default: false* + +Fix the violations. + +**no-cache** + +*Default: false* + +Do not use cache. + +**debug** + +*Default: false* + +Display debugging information. + +**quiet** + +*Default: false* + +Do not output any message. + +**version** + +*Default: false* + +Display this application version. + +**ansi** + +*Default: false* + +Force ANSI output. + +**no-ansi** + +*Default: false* + +Disable ANSI output. + +**no-interaction** + +*Default: false* + +Do not ask any interactive question. + +**verbose** + +*Default: false* + +Increase the verbosity of messages. **triggered_by** diff --git a/src/Task/TwigCsFixer.php b/src/Task/TwigCsFixer.php index a8b81e6e..7ad37362 100644 --- a/src/Task/TwigCsFixer.php +++ b/src/Task/TwigCsFixer.php @@ -24,11 +24,35 @@ public static function getConfigurableOptions(): ConfigOptionsResolver { $resolver = new OptionsResolver(); $resolver->setDefaults([ - 'path' => '.', + 'paths' => ['.'], + 'level' => 'NOTICE', + 'config' => null, + 'report' => 'text', + 'fix' => false, + 'no-cache' => false, + 'debug' => false, + 'quiet' => false, + 'version' => false, + 'ansi' => false, + 'no-ansi' => false, + 'no-interaction' => false, + 'verbose' => false, 'triggered_by' => ['twig'], ]); - $resolver->addAllowedTypes('path', ['string']); + $resolver->addAllowedTypes('paths', ['array']); + $resolver->addAllowedTypes('level', ['string']); + $resolver->addAllowedTypes('config', ['null', 'string']); + $resolver->addAllowedTypes('report', ['string']); + $resolver->addAllowedTypes('fix', ['bool']); + $resolver->addAllowedTypes('no-cache', ['bool']); + $resolver->addAllowedTypes('debug', ['bool']); + $resolver->addAllowedTypes('quiet', ['bool']); + $resolver->addAllowedTypes('version', ['bool']); + $resolver->addAllowedTypes('ansi', ['bool']); + $resolver->addAllowedTypes('no-ansi', ['bool']); + $resolver->addAllowedTypes('no-interaction', ['bool']); + $resolver->addAllowedTypes('verbose', ['bool']); return ConfigOptionsResolver::fromOptionsResolver($resolver); } @@ -41,27 +65,40 @@ public function canRunInContext(ContextInterface $context): bool public function run(ContextInterface $context): TaskResultInterface { $config = $this->getConfig()->getOptions(); + $files = $context->getFiles() + ->extensions($config['triggered_by']) + ->paths($config['paths']); - $files = $context->getFiles()->extensions($config['triggered_by']); - if (0 === \count($files)) { + if (\count($files) === 0) { return TaskResult::createSkipped($this, $context); } $arguments = $this->processBuilder->createArgumentsForCommand('twig-cs-fixer'); $arguments->add('lint'); - $arguments->add('--report=text'); if ($context instanceof GitPreCommitContext) { $arguments->addFiles($files); } if ($context instanceof RunContext) { - $arguments->add($config['path']); + foreach ($config['paths'] as $path) { + $arguments->add($path); + } } - $process = $this->processBuilder->buildProcess($arguments); - - $process->run(); + $arguments->addOptionalArgument('--level=%s', $config['level']); + $arguments->addOptionalArgument('--config=%s', $config['config']); + $arguments->addOptionalArgument('--report=%s', $config['report']); + + $arguments->addOptionalArgument('--fix', $config['fix']); + $arguments->addOptionalArgument('--no-cache', $config['no-cache']); + $arguments->addOptionalArgument('--debug', $config['debug']); + $arguments->addOptionalArgument('--quiet', $config['quiet']); + $arguments->addOptionalArgument('--version', $config['version']); + $arguments->addOptionalArgument('--ansi', $config['ansi']); + $arguments->addOptionalArgument('--no-ansi', $config['no-ansi']); + $arguments->addOptionalArgument('--no-interaction', $config['no-interaction']); + $arguments->addOptionalArgument('--verbose', $config['verbose']); $process = $this->processBuilder->buildProcess($arguments); $process->run(); diff --git a/test/Unit/Task/TwigCsFixerTest.php b/test/Unit/Task/TwigCsFixerTest.php index 39491c15..5cf284ff 100644 --- a/test/Unit/Task/TwigCsFixerTest.php +++ b/test/Unit/Task/TwigCsFixerTest.php @@ -27,7 +27,19 @@ public function provideConfigurableOptions(): iterable [], [ 'triggered_by' => ['twig'], - 'path' => '.', + 'paths' => ['.'], + 'level' => 'NOTICE', + 'config' => null, + 'report' => 'text', + 'fix' => false, + 'no-cache' => false, + 'debug' => false, + 'quiet' => false, + 'version' => false, + 'ansi' => false, + 'no-ansi' => false, + 'no-interaction' => false, + 'verbose' => false, ] ]; } @@ -80,12 +92,20 @@ public function provideSkipsOnStuff(): iterable yield 'no-files' => [ [], $this->mockContext(RunContext::class), - function () {} + function () { + } ]; yield 'no-files-after-triggered-by' => [ [], $this->mockContext(RunContext::class, ['notatwigfile.php']), - function () {} + function () { + } + ]; + yield 'no-files-in-paths' => [ + ['paths' => ['src']], + $this->mockContext(RunContext::class, ['other/hello.twig']), + function () { + } ]; } @@ -97,35 +117,39 @@ public function provideExternalTaskRuns(): iterable 'twig-cs-fixer', [ 'lint', - '--report=text', '.', + '--level=NOTICE', + '--report=text', ] ]; - yield 'path' => [ + yield 'paths' => [ [ - 'path' => 'src', + 'paths' => ['src', 'templates'], ], - $this->mockContext(RunContext::class, ['hello.twig', 'hello2.twig']), + $this->mockContext(RunContext::class, ['templates/hello.twig', 'templates/hello2.twig']), 'twig-cs-fixer', [ 'lint', - '--report=text', 'src', + 'templates', + '--level=NOTICE', + '--report=text', ] ]; yield 'precommit' => [ [ - 'path' => 'src', + 'paths' => ['templates'], ], - $this->mockContext(GitPreCommitContext::class, ['hello.twig', 'hello2.twig']), + $this->mockContext(GitPreCommitContext::class, ['templates/hello.twig', 'templates/hello2.twig', 'other/hello2.twig']), 'twig-cs-fixer', [ 'lint', + 'templates/hello.twig', + 'templates/hello2.twig', + '--level=NOTICE', '--report=text', - 'hello.twig', - 'hello2.twig', ] ]; } From 3fc91de0f2946bd7a39c5f463f8c05153dde2bff Mon Sep 17 00:00:00 2001 From: Antonio de la Vega Date: Thu, 16 May 2024 11:20:38 +0200 Subject: [PATCH 6/6] fix: Remove useless config params. Improve tests --- doc/tasks/twigcsfixer.md | 62 ++-------------- src/Task/TwigCsFixer.php | 33 ++------- test/Unit/Task/TwigCsFixerTest.php | 112 +++++++++++++++++++++++++---- 3 files changed, 110 insertions(+), 97 deletions(-) diff --git a/doc/tasks/twigcsfixer.md b/doc/tasks/twigcsfixer.md index fbd6036a..f4036aae 100644 --- a/doc/tasks/twigcsfixer.md +++ b/doc/tasks/twigcsfixer.md @@ -17,35 +17,28 @@ The task lives under the `twigcsfixer` namespace and has following configurable grumphp: tasks: twigcsfixer: - paths: ['.'] - level: 'NOTICE' + paths: [] + level: ~ config: ~ report: 'text' - fix: false no-cache: false - debug: false - quiet: false - version: false - ansi: false - no-ansi: false - no-interaction: false verbose: false triggered_by: ['twig'] ``` **paths** -*Default: null* +*Default: []* -By default [`.`] (current folder) will be used. +By default, current folder will be used. On precommit only changed files that live in the paths will be passed as arguments. **level** -*Default: 'NOTICE'* +*Default: 'notice'* -The level of the messages to display (possibles values are : 'NOTICE', 'WARNING', 'ERROR'). +The level of the messages to display (possibles values are : 'notice', 'warning', 'error'). **config** @@ -68,55 +61,12 @@ Supported formats are: - `junit` following JUnit schema XML from Jenkins. - `null` if you don't want any reporting. - -**fix** - -*Default: false* - -Fix the violations. - **no-cache** *Default: false* Do not use cache. -**debug** - -*Default: false* - -Display debugging information. - -**quiet** - -*Default: false* - -Do not output any message. - -**version** - -*Default: false* - -Display this application version. - -**ansi** - -*Default: false* - -Force ANSI output. - -**no-ansi** - -*Default: false* - -Disable ANSI output. - -**no-interaction** - -*Default: false* - -Do not ask any interactive question. - **verbose** *Default: false* diff --git a/src/Task/TwigCsFixer.php b/src/Task/TwigCsFixer.php index 7ad37362..20bdaa8b 100644 --- a/src/Task/TwigCsFixer.php +++ b/src/Task/TwigCsFixer.php @@ -24,34 +24,20 @@ public static function getConfigurableOptions(): ConfigOptionsResolver { $resolver = new OptionsResolver(); $resolver->setDefaults([ - 'paths' => ['.'], - 'level' => 'NOTICE', + 'paths' => [], + 'level' => null, 'config' => null, 'report' => 'text', - 'fix' => false, 'no-cache' => false, - 'debug' => false, - 'quiet' => false, - 'version' => false, - 'ansi' => false, - 'no-ansi' => false, - 'no-interaction' => false, 'verbose' => false, 'triggered_by' => ['twig'], ]); $resolver->addAllowedTypes('paths', ['array']); - $resolver->addAllowedTypes('level', ['string']); + $resolver->addAllowedTypes('level', ['null', 'string']); $resolver->addAllowedTypes('config', ['null', 'string']); - $resolver->addAllowedTypes('report', ['string']); - $resolver->addAllowedTypes('fix', ['bool']); + $resolver->addAllowedTypes('report', ['null', 'string']); $resolver->addAllowedTypes('no-cache', ['bool']); - $resolver->addAllowedTypes('debug', ['bool']); - $resolver->addAllowedTypes('quiet', ['bool']); - $resolver->addAllowedTypes('version', ['bool']); - $resolver->addAllowedTypes('ansi', ['bool']); - $resolver->addAllowedTypes('no-ansi', ['bool']); - $resolver->addAllowedTypes('no-interaction', ['bool']); $resolver->addAllowedTypes('verbose', ['bool']); return ConfigOptionsResolver::fromOptionsResolver($resolver); @@ -81,23 +67,14 @@ public function run(ContextInterface $context): TaskResultInterface } if ($context instanceof RunContext) { - foreach ($config['paths'] as $path) { - $arguments->add($path); - } + $arguments->addArgumentArray('%s', $config['paths']); } $arguments->addOptionalArgument('--level=%s', $config['level']); $arguments->addOptionalArgument('--config=%s', $config['config']); $arguments->addOptionalArgument('--report=%s', $config['report']); - $arguments->addOptionalArgument('--fix', $config['fix']); $arguments->addOptionalArgument('--no-cache', $config['no-cache']); - $arguments->addOptionalArgument('--debug', $config['debug']); - $arguments->addOptionalArgument('--quiet', $config['quiet']); - $arguments->addOptionalArgument('--version', $config['version']); - $arguments->addOptionalArgument('--ansi', $config['ansi']); - $arguments->addOptionalArgument('--no-ansi', $config['no-ansi']); - $arguments->addOptionalArgument('--no-interaction', $config['no-interaction']); $arguments->addOptionalArgument('--verbose', $config['verbose']); $process = $this->processBuilder->buildProcess($arguments); diff --git a/test/Unit/Task/TwigCsFixerTest.php b/test/Unit/Task/TwigCsFixerTest.php index 5cf284ff..3dd084d0 100644 --- a/test/Unit/Task/TwigCsFixerTest.php +++ b/test/Unit/Task/TwigCsFixerTest.php @@ -27,18 +27,11 @@ public function provideConfigurableOptions(): iterable [], [ 'triggered_by' => ['twig'], - 'paths' => ['.'], - 'level' => 'NOTICE', + 'paths' => [], + 'level' => null, 'config' => null, 'report' => 'text', - 'fix' => false, 'no-cache' => false, - 'debug' => false, - 'quiet' => false, - 'version' => false, - 'ansi' => false, - 'no-ansi' => false, - 'no-interaction' => false, 'verbose' => false, ] ]; @@ -117,8 +110,6 @@ public function provideExternalTaskRuns(): iterable 'twig-cs-fixer', [ 'lint', - '.', - '--level=NOTICE', '--report=text', ] ]; @@ -133,7 +124,6 @@ public function provideExternalTaskRuns(): iterable 'lint', 'src', 'templates', - '--level=NOTICE', '--report=text', ] ]; @@ -148,9 +138,105 @@ public function provideExternalTaskRuns(): iterable 'lint', 'templates/hello.twig', 'templates/hello2.twig', - '--level=NOTICE', '--report=text', ] ]; + + yield 'level' => [ + [ + 'level' => 'warning', + ], + $this->mockContext(RunContext::class, ['hello.twig', 'hello2.twig']), + 'twig-cs-fixer', + [ + 'lint', + '--level=warning', + '--report=text', + ] + ]; + + yield 'config' => [ + [ + 'config' => 'twig-cs-fixer.php', + ], + $this->mockContext(RunContext::class, ['hello.twig', 'hello2.twig']), + 'twig-cs-fixer', + [ + 'lint', + '--config=twig-cs-fixer.php', + '--report=text', + ] + ]; + + yield 'no-cache' => [ + [ + 'no-cache' => true, + ], + $this->mockContext(RunContext::class, ['hello.twig', 'hello2.twig']), + 'twig-cs-fixer', + [ + 'lint', + '--report=text', + '--no-cache', + ] + ]; + + yield 'verbose' => [ + [ + 'verbose' => true, + ], + $this->mockContext(RunContext::class, ['hello.twig', 'hello2.twig']), + 'twig-cs-fixer', + [ + 'lint', + '--report=text', + '--verbose', + ] + ]; + + yield 'report' => [ + [ + 'report' => 'json', + ], + $this->mockContext(RunContext::class, ['hello.twig', 'hello2.twig']), + 'twig-cs-fixer', + [ + 'lint', + '--report=json', + ] + ]; + + yield 'default report' => [ + [ + 'report' => null, + ], + $this->mockContext(RunContext::class, ['hello.twig', 'hello2.twig']), + 'twig-cs-fixer', + [ + 'lint', + ] + ]; + + yield 'multiple options' => [ + [ + 'paths' => ['src', 'templates'], + 'level' => 'warning', + 'config' => 'twig-cs-fixer.php', + 'no-cache' => true, + 'verbose' => true, + ], + $this->mockContext(RunContext::class, ['templates/hello.twig', 'templates/hello2.twig']), + 'twig-cs-fixer', + [ + 'lint', + 'src', + 'templates', + '--level=warning', + '--config=twig-cs-fixer.php', + '--report=text', + '--no-cache', + '--verbose', + ] + ]; } }