Skip to content

Commit 7b88cfa

Browse files
committed
Config: add tests for the --generator= argument
1 parent 5033272 commit 7b88cfa

File tree

1 file changed

+76
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)