-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapped entity listeners are now processed by metadata exporters #6593
Changes from all commits
b7ae5b4
ec3eed6
741819f
fe88422
5998655
b1e091b
e4006e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
use Doctrine\Common\EventManager; | ||
use Doctrine\Common\Persistence\Mapping\Driver\PHPDriver; | ||
use Doctrine\ORM\Configuration; | ||
use Doctrine\ORM\Events; | ||
use Doctrine\ORM\Mapping\ClassMetadata; | ||
use Doctrine\ORM\Mapping\ClassMetadataFactory; | ||
use Doctrine\ORM\Mapping\ClassMetadataInfo; | ||
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; | ||
|
@@ -344,7 +346,7 @@ public function testInversedByIsExported($class) | |
{ | ||
$this->assertEquals('user', $class->associationMappings['address']['inversedBy']); | ||
} | ||
/** | ||
/** | ||
* @depends testExportDirectoryAndFilesAreCreated | ||
*/ | ||
public function testCascadeAllCollapsed() | ||
|
@@ -371,6 +373,26 @@ public function testCascadeAllCollapsed() | |
} | ||
} | ||
|
||
/** | ||
* @depends testExportedMetadataCanBeReadBackIn | ||
* | ||
* @param ClassMetadata $class | ||
*/ | ||
public function testEntityListenersAreExported($class) | ||
{ | ||
$this->assertNotEmpty($class->entityListeners); | ||
$this->assertCount(2, $class->entityListeners[Events::prePersist]); | ||
$this->assertCount(2, $class->entityListeners[Events::postPersist]); | ||
$this->assertEquals(UserListener::class, $class->entityListeners[Events::prePersist][0]['class']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, this is the test that I was missing. |
||
$this->assertEquals('customPrePersist', $class->entityListeners[Events::prePersist][0]['method']); | ||
$this->assertEquals(GroupListener::class, $class->entityListeners[Events::prePersist][1]['class']); | ||
$this->assertEquals('prePersist', $class->entityListeners[Events::prePersist][1]['method']); | ||
$this->assertEquals(UserListener::class, $class->entityListeners[Events::postPersist][0]['class']); | ||
$this->assertEquals('customPostPersist', $class->entityListeners[Events::postPersist][0]['method']); | ||
$this->assertEquals(AddressListener::class, $class->entityListeners[Events::postPersist][1]['class']); | ||
$this->assertEquals('customPostPersist', $class->entityListeners[Events::postPersist][1]['method']); | ||
} | ||
|
||
public function __destruct() | ||
{ | ||
# $this->_deleteDirectory(__DIR__ . '/export/'.$this->_getType()); | ||
|
@@ -406,3 +428,28 @@ class Group | |
{ | ||
|
||
} | ||
class UserListener | ||
{ | ||
/** | ||
* @\Doctrine\ORM\Mapping\PrePersist | ||
*/ | ||
public function customPrePersist(): void {} | ||
/** | ||
* @\Doctrine\ORM\Mapping\PostPersist | ||
*/ | ||
public function customPostPersist(): void {} | ||
} | ||
class GroupListener | ||
{ | ||
/** | ||
* @\Doctrine\ORM\Mapping\PrePersist | ||
*/ | ||
public function prePersist(): void {} | ||
} | ||
class AddressListener | ||
{ | ||
/** | ||
* @\Doctrine\ORM\Mapping\PostPersist | ||
*/ | ||
public function customPostPersist(): void {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,11 @@ | |
/** | ||
* @Entity | ||
* @HasLifecycleCallbacks | ||
* @EntityListeners({ | ||
* Doctrine\Tests\ORM\Tools\Export\UserListener::class, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should probably be prefixed with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a weird issue with this, the resulting string is <?php
echo \SimpleXMLElement::class;
// SimpleXMLElement Using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tPl0ch gotcha, seems weird, but it's probably a doctrine/annotations bug. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to doctrine/annotations#141 |
||
* Doctrine\Tests\ORM\Tools\Export\GroupListener::class, | ||
* Doctrine\Tests\ORM\Tools\Export\AddressListener::class | ||
* }) | ||
* @Table(name="cms_users",options={"engine"="MyISAM","foo"={"bar"="baz"}}) | ||
*/ | ||
class User | ||
|
@@ -57,21 +62,21 @@ class User | |
/** | ||
* @PrePersist | ||
*/ | ||
public function doStuffOnPrePersist() | ||
public function doStuffOnPrePersist(): void | ||
{ | ||
} | ||
|
||
/** | ||
* @PrePersist | ||
*/ | ||
public function doOtherStuffOnPrePersistToo() | ||
public function doOtherStuffOnPrePersistToo(): void | ||
{ | ||
} | ||
|
||
/** | ||
* @PostPersist | ||
*/ | ||
public function doStuffOnPostPersist() | ||
public function doStuffOnPostPersist(): void | ||
{ | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really want to use
@depends
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's how all other export tests are structured, so I just adhered to the structure within the test case.