Skip to content

Commit

Permalink
More serialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-xo committed Feb 14, 2021
1 parent 1cc7c62 commit f358eb4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/Media_RSS_Item_SerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,45 @@ public function test_serialize_and_deserialize_yield_the_same_thing()
$this->assertEquals('b', $item2->getB());
}

public function test_unserialize_rejects_invalid_serialization_version()
{
$item = new Media_RSS_Item('example.mp3');
$item->setA('a');
$item->setB('b');

$serialized = serialize($item);
$serialized = preg_replace('/:"serialVersion";i:\d+;/', ':"serialVersion";i:0;', $serialized);
$this->expectException(SerializationException::class);
$item2 = unserialize($serialized);
}

public function test_unserialize_does_not_overwrite_properties_set_from_fs_metadata()
{
$item = new Media_RSS_Item('example.mp3');
$item->setA('a');
$item->setB('b');

$serialized = $item->serialize($item);

file_put_contents('example2.abc', 'abcde');
$filemtime = time()-100;
touch('example2.abc', $filemtime);
$item2 = new Media_RSS_Item('example2.abc');
$item2->unserialize($serialized);

$this->assertEquals('a', $item2->getA());
$this->assertEquals('b', $item2->getB());

$this->assertEquals(5, $item2->getLength());
$this->assertEquals(date('r', $filemtime), $item2->getPubDate());
$this->assertEquals('example2.abc', $item2->getFilename());
$this->assertEquals('abc', $item2->getExtension());
$this->assertEquals('http://www.example.com/mp3/example2.abc', $item2->getLink());
}

public function tearDown(): void
{
unlink('example.mp3');
file_exists('example2.abc') && unlink('example2.abc');
}
}

0 comments on commit f358eb4

Please sign in to comment.