public function testToDomainTypesShouldReplaceMongoTypesByDomainTypes() { $mongoId = new MongoObjectID(); $timestamp = time(); $mongoDate = new MongoUTCDateTime($timestamp * 1000); $id = new ObjectID($mongoId); $date = new UTCDateTime($timestamp); $data = ['_id' => $mongoId, 'created_at' => $mongoDate, 'parents' => [$mongoId, $mongoId, $mongoId], 'comments' => [['author' => 'Jhon', 'date' => $mongoDate], ['author' => 'Doe', 'date' => $mongoDate, 'versions' => [['_id' => $mongoId, 'date' => $mongoDate, 'content' => 'Awsome'], ['_id' => $mongoId, 'date' => $mongoDate, 'content' => 'Great']]]]]; $expected = ['_id' => $id, 'created_at' => $date, 'parents' => [$id, $id, $id], 'comments' => [['author' => 'Jhon', 'date' => $date], ['author' => 'Doe', 'date' => $date, 'versions' => [['_id' => $id, 'date' => $date, 'content' => 'Awsome'], ['_id' => $id, 'date' => $date, 'content' => 'Great']]]]]; $this->assertEquals($expected, $this->converter->toDomainTypes($data)); }
/** * Converts recursively the given objects (probably retrieved from MongoDB) * to our specific types. * Example: converts MongoDB\BSON\ObjectID to Type\ObjectID. * * @param array $attributes Array to convert. * * @return array */ public function convert(array $attributes) { return $this->converter->toDomainTypes($attributes); }