Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AbstractLineContentRuleTestCase #1540

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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