spatie/phpunit-snapshot-assertions

MongoDB ObjectId spanshots are wrong

Closed this issue · 1 comments

The snapshots should contain the string representation (5deb63d67c562a39d75aa126) but they are timestamp in the current version of phpunit-snapshot-assertions. At the moment it is not a serious issue for me, but I am surprised to know that sometimes snapshots saved ObjectIds as null in older versions.

Test Case 1

public function test_object_id()
{
    $id = new MongoDB\BSON\ObjectId('5deb63d67c562a39d75aa126');
    $this->assertMatchesSnapshot($id);
}

Invalid yml Snapshot in ^4.2.6

timestamp: 1575707606

Correct php Snapshot in ^3.0.0

<?php return MongoDB\BSON\ObjectId::__set_state(array(
   'oid' => '5deb63d67c562a39d75aa126',
));

Test Case 2

public function test_object_id()
{
    $id = new MongoDB\BSON\ObjectId('5deb63d67c562a39d75aa126');
    $this->assertMatchesSnapshot([$id]); // <-- Array snapshot
}

Invalid yml Snapshot in ^4.2.6

-
    timestamp: 1575707606

Invalid yml Snapshot in ^3.0.0

- null

Feel free to create a PR to improve this.