Skip to content

Commit

Permalink
Add AbstractLineContentRuleTestCase (#1540)
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarStark authored Oct 11, 2023
1 parent 5dc4aff commit 76f5a7e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 32 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/RstSample.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ public function __construct(

$this->lines = Lines::fromArray($content);
}

}
42 changes: 42 additions & 0 deletions tests/Rule/AbstractLineContentRuleTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

/**
* This file is part of DOCtor-RST.
*
* (c) Oskar Stark <oskarstark@googlemail.com>
*
* 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<array{0: ViolationInterface, 1: RstSample}>
*/
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'),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<array{0: ViolationInterface, 1: RstSample}>
*/
public static function whitelistProvider(): iterable
public static function checkProvider(): iterable
{
$whitelist = [
'...',
Expand All @@ -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<array{0: ViolationInterface, 1: RstSample}>
*/
public static function checkProvider(): iterable
{
$valid = '';
$invalid = 'the cached items will not not be invalidated unless you clear OPcache.';

Expand Down

0 comments on commit 76f5a7e

Please sign in to comment.