|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests for the \PHP_CodeSniffer\Config --generator argument. |
| 4 | + * |
| 5 | + * @copyright 2024 PHPCSStandards and contributors |
| 6 | + * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence |
| 7 | + */ |
| 8 | + |
| 9 | +namespace PHP_CodeSniffer\Tests\Core\Config; |
| 10 | + |
| 11 | +use PHP_CodeSniffer\Tests\ConfigDouble; |
| 12 | +use PHPUnit\Framework\TestCase; |
| 13 | + |
| 14 | +/** |
| 15 | + * Tests for the \PHP_CodeSniffer\Config --generator argument. |
| 16 | + * |
| 17 | + * @covers \PHP_CodeSniffer\Config::processLongArgument |
| 18 | + */ |
| 19 | +final class GeneratorArgTest extends TestCase |
| 20 | +{ |
| 21 | + |
| 22 | + |
| 23 | + /** |
| 24 | + * Ensure that the generator property is set when the parameter is passed a valid value. |
| 25 | + * |
| 26 | + * @param string $generatorName Generator name. |
| 27 | + * |
| 28 | + * @dataProvider dataGeneratorNames |
| 29 | + * |
| 30 | + * @return void |
| 31 | + */ |
| 32 | + public function testGenerators($generatorName) |
| 33 | + { |
| 34 | + $config = new ConfigDouble(["--generator=$generatorName"]); |
| 35 | + |
| 36 | + $this->assertSame($generatorName, $config->generator); |
| 37 | + |
| 38 | + }//end testGenerators() |
| 39 | + |
| 40 | + |
| 41 | + /** |
| 42 | + * Data provider for testGenerators(). |
| 43 | + * |
| 44 | + * @see self::testGenerators() |
| 45 | + * |
| 46 | + * @return array<int, array<string>> |
| 47 | + */ |
| 48 | + public static function dataGeneratorNames() |
| 49 | + { |
| 50 | + return [ |
| 51 | + ['Text'], |
| 52 | + ['HTML'], |
| 53 | + ['Markdown'], |
| 54 | + ]; |
| 55 | + |
| 56 | + }//end dataGeneratorNames() |
| 57 | + |
| 58 | + |
| 59 | + /** |
| 60 | + * Ensure that only the first argument is processed and others are ignored. |
| 61 | + * |
| 62 | + * @return void |
| 63 | + */ |
| 64 | + public function testOnlySetOnce() |
| 65 | + { |
| 66 | + $config = new ConfigDouble( |
| 67 | + [ |
| 68 | + '--generator=Text', |
| 69 | + '--generator=HTML', |
| 70 | + '--generator=InvalidGenerator', |
| 71 | + ] |
| 72 | + ); |
| 73 | + |
| 74 | + $this->assertSame('Text', $config->generator); |
| 75 | + |
| 76 | + }//end testOnlySetOnce() |
| 77 | + |
| 78 | + |
| 79 | +}//end class |
0 commit comments