assertIsArray($decoded); $this->assertEquals(5, count($decoded)); $this->assertArrayHasKey('announce', $decoded); $this->assertEquals('https://tracker.flashii.net/announce.php/meow', $decoded['announce']); $this->assertArrayHasKey('creation date', $decoded); $this->assertEquals(1689973664, $decoded['creation date']); $this->assertArrayHasKey('info', $decoded); $this->assertIsArray($decoded['info']); $this->assertArrayHasKey('private', $decoded['info']); $this->assertEquals(1, $decoded['info']['private']); $decoded = Bencode::decode(base64_decode(self::TORRENT), associative: false); $this->assertIsObject($decoded); $this->assertObjectHasProperty('announce', $decoded); $this->assertEquals('https://tracker.flashii.net/announce.php/meow', $decoded->announce); // @phpstan-ignore-line: checked above $this->assertObjectHasProperty('creation date', $decoded); $this->assertEquals(1689973664, $decoded->{'creation date'}); // @phpstan-ignore-line: checked above $this->assertObjectHasProperty('comment', $decoded); $this->assertEquals('this is the comments field', $decoded->comment); // @phpstan-ignore-line: checked above $this->assertObjectHasProperty('info', $decoded); $this->assertIsObject($decoded->info); // @phpstan-ignore-line: checked above $this->assertObjectHasProperty('private', $decoded->info); $this->assertEquals(1, $decoded->info->private); // @phpstan-ignore-line: checked above } public function testEncode(): void { $original = base64_decode(self::TORRENT); $decoded = Bencode::decode($original); $encoded = Bencode::encode($decoded); $this->assertEquals($original, $encoded); } }