Skip to content

Commit af47302

Browse files
authored
Don't wrap the reader if it is already an attribute reader (#2566)
* Don't wrap the reader if it is already an attribute reader * Test the LoggableListener with both an annotation and attribute reader * Apply suggestions from code review
1 parent 7c27ed8 commit af47302

File tree

4 files changed

+80
-16
lines changed

4 files changed

+80
-16
lines changed

src/Mapping/ExtensionMetadataFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ protected function getDriver($omDriver)
206206
}
207207

208208
if ($driver instanceof AttributeDriverInterface) {
209-
$driver->setAnnotationReader(new AttributeAnnotationReader(new AttributeReader(), $this->annotationReader));
209+
if ($this->annotationReader instanceof AttributeReader) {
210+
$driver->setAnnotationReader($this->annotationReader);
211+
} else {
212+
$driver->setAnnotationReader(new AttributeAnnotationReader(new AttributeReader(), $this->annotationReader));
213+
}
210214
} elseif ($driver instanceof AnnotationDriverInterface) {
211215
$driver->setAnnotationReader($this->annotationReader);
212216
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Doctrine Behavioral Extensions package.
7+
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Gedmo\Loggable;
13+
14+
use Doctrine\Common\EventManager;
15+
use Gedmo\Tests\Loggable\LoggableEntityTest;
16+
17+
/**
18+
* These are tests for loggable behavior with an annotation reader (created by the listener by default)
19+
*
20+
* @author Gediminas Morkevicius <[email protected]>
21+
*/
22+
final class AnnotationLoggableEntityTest extends LoggableEntityTest
23+
{
24+
protected function setUp(): void
25+
{
26+
parent::setUp();
27+
28+
$evm = new EventManager();
29+
$loggableListener = new LoggableListener();
30+
$loggableListener->setUsername('jules');
31+
$evm->addEventSubscriber($loggableListener);
32+
33+
$this->em = $this->getDefaultMockSqliteEntityManager($evm);
34+
}
35+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Doctrine Behavioral Extensions package.
7+
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Gedmo\Loggable;
13+
14+
use Doctrine\Common\EventManager;
15+
use Gedmo\Mapping\Driver\AttributeReader;
16+
use Gedmo\Tests\Loggable\LoggableEntityTest;
17+
18+
/**
19+
* These are tests for loggable behavior with an attribute reader
20+
*
21+
* @requires PHP >= 8.0
22+
*
23+
* @author Gediminas Morkevicius <[email protected]>
24+
*/
25+
final class AttributeLoggableEntityTest extends LoggableEntityTest
26+
{
27+
protected function setUp(): void
28+
{
29+
parent::setUp();
30+
31+
$evm = new EventManager();
32+
$loggableListener = new LoggableListener();
33+
$loggableListener->setAnnotationReader(new AttributeReader());
34+
$loggableListener->setUsername('jules');
35+
$evm->addEventSubscriber($loggableListener);
36+
37+
$this->em = $this->getDefaultMockSqliteEntityManager($evm);
38+
}
39+
}

tests/Gedmo/Loggable/LoggableEntityTest.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
namespace Gedmo\Tests\Loggable;
1313

14-
use Doctrine\Common\EventManager;
1514
use Gedmo\Loggable\Entity\LogEntry;
16-
use Gedmo\Loggable\LoggableListener;
1715
use Gedmo\Tests\Loggable\Fixture\Entity\Address;
1816
use Gedmo\Tests\Loggable\Fixture\Entity\Article;
1917
use Gedmo\Tests\Loggable\Fixture\Entity\Comment;
@@ -27,25 +25,13 @@
2725
*
2826
* @author Gediminas Morkevicius <[email protected]>
2927
*/
30-
final class LoggableEntityTest extends BaseTestCaseORM
28+
abstract class LoggableEntityTest extends BaseTestCaseORM
3129
{
3230
public const ARTICLE = Article::class;
3331
public const COMMENT = Comment::class;
3432
public const RELATED_ARTICLE = RelatedArticle::class;
3533
public const COMMENT_LOG = \Gedmo\Tests\Loggable\Fixture\Entity\Log\Comment::class;
3634

37-
protected function setUp(): void
38-
{
39-
parent::setUp();
40-
41-
$evm = new EventManager();
42-
$loggableListener = new LoggableListener();
43-
$loggableListener->setUsername('jules');
44-
$evm->addEventSubscriber($loggableListener);
45-
46-
$this->em = $this->getDefaultMockSqliteEntityManager($evm);
47-
}
48-
4935
public function testShouldHandleClonedEntity(): void
5036
{
5137
$art0 = new Article();

0 commit comments

Comments
 (0)