Skip to content

Commit

Permalink
Change serialization of inheritance fields
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Feb 1, 2017
1 parent 12611cf commit 20da3ee
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function __sleep()
$serialized[] = 'customRepositoryClassName';
}

if ($this->inheritanceType != self::INHERITANCE_TYPE_NONE) {
if ($this->inheritanceType != self::INHERITANCE_TYPE_NONE || $this->discriminatorField !== null) {
$serialized[] = 'inheritanceType';
$serialized[] = 'discriminatorField';
$serialized[] = 'discriminatorValue';
Expand Down
33 changes: 33 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,37 @@ public function testMapNotExistingFieldThrowsException()
$cm = new ClassMetadata('Documents\CmsUser');
$cm->mapField(array('fieldName' => 'namee', 'columnName' => 'name', 'type' => 'string'));
}

/**
* @param ClassMetadata $cm
* @dataProvider dataProviderMetadataClasses
*/
public function testEmbeddedDocumentWithDiscriminator(ClassMetadata $cm)
{
$cm->setDiscriminatorField('discriminator');
$cm->setDiscriminatorValue('discriminatorValue');

$serialized = serialize($cm);
$cm = unserialize($serialized);

$this->assertSame('discriminator', $cm->discriminatorField);
$this->assertSame('discriminatorValue', $cm->discriminatorValue);
}

public static function dataProviderMetadataClasses()
{
$document = new ClassMetadata('Documents\CmsUser');

$embeddedDocument = new ClassMetadata('Documents\CmsUser');
$embeddedDocument->isEmbeddedDocument = true;

$mappedSuperclass = new ClassMetadata('Documents\CmsUser');
$mappedSuperclass->isMappedSuperclass = true;

return [
'document' => [$document],
'mappedSuperclass' => [$mappedSuperclass],
'embeddedDocument' => [$embeddedDocument],
];
}
}

0 comments on commit 20da3ee

Please sign in to comment.