You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to find a suitable place to test this and throw an exception so I could have submitted a PR with fix & test case, but unfortunately I do not know that much about mongodb-odm codebase to find a correct place for throwing an exception...
However, I drafted a test case for the issue. Don't know whether HydratorException is the correct exception class and where this test function should be added (Tests/Functional/InheritanceTest.php maybe), but here is it anyway.
/** * @expectedException \Doctrine\ODM\MongoDB\Hydrator\HydratorException */publicfunctiontestUnsupportedDatabaseValueForDiscriminatorMapRaisesException()
{
$project = new \Documents\Project('Project');
$this->dm->persist($project);
$this->dm->flush();
$id = $project->getId();
$coll = $this->dm->getDocumentCollection('Documents\Project');
$document = $coll->findOne(array('name' => 'Project'));
$this->assertEquals('project', $document['type']);
// Changing database value for DiscriminatorMap field$coll->update(array('name' => 'Project'), array('$set' => array('type' => 'unsupported-type')));
// Ensuring it's properly persisted$document = $coll->findOne(array('name' => 'Project'));
$this->assertEquals('unsupported-type', $document['type']);
// This query should raise \Doctrine\ODM\MongoDB\Mapping\HydratorException// because 'unsupported-type' is not an allowed value in @DiscriminatorMap$document = $this->dm->find('Documents\Project', $id);
$this->assertInstanceOf('Documents\Project', $document);
}
The text was updated successfully, but these errors were encountered:
Referring to the second issue in my SO question (http://stackoverflow.com/questions/15056946/doctrine-odm-returns-proxy-object-for-base-class-instead-of-sub-classed-document): if a database value of the discriminator field changes to some unsupported value, a PHP notice is thrown instead of proper exception.
I tried to find a suitable place to test this and throw an exception so I could have submitted a PR with fix & test case, but unfortunately I do not know that much about mongodb-odm codebase to find a correct place for throwing an exception...
However, I drafted a test case for the issue. Don't know whether HydratorException is the correct exception class and where this test function should be added (
Tests/Functional/InheritanceTest.php
maybe), but here is it anyway.The text was updated successfully, but these errors were encountered: