diff --git a/src/Exception/CouldNotCompressData.php b/src/Exception/CouldNotCompressData.php deleted file mode 100644 index 6fb64af..0000000 --- a/src/Exception/CouldNotCompressData.php +++ /dev/null @@ -1,14 +0,0 @@ - - */ -abstract class CouldNotCompressData extends CouldNotProcessData implements Exception -{ -} diff --git a/src/Exception/CouldNotDecompressData.php b/src/Exception/CouldNotDecompressData.php deleted file mode 100644 index 786d241..0000000 --- a/src/Exception/CouldNotDecompressData.php +++ /dev/null @@ -1,14 +0,0 @@ - - */ -abstract class CouldNotDecompressData extends CouldNotProcessData implements Exception -{ -} diff --git a/src/Exception/LzmaCouldNotCompressData.php b/src/Exception/LzmaCouldNotCompressData.php index c73c38d..b9d68ca 100644 --- a/src/Exception/LzmaCouldNotCompressData.php +++ b/src/Exception/LzmaCouldNotCompressData.php @@ -4,6 +4,11 @@ namespace PetrKnap\XzUtils\Exception; -final class LzmaCouldNotCompressData extends CouldNotCompressData implements LzmaException +use PetrKnap\Shorts\Exception\CouldNotProcessData; + +/** + * @extends CouldNotProcessData + */ +final class LzmaCouldNotCompressData extends CouldNotProcessData implements LzmaException { } diff --git a/src/Exception/LzmaCouldNotDecompressData.php b/src/Exception/LzmaCouldNotDecompressData.php index d9f0ebe..516ae19 100644 --- a/src/Exception/LzmaCouldNotDecompressData.php +++ b/src/Exception/LzmaCouldNotDecompressData.php @@ -4,6 +4,11 @@ namespace PetrKnap\XzUtils\Exception; -final class LzmaCouldNotDecompressData extends CouldNotDecompressData implements XzException +use PetrKnap\Shorts\Exception\CouldNotProcessData; + +/** + * @extends CouldNotProcessData + */ +final class LzmaCouldNotDecompressData extends CouldNotProcessData implements LzmaException { } diff --git a/src/Exception/XzCouldNotCompressData.php b/src/Exception/XzCouldNotCompressData.php index 672e7f0..410b8f7 100644 --- a/src/Exception/XzCouldNotCompressData.php +++ b/src/Exception/XzCouldNotCompressData.php @@ -4,6 +4,11 @@ namespace PetrKnap\XzUtils\Exception; -final class XzCouldNotCompressData extends CouldNotCompressData implements XzException +use PetrKnap\Shorts\Exception\CouldNotProcessData; + +/** + * @extends CouldNotProcessData + */ +final class XzCouldNotCompressData extends CouldNotProcessData implements XzException { } diff --git a/src/Exception/XzCouldNotDecompressData.php b/src/Exception/XzCouldNotDecompressData.php index 1cab810..cbffa09 100644 --- a/src/Exception/XzCouldNotDecompressData.php +++ b/src/Exception/XzCouldNotDecompressData.php @@ -4,6 +4,11 @@ namespace PetrKnap\XzUtils\Exception; -final class XzCouldNotDecompressData extends CouldNotDecompressData implements XzException +use PetrKnap\Shorts\Exception\CouldNotProcessData; + +/** + * @extends CouldNotProcessData + */ +final class XzCouldNotDecompressData extends CouldNotProcessData implements XzException { } diff --git a/src/Lzma.php b/src/Lzma.php index 6d98354..ec0d718 100644 --- a/src/Lzma.php +++ b/src/Lzma.php @@ -14,7 +14,10 @@ protected static function compressException(): string return Exception\LzmaCouldNotCompressData::class; } - protected static function decompressException(): string + /** + * @internal public for testing purposes only + */ + public static function decompressException(): string { return Exception\LzmaCouldNotDecompressData::class; } diff --git a/src/Xz.php b/src/Xz.php index 274473d..8d68b56 100644 --- a/src/Xz.php +++ b/src/Xz.php @@ -14,7 +14,10 @@ protected static function compressException(): string return Exception\XzCouldNotCompressData::class; } - protected static function decompressException(): string + /** + * @internal public for testing purposes only + */ + public static function decompressException(): string { return Exception\XzCouldNotDecompressData::class; } diff --git a/src/XzUtils.php b/src/XzUtils.php index 90a085c..fdd8358 100644 --- a/src/XzUtils.php +++ b/src/XzUtils.php @@ -5,19 +5,20 @@ namespace PetrKnap\XzUtils; use PetrKnap\ExternalFilter\Exception\FilterException; +use PetrKnap\Shorts\Exception\CouldNotProcessData; /** * @internal shared logic * - * @template TCompressException of Exception\CouldNotCompressData - * @template TDecompressException of Exception\CouldNotDecompressData + * @template TCompressException of Exception\Exception + * @template TDecompressException of Exception\Exception */ abstract class XzUtils { /** * @param array|null $options * - * @throws TCompressException&Exception\CouldNotCompressData + * @throws TCompressException */ final public function compress( string $data, @@ -34,7 +35,7 @@ final public function compress( /** * @param array|null $options * - * @throws TDecompressException&Exception\CouldNotDecompressData + * @throws TDecompressException */ final public function decompress( string $data, @@ -48,12 +49,12 @@ final public function decompress( } /** - * @return class-string + * @return class-string> */ abstract protected static function compressException(): string; /** - * @return class-string + * @return class-string> */ abstract protected static function decompressException(): string; diff --git a/tests/XzUtilsTestCase.php b/tests/XzUtilsTestCase.php index a8f243e..bfd3f46 100644 --- a/tests/XzUtilsTestCase.php +++ b/tests/XzUtilsTestCase.php @@ -4,9 +4,11 @@ namespace PetrKnap\XzUtils; +use PetrKnap\Shorts\Exception\CouldNotProcessData; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; +use Throwable; #[CoversClass(FilterFactory::class)] abstract class XzUtilsTestCase extends TestCase @@ -31,11 +33,19 @@ final public function testDecompressesData(string $decompressed, string $compres ); } - final public function testDecompressThrowsOnWrongData(): void + final public function testDecompressThrowsCorrectlyOnWrongData(): void { - self::expectException(Exception\CouldNotDecompressData::class); + self::expectException(Exception\Exception::class); - static::getInstance()->decompress('?'); + try { + static::getInstance()->decompress('wrong data'); + } catch (Throwable $throwable) { + self::assertInstanceOf(call_user_func([static::getInstance()::class, 'decompressException']), $throwable); + /** @var CouldNotProcessData $throwable */ + self::assertSame('wrong data', $throwable->getData()); + + throw $throwable; + } } public static function data(): array