|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace PhpCodeConv\Tests\Sniffs; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | + |
| 7 | +abstract class AbstractTestCase extends TestCase |
| 8 | +{ |
| 9 | + |
| 10 | + /** @var Validator */ |
| 11 | + private static $validator; |
| 12 | + |
| 13 | + abstract protected function getFilename() : string; |
| 14 | + |
| 15 | + /** @phpstan-ignore-next-line */ |
| 16 | + final public function __construct($name = null, array $data = [], $dataName = '') |
| 17 | + { |
| 18 | + parent::__construct($name, $data, $dataName); |
| 19 | + } |
| 20 | + |
| 21 | + /** @return string[] */ |
| 22 | + protected function getExcludeSniff() : array |
| 23 | + { |
| 24 | + return []; |
| 25 | + } |
| 26 | + |
| 27 | + /** @return void */ |
| 28 | + final public static function setUpBeforeClass() |
| 29 | + { |
| 30 | + self::$validator = new Validator(); |
| 31 | + |
| 32 | + $filepath = dirname(__DIR__) . '/Inc/' . (new static)->getFilename(); |
| 33 | + |
| 34 | + self::$validator->setFile($filepath, (new static)->getExcludeSniff()); |
| 35 | + } |
| 36 | + |
| 37 | + /** @return void */ |
| 38 | + final public static function tearDownAfterClass() |
| 39 | + { |
| 40 | + if (self::$validator->errorCount() > 0) { |
| 41 | + printf("\n\n"); |
| 42 | + self::$validator->printError(); |
| 43 | + } |
| 44 | + |
| 45 | + self::assertEquals(0, self::$validator->errorCount()); |
| 46 | + } |
| 47 | + |
| 48 | + /** @return void */ |
| 49 | + final protected function checkSniff(int $line, int $column, string $sniff, string $message) |
| 50 | + { |
| 51 | + $key = SniffEntity::createKey($line, $column, $sniff); |
| 52 | + |
| 53 | + $this->assertTrue(self::$validator->hasKey($key)); |
| 54 | + $this->assertSame($message, self::$validator->getMessage($key)); |
| 55 | + |
| 56 | + self::$validator->removeItem($key); |
| 57 | + } |
| 58 | +} |
0 commit comments