diff --git a/tests/EncodeTest.php b/tests/EncodeTest.php index 9693b35..9458262 100644 --- a/tests/EncodeTest.php +++ b/tests/EncodeTest.php @@ -2,6 +2,7 @@ use PHPUnit\Framework\TestCase; use SandFox\Bencode\Bencode; +use SandFox\Bencode\Exceptions\InvalidArgumentException; use SandFox\Bencode\Types\BencodeSerializable; use SandFox\Bencode\Types\ListType; @@ -272,4 +273,19 @@ public function bencodeSerialize() $this->assertEquals('4:Test', Bencode::encode($dataRecursion)); $this->assertEquals('li1ei2ei3ee', Bencode::encode($dataArray)); } + + public function testUnknown() + { + // We can't serialize resources + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("Bencode doesn't know how to serialize an instance of resource"); + + Bencode::encode(fopen(__FILE__, 'r')); + + // We can't serialize non-stringable objects + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("Bencode doesn't know how to serialize an instance of " . get_class($this)); + + Bencode::encode($this); + } }