|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace MagoCakePHP\Tests\Unit; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | + |
| 10 | +final class RuleIntegrationTest extends TestCase |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @return iterable<string, array{string, list<string>}> |
| 14 | + */ |
| 15 | + public static function rules(): iterable |
| 16 | + { |
| 17 | + yield 'trait suffix' => ['mago-cakephp/trait-suffix', ['rules/TraitSuffix.php']]; |
| 18 | + yield 'method underscore' => ['mago-cakephp/public-method-underscore', ['rules/PublicMethodUnderscore.php']]; |
| 19 | + yield 'elseif' => ['mago-cakephp/elseif', ['rules/ElseIf.php']]; |
| 20 | + yield 'function docblock' => [ |
| 21 | + 'mago-cakephp/function-docblock', |
| 22 | + ['rules/FunctionDocblock.php', 'rules/tests/FunctionDocblockTest.php'], |
| 23 | + ]; |
| 24 | + yield 'docblock tag spacing' => ['mago-cakephp/docblock-tag-spacing', ['rules/DocblockTagSpacing.php']]; |
| 25 | + yield 'throws tag' => ['mago-cakephp/throws-tag', ['rules/ThrowsTag.php']]; |
| 26 | + yield 'inheritDoc' => ['mago-cakephp/inherit-doc', ['rules/InheritDoc.php']]; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Runs a rule through Mago's parser and extension protocol. |
| 31 | + * |
| 32 | + * @param list<string> $fixtures |
| 33 | + */ |
| 34 | + #[DataProvider('rules')] |
| 35 | + public function testRuleFixtures(string $rule, array $fixtures): void |
| 36 | + { |
| 37 | + $root = dirname(path: __DIR__, levels: 2); |
| 38 | + $command = [ |
| 39 | + $root . '/vendor/bin/mago', |
| 40 | + '--workspace', |
| 41 | + $root . '/tests/corpus', |
| 42 | + 'lint', |
| 43 | + '--only', |
| 44 | + $rule, |
| 45 | + '--reporting-format', |
| 46 | + 'short', |
| 47 | + ...$fixtures, |
| 48 | + ]; |
| 49 | + $pipes = []; |
| 50 | + $process = proc_open( |
| 51 | + $command, |
| 52 | + [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], |
| 53 | + $pipes, |
| 54 | + $root, |
| 55 | + ); |
| 56 | + |
| 57 | + self::assertIsResource($process); |
| 58 | + $output = stream_get_contents($pipes[1]) . stream_get_contents($pipes[2]); |
| 59 | + fclose($pipes[1]); |
| 60 | + fclose($pipes[2]); |
| 61 | + |
| 62 | + self::assertSame(0, proc_close($process), $output); |
| 63 | + } |
| 64 | +} |
0 commit comments