Skip to content

NULL MongoDate field causes "Trying to get property of non-object" error #9

@Jasrags

Description

@Jasrags

Example mongo rating record array:
....array(8) {
'_id' =>
class MongoId#186 (1) {
public $$id =>
string(24) "5154d78a8c69d87a4000000b"
}
'ID' =>
string(8) "13-12345"
'Version' =>
int(18)
'createdAt' =>
class MongoDate#182 (2) {
public $sec =>
int(1364514698)
public $usec =>
int(896000)
}
'updatedAt' =>
NULL
}

Example model Rating.php:
public function properties()
{
return array(
'ID' => new StringField(array('required' => true)),
'Version' => new IntegerField(array('required' => true)),
'createdAt' => new DateField(),
'updatedAt' => new DateField(),
);
}

Example Test.php:
public function testRating()
{
$mongoDoc = unserialize(file_get_contents(DIR . '/data/rating.out'));
$rating = new Rating();
$rating->fromMongo($mongoDoc);

    $this->assertEquals($mongoDoc['ID'], $rating->ID);
    $this->assertEquals($mongoDoc['Version'], $rating->Version);
    $this->assertInstanceOf('\DateTime', $rating->createdAt);
    $this->assertInstanceOf('\DateTime', $rating->updatedAt);
}

Will cause:
Trying to get property of non-object

/vendor/99designs/moa/lib/Moa/Types/DateField.php:64
/vendor/99designs/moa/lib/Moa/Document.php:27
/vendor/99designs/moa/lib/Moa/DomainObject.php:40
/test/unit/Test.php:17

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions