Commit bdefe81c authored by Anton Smirnov's avatar Anton Smirnov
Browse files

More tests, 100% coverage

parent fc2ff52d
Loading
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -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)
    {
+17 −0
Original line number Diff line number Diff line
@@ -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
{
@@ -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);
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -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()