Skip to content

Commit

Permalink
Test for unserializable values
Browse files Browse the repository at this point in the history
  • Loading branch information
arokettu committed Jun 30, 2020
1 parent 56952f2 commit 9d63110
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/EncodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 9d63110

Please sign in to comment.