-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: if xml value is set, change value in class metadata (#2670)
- Loading branch information
1 parent
52e6411
commit c4c6f85
Showing
6 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"> | ||
<entity name="Gedmo\Tests\Mapping\Fixture\Xml\References" table="references"> | ||
<id name="id" type="integer" column="id"> | ||
<generator strategy="AUTO"/> | ||
</id> | ||
<field name="name" type="string" length="128"/> | ||
<gedmo:reference field="users" reference="referenceMany" type="document" identifier="referecesId" class="Gedmo\Tests\Mapping\Fixture\Document\User" mappedBy="reference"/> | ||
</entity> | ||
</doctrine-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Doctrine Behavioral Extensions package. | ||
* (c) Gediminas Morkevicius <gediminas.morkevicius@gmail.com> http://www.gediminasm.org | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gedmo\Tests\Mapping\Fixture\Xml; | ||
|
||
use Gedmo\Tests\Mapping\Fixture\Document\User; | ||
|
||
class References | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var User[] | ||
*/ | ||
private $users; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Doctrine Behavioral Extensions package. | ||
* (c) Gediminas Morkevicius <gediminas.morkevicius@gmail.com> http://www.gediminasm.org | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gedmo\Tests\Mapping\Xml; | ||
|
||
use Doctrine\Common\Annotations\AnnotationReader; | ||
use Doctrine\Common\EventManager; | ||
use Doctrine\ORM\EntityManager; | ||
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; | ||
use Doctrine\ORM\Mapping\Driver\XmlDriver; | ||
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; | ||
use Gedmo\References\ReferencesListener; | ||
use Gedmo\Tests\Mapping\Fixture\Xml\References; | ||
use Gedmo\Tests\Tool\BaseTestCaseOM; | ||
|
||
/** | ||
* @author Guillermo Fuentes <guillermofuentesquijada@gmail.com> | ||
*/ | ||
final class ReferencesMappingTest extends BaseTestCaseOM | ||
{ | ||
/** | ||
* @var EntityManager | ||
*/ | ||
private $em; | ||
|
||
/** | ||
* @var ReferencesListener | ||
*/ | ||
private $referencesListener; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$reader = new AnnotationReader(); | ||
$annotationDriver = new AnnotationDriver($reader); | ||
|
||
$xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml'); | ||
|
||
$chain = new MappingDriverChain(); | ||
$chain->addDriver($xmlDriver, 'Gedmo\Tests\Mapping\Fixture\Xml'); | ||
$chain->addDriver($annotationDriver, 'Gedmo\Tests\Mapping\Fixture'); | ||
|
||
$this->referencesListener = new ReferencesListener(); | ||
$this->evm = new EventManager(); | ||
$this->evm->addEventSubscriber($this->referencesListener); | ||
|
||
$this->em = $this->getDefaultMockSqliteEntityManager([ | ||
References::class, | ||
], $chain); | ||
} | ||
|
||
public function testMetadata(): void | ||
{ | ||
$meta = $this->em->getClassMetadata(References::class); | ||
$config = $this->referencesListener->getConfiguration($this->em, $meta->getName()); | ||
|
||
static::assertArrayHasKey('referenceMany', $config); | ||
static::assertArrayHasKey('useObjectClass', $config); | ||
static::assertSame(References::class, $config['useObjectClass']); | ||
$configInternal = $config['referenceMany']; | ||
static::assertArrayHasKey('users', $configInternal); | ||
$configUsers = $configInternal['users']; | ||
static::assertArrayHasKey('field', $configUsers); | ||
static::assertArrayHasKey('type', $configUsers); | ||
static::assertSame('document', $configUsers['type']); | ||
static::assertArrayHasKey('class', $configUsers); | ||
static::assertArrayHasKey('identifier', $configUsers); | ||
static::assertArrayHasKey('mappedBy', $configUsers); | ||
static::assertSame('reference', $configUsers['mappedBy']); | ||
} | ||
} |