From 76f5a7ef8eacceff3004c714c0f48e8172288a53 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 11 Oct 2023 15:52:02 +0200 Subject: [PATCH] Add `AbstractLineContentRuleTestCase` (#1540) --- Makefile | 14 +++---- tests/RstSample.php | 1 - .../Rule/AbstractLineContentRuleTestCase.php | 42 +++++++++++++++++++ ...> AvoidRepetetiveWordsTestLineContent.php} | 28 ++----------- 4 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 tests/Rule/AbstractLineContentRuleTestCase.php rename tests/Rule/{AvoidRepetetiveWordsTest.php => AvoidRepetetiveWordsTestLineContent.php} (85%) diff --git a/Makefile b/Makefile index 65233ccc..82876df2 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,17 @@ -.PHONY: test -test: +.PHONY: tests +tests: vendor/bin/phpunit .PHONY: cs cs: vendor symfony php vendor/bin/php-cs-fixer fix --diff --verbose -.PHONY: phpstan -phpstan: - vendor/bin/phpstan analyse -c phpstan.neon.dist +.PHONY: static-code-analysis +static-code-analysis: + vendor/bin/phpstan analyse -c phpstan.neon.dist --memory-limit=-1 -.PHONY: phpstan-baseline -phpstan-baseline: +.PHONY: static-code-analysis-baseline +static-code-analysis-baseline: vendor/bin/phpstan analyse -c phpstan.neon.dist --generate-baseline=phpstan-baseline.neon .PHONY: refactoring diff --git a/tests/RstSample.php b/tests/RstSample.php index a4578c5c..75d1fa28 100644 --- a/tests/RstSample.php +++ b/tests/RstSample.php @@ -32,5 +32,4 @@ public function __construct( $this->lines = Lines::fromArray($content); } - } diff --git a/tests/Rule/AbstractLineContentRuleTestCase.php b/tests/Rule/AbstractLineContentRuleTestCase.php new file mode 100644 index 00000000..33bc79e7 --- /dev/null +++ b/tests/Rule/AbstractLineContentRuleTestCase.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace App\Tests\Rule; + +use App\Rule\LineContentRule; +use App\Tests\RstSample; +use App\Tests\UnitTestCase; +use App\Value\ViolationInterface; + +abstract class AbstractLineContentRuleTestCase extends UnitTestCase +{ + abstract public function createRule(): LineContentRule; + + /** + * @return \Generator + */ + abstract public static function checkProvider(): iterable; + + /** + * @test + * + * @dataProvider checkProvider + */ + public function check(ViolationInterface $expected, RstSample $sample): void + { + self::assertEquals( + $expected, + static::createRule()->check($sample->lines, $sample->lineNumber, 'filename'), + ); + } +} diff --git a/tests/Rule/AvoidRepetetiveWordsTest.php b/tests/Rule/AvoidRepetetiveWordsTestLineContent.php similarity index 85% rename from tests/Rule/AvoidRepetetiveWordsTest.php rename to tests/Rule/AvoidRepetetiveWordsTestLineContent.php index 79eeb1bb..90c3039c 100644 --- a/tests/Rule/AvoidRepetetiveWordsTest.php +++ b/tests/Rule/AvoidRepetetiveWordsTestLineContent.php @@ -15,31 +15,17 @@ use App\Rule\AvoidRepetetiveWords; use App\Tests\RstSample; -use App\Tests\UnitTestCase; use App\Value\NullViolation; use App\Value\Violation; -use App\Value\ViolationInterface; -final class AvoidRepetetiveWordsTest extends UnitTestCase +final class AvoidRepetetiveWordsTestLineContent extends AbstractLineContentRuleTestCase { - /** - * @test - * - * @dataProvider checkProvider - * @dataProvider whitelistProvider - */ - public function check(ViolationInterface $expected, RstSample $sample): void + public function createRule(): AvoidRepetetiveWords { - self::assertEquals( - $expected, - (new AvoidRepetetiveWords())->check($sample->lines, $sample->lineNumber, 'filename'), - ); + return new AvoidRepetetiveWords(); } - /** - * @return \Generator - */ - public static function whitelistProvider(): iterable + public static function checkProvider(): iterable { $whitelist = [ '...', @@ -48,13 +34,7 @@ public static function whitelistProvider(): iterable foreach ($whitelist as $word) { yield sprintf('valid whitelist: %s', $word) => [NullViolation::create(), new RstSample(sprintf('%s %s %s', $word, $word, $word))]; } - } - /** - * @return \Generator - */ - public static function checkProvider(): iterable - { $valid = ''; $invalid = 'the cached items will not not be invalidated unless you clear OPcache.';