Loading src/Engine/Decoder.php +0 −2 Original line number Diff line number Diff line Loading @@ -155,10 +155,8 @@ final class Decoder return; } if ((string)$int !== $intStr) { throw new ParseErrorException("Invalid integer format or integer overflow: '{$intStr}'"); } } private function stringToBigInt(string $intStr) { Loading tests/FileTest.php +17 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ namespace SandFox\Bencode\Tests; use PHPUnit\Framework\TestCase; use SandFoxMe\Bencode\Bencode; use SandFoxMe\Bencode\Exceptions\InvalidArgumentException; class FileTest extends TestCase { Loading Loading @@ -69,4 +70,20 @@ class FileTest extends TestCase unlink($file); } public function testEncodeToInvalidResource() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Output is not a valid stream'); Bencode::encodeToStream([], false); } public function testDecodeFromInvalidResource() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Input is not a valid stream'); Bencode::decodeStream(false); } } tests/LargeIntegerTest.php +10 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,16 @@ class LargeIntegerTest extends TestCase self::assertEquals(self::POW_2_1024, $decoded->getValue()); } public function testInvalidMode() { $encoded = 'i' . self::POW_2_1024 . 'e'; $this->expectException(ParseErrorException::class); $this->expectExceptionMessage('Invalid BigMath mode'); Bencode::decode($encoded, ['bigInt' => 'invalid']); } // GMP public function testEncodeLargeIntegerGMP() Loading Loading
src/Engine/Decoder.php +0 −2 Original line number Diff line number Diff line Loading @@ -155,10 +155,8 @@ final class Decoder return; } if ((string)$int !== $intStr) { throw new ParseErrorException("Invalid integer format or integer overflow: '{$intStr}'"); } } private function stringToBigInt(string $intStr) { Loading
tests/FileTest.php +17 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ namespace SandFox\Bencode\Tests; use PHPUnit\Framework\TestCase; use SandFoxMe\Bencode\Bencode; use SandFoxMe\Bencode\Exceptions\InvalidArgumentException; class FileTest extends TestCase { Loading Loading @@ -69,4 +70,20 @@ class FileTest extends TestCase unlink($file); } public function testEncodeToInvalidResource() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Output is not a valid stream'); Bencode::encodeToStream([], false); } public function testDecodeFromInvalidResource() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Input is not a valid stream'); Bencode::decodeStream(false); } }
tests/LargeIntegerTest.php +10 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,16 @@ class LargeIntegerTest extends TestCase self::assertEquals(self::POW_2_1024, $decoded->getValue()); } public function testInvalidMode() { $encoded = 'i' . self::POW_2_1024 . 'e'; $this->expectException(ParseErrorException::class); $this->expectExceptionMessage('Invalid BigMath mode'); Bencode::decode($encoded, ['bigInt' => 'invalid']); } // GMP public function testEncodeLargeIntegerGMP() Loading