From 7b88cfa1e1825e28ba4c2bbbdc6ab2fa40c338a6 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Fri, 22 Nov 2024 14:10:42 -0300 Subject: [PATCH 1/3] Config: add tests for the `--generator=` argument --- tests/Core/Config/GeneratorArgTest.php | 76 ++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/Core/Config/GeneratorArgTest.php diff --git a/tests/Core/Config/GeneratorArgTest.php b/tests/Core/Config/GeneratorArgTest.php new file mode 100644 index 0000000000..15039e738d --- /dev/null +++ b/tests/Core/Config/GeneratorArgTest.php @@ -0,0 +1,76 @@ +assertSame($generatorName, $config->generator); + + }//end testGenerators() + + + /** + * Data provider for testGenerators(). + * + * @return array> + * @see self::testGenerators() + */ + public static function dataGeneratorNames() + { + return [ + ['Text'], + ['HTML'], + ['Markdown'], + ]; + + }//end dataGeneratorNames() + + + /** + * Ensure that only the first argument is processed and others are ignored. + * + * @return void + */ + public function testOnlySetOnce() + { + $config = new ConfigDouble( + [ + "--generator=Text", + "--generator=HTML", + "--generator=InvalidGenerator", + ] + ); + + $this->assertSame('Text', $config->generator); + + }//end testOnlySetOnce() + + +}//end class From 0a402fb01320fd1e95c5e05aaacf83518e5b621d Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Thu, 12 Dec 2024 11:52:38 -0300 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com> --- tests/Core/Config/GeneratorArgTest.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/Core/Config/GeneratorArgTest.php b/tests/Core/Config/GeneratorArgTest.php index 15039e738d..3a8f91f2dd 100644 --- a/tests/Core/Config/GeneratorArgTest.php +++ b/tests/Core/Config/GeneratorArgTest.php @@ -2,7 +2,8 @@ /** * Tests for the \PHP_CodeSniffer\Config --generator argument. * - * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + * @copyright 2024 PHPCSStandards and contributors + * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence */ namespace PHP_CodeSniffer\Tests\Core\Config; @@ -20,7 +21,7 @@ final class GeneratorArgTest extends TestCase /** - * Ensure that the generator property is set when the parameter is passed. + * Ensure that the generator property is set when the parameter is passed a valid value. * * @param string $generatorName Generator name. * @@ -62,9 +63,9 @@ public function testOnlySetOnce() { $config = new ConfigDouble( [ - "--generator=Text", - "--generator=HTML", - "--generator=InvalidGenerator", + '--generator=Text', + '--generator=HTML', + '--generator=InvalidGenerator', ] ); From cea9be26fb0bada2c5222584fc5674717d8f3966 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Thu, 12 Dec 2024 11:57:48 -0300 Subject: [PATCH 3/3] Fix positioning of the `@see` and `@dataProvider` tags --- tests/Core/Config/GeneratorArgTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Core/Config/GeneratorArgTest.php b/tests/Core/Config/GeneratorArgTest.php index 3a8f91f2dd..f0b52db157 100644 --- a/tests/Core/Config/GeneratorArgTest.php +++ b/tests/Core/Config/GeneratorArgTest.php @@ -25,8 +25,9 @@ final class GeneratorArgTest extends TestCase * * @param string $generatorName Generator name. * - * @return void * @dataProvider dataGeneratorNames + * + * @return void */ public function testGenerators($generatorName) { @@ -40,8 +41,9 @@ public function testGenerators($generatorName) /** * Data provider for testGenerators(). * + * @see self::testGenerators() + * * @return array> - * @see self::testGenerators() */ public static function dataGeneratorNames() {