diff --git a/phpstan.neon b/phpstan.neon index d7adbbd5..3a767e2d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,7 +4,6 @@ includes: parameters: ergebnis: classesAllowedToBeExtended: - - Ergebnis\Classy\Test\Unit\Exception\AbstractTestCase - InvalidArgumentException - LogicException - ParseError diff --git a/test/Unit/Exception/AbstractTestCase.php b/test/Unit/Exception/AbstractTestCase.php deleted file mode 100644 index 62f2f8f6..00000000 --- a/test/Unit/Exception/AbstractTestCase.php +++ /dev/null @@ -1,53 +0,0 @@ -assertClassImplementsInterface(ExceptionInterface::class, $this->className()); - } - - final protected function className(): string - { - $className = \preg_replace( - '/Test$/', - '', - \str_replace( - 'Ergebnis\\Classy\\Test\\Unit\\', - 'Ergebnis\\Classy\\', - static::class - ) - ); - - if (!\is_string($className)) { - throw new \RuntimeException(\sprintf( - 'Could not resolve class name from test class name "%s".', - static::class - )); - } - - return $className; - } -} diff --git a/test/Unit/Exception/DirectoryDoesNotExistTest.php b/test/Unit/Exception/DirectoryDoesNotExistTest.php index f70cafb6..4ac88d1d 100644 --- a/test/Unit/Exception/DirectoryDoesNotExistTest.php +++ b/test/Unit/Exception/DirectoryDoesNotExistTest.php @@ -14,14 +14,19 @@ namespace Ergebnis\Classy\Test\Unit\Exception; use Ergebnis\Classy\Exception\DirectoryDoesNotExist; +use Ergebnis\Classy\Exception\ExceptionInterface; +use Localheinz\Test\Util\Helper; +use PHPUnit\Framework; /** * @internal * * @covers \Ergebnis\Classy\Exception\DirectoryDoesNotExist */ -final class DirectoryDoesNotExistTest extends AbstractTestCase +final class DirectoryDoesNotExistTest extends Framework\TestCase { + use Helper; + public function testFromDirectoryReturnsException(): void { $directory = $this->faker()->sentence; @@ -29,6 +34,8 @@ public function testFromDirectoryReturnsException(): void $exception = DirectoryDoesNotExist::fromDirectory($directory); self::assertInstanceOf(DirectoryDoesNotExist::class, $exception); + self::assertInstanceOf(\InvalidArgumentException::class, $exception); + self::assertInstanceOf(ExceptionInterface::class, $exception); $message = \sprintf( 'Directory "%s" does not exist.', diff --git a/test/Unit/Exception/MultipleDefinitionsFoundTest.php b/test/Unit/Exception/MultipleDefinitionsFoundTest.php index b98c44be..4f62141a 100644 --- a/test/Unit/Exception/MultipleDefinitionsFoundTest.php +++ b/test/Unit/Exception/MultipleDefinitionsFoundTest.php @@ -14,7 +14,10 @@ namespace Ergebnis\Classy\Test\Unit\Exception; use Ergebnis\Classy\Construct; +use Ergebnis\Classy\Exception\ExceptionInterface; use Ergebnis\Classy\Exception\MultipleDefinitionsFound; +use Localheinz\Test\Util\Helper; +use PHPUnit\Framework; /** * @internal @@ -23,8 +26,10 @@ * * @uses \Ergebnis\Classy\Construct */ -final class MultipleDefinitionsFoundTest extends AbstractTestCase +final class MultipleDefinitionsFoundTest extends Framework\TestCase { + use Helper; + public function testFromConstructsReturnsException(): void { $name = 'Foo\\Bar\\Baz'; @@ -41,6 +46,8 @@ public function testFromConstructsReturnsException(): void $exception = MultipleDefinitionsFound::fromConstructs($constructs); self::assertInstanceOf(MultipleDefinitionsFound::class, $exception); + self::assertInstanceOf(\RuntimeException::class, $exception); + self::assertInstanceOf(ExceptionInterface::class, $exception); $format = <<<'PHP' Multiple definitions have been found for the following constructs: diff --git a/test/Unit/Exception/ParseErrorTest.php b/test/Unit/Exception/ParseErrorTest.php index 1abe2980..ff91172d 100644 --- a/test/Unit/Exception/ParseErrorTest.php +++ b/test/Unit/Exception/ParseErrorTest.php @@ -13,19 +13,19 @@ namespace Ergebnis\Classy\Test\Unit\Exception; +use Ergebnis\Classy\Exception\ExceptionInterface; use Ergebnis\Classy\Exception\ParseError; +use Localheinz\Test\Util\Helper; +use PHPUnit\Framework; /** * @internal * * @covers \Ergebnis\Classy\Exception\ParseError */ -final class ParseErrorTest extends AbstractTestCase +final class ParseErrorTest extends Framework\TestCase { - public function testExtendsParseError(): void - { - $this->assertClassExtends(\ParseError::class, ParseError::class); - } + use Helper; public function testFromParseErrorReturnsException(): void { @@ -34,6 +34,8 @@ public function testFromParseErrorReturnsException(): void $exception = ParseError::fromParseError($parseError); self::assertInstanceOf(ParseError::class, $exception); + self::assertInstanceOf(\ParseError::class, $exception); + self::assertInstanceOf(ExceptionInterface::class, $exception); self::assertSame($parseError->getMessage(), $exception->getMessage()); self::assertSame(0, $exception->getCode()); self::assertSame($parseError, $exception->getPrevious()); @@ -50,6 +52,8 @@ public function testFromFileNameAndParseErrorReturnsException(): void ); self::assertInstanceOf(ParseError::class, $exception); + self::assertInstanceOf(\ParseError::class, $exception); + self::assertInstanceOf(ExceptionInterface::class, $exception); $expectedMessage = \sprintf( 'A parse error occurred when parsing "%s": "%s".', diff --git a/test/Unit/Exception/ShouldNotHappenTest.php b/test/Unit/Exception/ShouldNotHappenTest.php index ce021ab2..54469aef 100644 --- a/test/Unit/Exception/ShouldNotHappenTest.php +++ b/test/Unit/Exception/ShouldNotHappenTest.php @@ -13,25 +13,24 @@ namespace Ergebnis\Classy\Test\Unit\Exception; +use Ergebnis\Classy\Exception\ExceptionInterface; use Ergebnis\Classy\Exception\ShouldNotHappen; +use PHPUnit\Framework; /** * @internal * * @covers \Ergebnis\Classy\Exception\ShouldNotHappen */ -final class ShouldNotHappenTest extends AbstractTestCase +final class ShouldNotHappenTest extends Framework\TestCase { - public function testExtendsLogicException(): void - { - $this->assertClassExtends(\LogicException::class, ShouldNotHappen::class); - } - public function testCreateReturnsException(): void { $exception = ShouldNotHappen::create(); self::assertInstanceOf(ShouldNotHappen::class, $exception); + self::assertInstanceOf(\LogicException::class, $exception); + self::assertInstanceOf(ExceptionInterface::class, $exception); self::assertSame('This should not happen.', $exception->getMessage()); self::assertSame(0, $exception->getCode()); self::assertNull($exception->getPrevious());