From 4fdf926e831ca9749379c508ed406aa33708d004 Mon Sep 17 00:00:00 2001 From: brianvarskonst Date: Wed, 5 Jun 2024 18:28:15 +0200 Subject: [PATCH] Improve tests --- ...necessaryNamespaceUsageUnitTest.fail.1.inc | 82 +++++++++---------- .../UnnecessaryNamespaceUsageUnitTest.php | 2 +- .../MultipleEmptyLinesUnitTest.fail.inc.fixed | 20 ++--- Brianvarskonst/ruleset.xml | 7 -- composer.json | 7 +- integrationtests/testfile.php | 48 +++++++---- phpunit.xml.dist | 2 +- 7 files changed, 89 insertions(+), 79 deletions(-) diff --git a/Brianvarskonst/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.fail.1.inc b/Brianvarskonst/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.fail.1.inc index 1e45d42..9787fda 100644 --- a/Brianvarskonst/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.fail.1.inc +++ b/Brianvarskonst/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.fail.1.inc @@ -1,8 +1,8 @@ [], 'UnnecessaryNamespaceUsageUnitTest.pass.2.inc' => [], 'UnnecessaryNamespaceUsageUnitTest.pass.3.inc' => [], diff --git a/Brianvarskonst/Tests/Whitespace/MultipleEmptyLinesUnitTest.fail.inc.fixed b/Brianvarskonst/Tests/Whitespace/MultipleEmptyLinesUnitTest.fail.inc.fixed index 5363934..3cd10c0 100644 --- a/Brianvarskonst/Tests/Whitespace/MultipleEmptyLinesUnitTest.fail.inc.fixed +++ b/Brianvarskonst/Tests/Whitespace/MultipleEmptyLinesUnitTest.fail.inc.fixed @@ -9,21 +9,21 @@ * @return void */ function wfFailedExamples() { - $a = 1; + $a = 1; - $b = 2; + $b = 2; - // Comment + // Comment - // Comment 2 + // Comment 2 - // Comment 3 + // Comment 3 - /* Comment 4 */ + /* Comment 4 */ - # Comment 5 + # Comment 5 - $c = 3; + $c = 3; } /** @@ -31,7 +31,7 @@ function wfFailedExamples() { * @return void */ function wfPassedExamples() { - $a = 1; + $a = 1; - $b = 2; + $b = 2; } diff --git a/Brianvarskonst/ruleset.xml b/Brianvarskonst/ruleset.xml index 549de8d..e7d0d2d 100644 --- a/Brianvarskonst/ruleset.xml +++ b/Brianvarskonst/ruleset.xml @@ -433,13 +433,6 @@ - - warning - - - - - diff --git a/composer.json b/composer.json index ea53f1c..d3918a2 100644 --- a/composer.json +++ b/composer.json @@ -53,6 +53,11 @@ "cs": "./vendor/bin/phpcs -q --parallel=$(nproc) -s", "cs:analyze": "./vendor/bin/phpstan --no-progress", "cs:bf": "php -d error_reporting=24575 vendor/bin/phpcbf;exit 0", - "test:all": "@php ./vendor/bin/phpunit" + "test": [ + "@test:unit", + "@test:integration" + ], + "test:unit": "@php ./vendor/bin/phpunit", + "test:integration": "@php vendor/bin/phpcs -s --standard=Brianvarskonst integrationtests/testfile.php" } } diff --git a/integrationtests/testfile.php b/integrationtests/testfile.php index 911c63d..eb3b0fe 100644 --- a/integrationtests/testfile.php +++ b/integrationtests/testfile.php @@ -1,5 +1,18 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Acme; const BAM = 1; @@ -7,6 +20,7 @@ /** * Coding standards demonstration. */ +// phpcs:ignore Brianvarskonst.Namespace.Psr4.InvalidPSR4, Squiz.Classes.ClassFileName.NoMatch class FooBar { public const SOME_CONST = 42; @@ -14,27 +28,25 @@ class FooBar protected const PROTECT = 0; public const LALA = 'lala'; - /** - * @var string - */ - private $fooBar; + private string $fooBar; - /** - * @param string $dummy Some argument description - */ + /** @param string $dummy Some argument description */ public function __construct(string $dummy) { $this->fooBar = $this->transformText($dummy); } - /** - * @return string - * - * @deprecated - */ + /** @deprecated */ public function someDeprecatedMethod(): string { - @\trigger_error(\sprintf('The %s() method is deprecated since version 2.8 and will be removed in 3.0. Use Acme\Baz::someMethod() instead.', __METHOD__), E_USER_DEPRECATED); + @\trigger_error( + \sprintf( + 'The %s() method is deprecated since version 2.8 and will be removed in 3.0. Use %s instead.', + __METHOD__, + 'Acme\Baz::someMethod()', + ), + E_USER_DEPRECATED, + ); return Baz::someMethod(); } @@ -49,7 +61,7 @@ public function someDeprecatedMethod(): string * * @throws \RuntimeException When an invalid option is provided */ - private function transformText($dummy, array $options = []): ?string + private function transformText(bool| string $dummy, array $options = []): ?string { /** @var array $defaultOptions */ $defaultOptions = [ @@ -67,15 +79,15 @@ private function transformText($dummy, array $options = []): ?string $mergedOptions = \array_merge( $defaultOptions, - $options + $options, ); - if (true === $dummy) { + if ($dummy === true) { return null; } - if ('string' === $dummy) { - if ('values' === $mergedOptions['some_default']) { + if ($dummy === 'string') { + if ($mergedOptions['some_default'] === 'values') { return \substr($dummy, 0, 5); } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index efa353f..3a84a81 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@