From 477d78dcb7a9c053457cd113e46c5d294d97ced8 Mon Sep 17 00:00:00 2001 From: Guillermo Fuentes <92819410+gfuentesboost@users.noreply.github.com> Date: Thu, 17 Aug 2023 20:53:18 +0200 Subject: [PATCH 1/7] fix: if xml value is set, change value in class metadata --- src/References/Mapping/Driver/Xml.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/References/Mapping/Driver/Xml.php b/src/References/Mapping/Driver/Xml.php index 9a7b0c774d..8f5bd0954a 100644 --- a/src/References/Mapping/Driver/Xml.php +++ b/src/References/Mapping/Driver/Xml.php @@ -93,10 +93,10 @@ public function readExtendedMetadata($meta, array &$config) 'identifier' => $identifier, ]; - if (!$this->_isAttributeSet($element, 'mappedBy')) { + if ($this->_isAttributeSet($element, 'mappedBy')) { $config[$reference][$field]['mappedBy'] = $this->_getAttribute($element, 'mappedBy'); } - if (!$this->_isAttributeSet($element, 'inversedBy')) { + if ($this->_isAttributeSet($element, 'inversedBy')) { $config[$reference][$field]['inversedBy'] = $this->_getAttribute($element, 'inversedBy'); } } From d38bb726bbac44d9fef9b0d0df6f817f82a597b9 Mon Sep 17 00:00:00 2001 From: Guillermo Fuentes Quijada Date: Fri, 18 Aug 2023 13:48:04 +0200 Subject: [PATCH 2/7] add: test --- ...sts.Mapping.Fixture.Xml.References.dcm.xml | 10 +++ .../Gedmo/Mapping/Fixture/Xml/References.php | 30 +++++++ .../Mapping/Xml/ReferencesMappingTest.php | 83 +++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml create mode 100644 tests/Gedmo/Mapping/Fixture/Xml/References.php create mode 100644 tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php diff --git a/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml b/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml new file mode 100644 index 0000000000..56a797b3d2 --- /dev/null +++ b/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/tests/Gedmo/Mapping/Fixture/Xml/References.php b/tests/Gedmo/Mapping/Fixture/Xml/References.php new file mode 100644 index 0000000000..7467be3130 --- /dev/null +++ b/tests/Gedmo/Mapping/Fixture/Xml/References.php @@ -0,0 +1,30 @@ + 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; + +class References +{ + /** + * @var int + */ + private $id; + + /** + * @var string + */ + private $name; + + /** + * @var User[] + */ + private $users; +} diff --git a/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php b/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php new file mode 100644 index 0000000000..ac3ad93a8e --- /dev/null +++ b/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php @@ -0,0 +1,83 @@ + 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; + +/** + * These are mapping tests for SoftDeleteable extension + * + * @author Gustavo Falco + * @author Gediminas Morkevicius + */ +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::assertEquals(References::class, $config['useObjectClass']); + $configInternal = $config['referenceMany']; + static::assertArrayHasKey('users', $configInternal); + $configUsers = $configInternal['users']; + static::assertArrayHasKey('field', $configUsers); + static::assertArrayHasKey('type', $configUsers); + static::assertEquals('document', $configUsers['type']); + static::assertArrayHasKey('class', $configUsers); + static::assertArrayHasKey('identifier', $configUsers); + static::assertArrayHasKey('mappedBy', $configUsers); + static::assertEquals('reference', $configUsers['mappedBy']); + } +} From f1c5692bb6c939dfe3c627afb8eef03b4d33dd3e Mon Sep 17 00:00:00 2001 From: Guillermo Fuentes Quijada Date: Fri, 18 Aug 2023 16:54:17 +0200 Subject: [PATCH 3/7] fix: linters --- ...Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml | 2 +- tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml b/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml index 56a797b3d2..6666e0a479 100644 --- a/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml +++ b/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml @@ -5,6 +5,6 @@ - + diff --git a/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php b/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php index ac3ad93a8e..d7c7cda433 100644 --- a/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php +++ b/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php @@ -24,8 +24,7 @@ /** * These are mapping tests for SoftDeleteable extension * - * @author Gustavo Falco - * @author Gediminas Morkevicius + * @author Guillermo Fuentes */ final class ReferencesMappingTest extends BaseTestCaseOM { @@ -46,7 +45,7 @@ protected function setUp(): void $reader = new AnnotationReader(); $annotationDriver = new AnnotationDriver($reader); - $xmlDriver = new XmlDriver(__DIR__ . '/../Driver/Xml'); + $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml'); $chain = new MappingDriverChain(); $chain->addDriver($xmlDriver, 'Gedmo\Tests\Mapping\Fixture\Xml'); @@ -68,16 +67,16 @@ public function testMetadata(): void static::assertArrayHasKey('referenceMany', $config); static::assertArrayHasKey('useObjectClass', $config); - static::assertEquals(References::class, $config['useObjectClass']); + 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::assertEquals('document', $configUsers['type']); + static::assertSame('document', $configUsers['type']); static::assertArrayHasKey('class', $configUsers); static::assertArrayHasKey('identifier', $configUsers); static::assertArrayHasKey('mappedBy', $configUsers); - static::assertEquals('reference', $configUsers['mappedBy']); + static::assertSame('reference', $configUsers['mappedBy']); } } From 7635f5af7b395b1b75198f56cbc1b68db94c6ee4 Mon Sep 17 00:00:00 2001 From: Guillermo Fuentes Quijada Date: Fri, 18 Aug 2023 16:55:55 +0200 Subject: [PATCH 4/7] fix: phpstan --- tests/Gedmo/Mapping/Fixture/Xml/References.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Gedmo/Mapping/Fixture/Xml/References.php b/tests/Gedmo/Mapping/Fixture/Xml/References.php index 7467be3130..d18e62393c 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/References.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/References.php @@ -11,6 +11,8 @@ namespace Gedmo\Tests\Mapping\Fixture\Xml; +use Gedmo\Tests\Mapping\Fixture\Document\User; + class References { /** From 9b0bdbb756cd6bff7c11a166909f606bdd7c1ca7 Mon Sep 17 00:00:00 2001 From: Guillermo Fuentes Quijada Date: Fri, 18 Aug 2023 18:08:21 +0200 Subject: [PATCH 5/7] fix: doctrine mapping --- schemas/orm/doctrine-extensions-mapping-2-2.xsd | 2 ++ .../Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/schemas/orm/doctrine-extensions-mapping-2-2.xsd b/schemas/orm/doctrine-extensions-mapping-2-2.xsd index 34ce2a37ed..71f30049a1 100644 --- a/schemas/orm/doctrine-extensions-mapping-2-2.xsd +++ b/schemas/orm/doctrine-extensions-mapping-2-2.xsd @@ -29,6 +29,7 @@ + @@ -65,6 +66,7 @@ + diff --git a/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml b/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml index 6666e0a479..32c8e2c6a9 100644 --- a/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml +++ b/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.References.dcm.xml @@ -1,6 +1,6 @@ - + From 8b431bcbedb4ae8761cf11529787cd7a8e8d5f24 Mon Sep 17 00:00:00 2001 From: Guillermo Fuentes Quijada Date: Mon, 21 Aug 2023 09:29:10 +0200 Subject: [PATCH 6/7] add: changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7375e30135..8eb668c10b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ a release. ## [Unreleased] ### Changed - Add conflict with "doctrine/orm" >=2.16 (temporary change until code is fixed) +### Fixed +- References: fixed condition in `XML` Driver that did not allow to retrieve from the entity definition the `mappedBy` and `inversedBy` fields. ## [3.12.0] - 2023-07-08 ### Added From 1eeaa2343dd729ceaf371ba07c802c07e666eab4 Mon Sep 17 00:00:00 2001 From: Guillermo Fuentes Quijada Date: Wed, 30 Aug 2023 19:09:03 +0200 Subject: [PATCH 7/7] fix: comment test --- tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php b/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php index d7c7cda433..29590c099a 100644 --- a/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php +++ b/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php @@ -22,8 +22,6 @@ use Gedmo\Tests\Tool\BaseTestCaseOM; /** - * These are mapping tests for SoftDeleteable extension - * * @author Guillermo Fuentes */ final class ReferencesMappingTest extends BaseTestCaseOM