From 570844364ffb1d5d5fbd78a4099a63bdfcd9c6ca Mon Sep 17 00:00:00 2001 From: dantleech Date: Thu, 21 Feb 2013 09:38:16 +0000 Subject: [PATCH 1/3] Removed extra event classes, made more similar to Commons 2.4 --- .../ODM/PHPCR/Event/LifecycleEventArgs.php | 16 ++++++ .../Event/LoadClassMetadataEventArgs.php | 10 ++++ .../ODM/PHPCR/Event/OnClearEventArgs.php | 46 ----------------- .../ODM/PHPCR/Event/OnFlushEventArgs.php | 46 ----------------- .../ODM/PHPCR/Event/PostFlushEventArgs.php | 51 ------------------- .../ODM/PHPCR/Event/PreFlushEventArgs.php | 46 ----------------- lib/Doctrine/ODM/PHPCR/UnitOfWork.php | 12 ++--- ...tArgsTest.php => ManagerEventArgsTest.php} | 12 +++-- .../ODM/PHPCR/Event/PreFlushEventArgsTest.php | 21 -------- .../ODM/PHPCR/Functional/EventManagerTest.php | 7 ++- 10 files changed, 44 insertions(+), 223 deletions(-) delete mode 100644 lib/Doctrine/ODM/PHPCR/Event/OnClearEventArgs.php delete mode 100644 lib/Doctrine/ODM/PHPCR/Event/OnFlushEventArgs.php delete mode 100644 lib/Doctrine/ODM/PHPCR/Event/PostFlushEventArgs.php delete mode 100644 lib/Doctrine/ODM/PHPCR/Event/PreFlushEventArgs.php rename tests/Doctrine/Tests/ODM/PHPCR/Event/{PostFlushEventArgsTest.php => ManagerEventArgsTest.php} (51%) delete mode 100644 tests/Doctrine/Tests/ODM/PHPCR/Event/PreFlushEventArgsTest.php diff --git a/lib/Doctrine/ODM/PHPCR/Event/LifecycleEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/LifecycleEventArgs.php index dbe95af51..512fbad1d 100644 --- a/lib/Doctrine/ODM/PHPCR/Event/LifecycleEventArgs.php +++ b/lib/Doctrine/ODM/PHPCR/Event/LifecycleEventArgs.php @@ -49,4 +49,20 @@ public function getDocumentManager() { return $this->dm; } + + /** + * @return object + */ + public function getObject() + { + return $this->object; + } + + /** + * @return \Doctrine\ODM\PHPCR\DocumentManager + */ + public function getObjectManager() + { + return $this->dm; + } } diff --git a/lib/Doctrine/ODM/PHPCR/Event/LoadClassMetadataEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/LoadClassMetadataEventArgs.php index a49808acb..c598fbfcb 100644 --- a/lib/Doctrine/ODM/PHPCR/Event/LoadClassMetadataEventArgs.php +++ b/lib/Doctrine/ODM/PHPCR/Event/LoadClassMetadataEventArgs.php @@ -66,4 +66,14 @@ public function getDocumentManager() { return $this->dm; } + + /** + * Retrieve associated ObjectManager. + * + * @return \Doctrine\PHPCR\ODM\ObjectManager + */ + public function getObjectManager() + { + return $this->dm; + } } diff --git a/lib/Doctrine/ODM/PHPCR/Event/OnClearEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/OnClearEventArgs.php deleted file mode 100644 index 7183594a9..000000000 --- a/lib/Doctrine/ODM/PHPCR/Event/OnClearEventArgs.php +++ /dev/null @@ -1,46 +0,0 @@ -. -*/ - -namespace Doctrine\ODM\PHPCR\Event; - -use Doctrine\Common\EventArgs; - -class OnClearEventArgs extends EventArgs -{ - /** - * @var \Doctrine\ODM\PHPCR\DocumentManager - */ - private $dm; - - /** - * @param \Doctrine\ODM\PHPCR\DocumentManager $dm - */ - public function __construct($dm) - { - $this->dm = $dm; - } - - /** - * @return \Doctrine\ODM\PHPCR\DocumentManager - */ - public function getDocumentManager() - { - return $this->dm; - } -} diff --git a/lib/Doctrine/ODM/PHPCR/Event/OnFlushEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/OnFlushEventArgs.php deleted file mode 100644 index 3a7d03b9d..000000000 --- a/lib/Doctrine/ODM/PHPCR/Event/OnFlushEventArgs.php +++ /dev/null @@ -1,46 +0,0 @@ -. - */ - -namespace Doctrine\ODM\PHPCR\Event; - -use Doctrine\Common\EventArgs; - -class OnFlushEventArgs extends EventArgs -{ - /** - * @var \Doctrine\ODM\PHPCR\DocumentManager - */ - private $dm; - - /** - * @param \Doctrine\ODM\PHPCR\DocumentManager $dm - */ - public function __construct($dm) - { - $this->dm = $dm; - } - - /** - * @return \Doctrine\ODM\PHPCR\DocumentManager - */ - public function getDocumentManager() - { - return $this->dm; - } -} diff --git a/lib/Doctrine/ODM/PHPCR/Event/PostFlushEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/PostFlushEventArgs.php deleted file mode 100644 index 604fccf4c..000000000 --- a/lib/Doctrine/ODM/PHPCR/Event/PostFlushEventArgs.php +++ /dev/null @@ -1,51 +0,0 @@ -. - */ - -namespace Doctrine\ODM\PHPCR\Event; - -use Doctrine\Common\EventArgs; -use Doctrine\ODM\PHPCR\DocumentManager; - -class PostFlushEventArgs extends EventArgs -{ - /** - * @var \Doctrine\ODM\PHPCR\DocumentManager - */ - private $dm; - - /** - * Constructor. - * - * @param \Doctrine\ODM\PHPCR\DocumentManager $em - */ - public function __construct(DocumentManager $dm) - { - $this->dm = $dm; - } - - /** - * Retrieve associated DocumentManager. - * - * @return \Doctrine\ODM\PHPCR\DocumentManager - */ - public function getDocumentManager() - { - return $this->dm; - } -} diff --git a/lib/Doctrine/ODM/PHPCR/Event/PreFlushEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/PreFlushEventArgs.php deleted file mode 100644 index f2ba5e489..000000000 --- a/lib/Doctrine/ODM/PHPCR/Event/PreFlushEventArgs.php +++ /dev/null @@ -1,46 +0,0 @@ -. - */ - -namespace Doctrine\ODM\PHPCR\Event; - -use Doctrine\Common\EventArgs; - -class PreFlushEventArgs extends EventArgs -{ - /** - * @var \Doctrine\ODM\PHPCR\DocumentManager - */ - private $dm; - - /** - * @param \Doctrine\ODM\PHPCR\DocumentManager $dm - */ - public function __construct($dm) - { - $this->dm = $dm; - } - - /** - * @return \Doctrine\ODM\PHPCR\DocumentManager - */ - public function getDocumentManager() - { - return $this->dm; - } -} diff --git a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php index c03f765ad..1d2184c82 100644 --- a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php +++ b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php @@ -27,11 +27,10 @@ use Doctrine\ODM\PHPCR\Exception\MissingTranslationException; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\ODM\PHPCR\Event\LifecycleEventArgs; use Doctrine\ODM\PHPCR\Event\OnFlushEventArgs; +use Doctrine\ODM\PHPCR\Event\LifecycleEventArgs; use Doctrine\ODM\PHPCR\Event\PreFlushEventArgs; use Doctrine\ODM\PHPCR\Event\PostFlushEventArgs; -use Doctrine\ODM\PHPCR\Event\OnClearEventArgs; use Doctrine\ODM\PHPCR\Event\MoveEventArgs; use Doctrine\ODM\PHPCR\Proxy\Proxy; @@ -45,6 +44,7 @@ use PHPCR\UnsupportedRepositoryOperationException; use PHPCR\RepositoryException; use PHPCR\Util\UUIDHelper; +use Doctrine\ODM\PHPCR\Event\ManagerEventArgs; /** * Unit of work class @@ -1615,7 +1615,7 @@ public function commit($document = null) { // Raise preFlush if ($this->evm->hasListeners(Event::preFlush)) { - $this->evm->dispatchEvent(Event::preFlush, new PreFlushEventArgs($this->dm)); + $this->evm->dispatchEvent(Event::preFlush, new ManagerEventArgs($this->dm)); } if ($document === null) { @@ -1629,7 +1629,7 @@ public function commit($document = null) } if ($this->evm->hasListeners(Event::onFlush)) { - $this->evm->dispatchEvent(Event::onFlush, new OnFlushEventArgs($this->dm)); + $this->evm->dispatchEvent(Event::onFlush, new ManagerEventArgs($this->dm)); } try { @@ -1680,7 +1680,7 @@ public function commit($document = null) // Raise postFlush if ($this->evm->hasListeners(Event::postFlush)) { - $this->evm->dispatchEvent(Event::postFlush, new PostFlushEventArgs($this->dm)); + $this->evm->dispatchEvent(Event::postFlush, new ManagerEventArgs($this->dm)); } $this->documentTranslations = @@ -2507,7 +2507,7 @@ public function clear() $this->documentVersion = array(); if ($this->evm->hasListeners(Event::onClear)) { - $this->evm->dispatchEvent(Event::onClear, new OnClearEventArgs($this->dm)); + $this->evm->dispatchEvent(Event::onClear, new ManagerEventArgs($this->dm)); } $this->session->refresh(false); diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Event/PostFlushEventArgsTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Event/ManagerEventArgsTest.php similarity index 51% rename from tests/Doctrine/Tests/ODM/PHPCR/Event/PostFlushEventArgsTest.php rename to tests/Doctrine/Tests/ODM/PHPCR/Event/ManagerEventArgsTest.php index 973220bb2..f83131030 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Event/PostFlushEventArgsTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Event/ManagerEventArgsTest.php @@ -1,16 +1,16 @@ dm = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager') ->disableOriginalConstructor() ->getMock(); - $this->postFlushEventArgs = new PostFlushEventArgs($this->dm); + $this->postFlushEventArgs = new ManagerEventArgs($this->dm); } public function testGetDocumentManager() @@ -18,4 +18,10 @@ public function testGetDocumentManager() $res = $this->postFlushEventArgs->getDocumentManager(); $this->assertSame($this->dm, $res); } + + public function testGetObjectManager() + { + $res = $this->postFlushEventArgs->getObjectManager(); + $this->assertSame($this->dm, $res); + } } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Event/PreFlushEventArgsTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Event/PreFlushEventArgsTest.php deleted file mode 100644 index 84d513e45..000000000 --- a/tests/Doctrine/Tests/ODM/PHPCR/Event/PreFlushEventArgsTest.php +++ /dev/null @@ -1,21 +0,0 @@ -dm = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager') - ->disableOriginalConstructor() - ->getMock(); - $this->preFlushEventArgs = new PreFlushEventArgs($this->dm); - } - - public function testGetDocumentManager() - { - $res = $this->preFlushEventArgs->getDocumentManager(); - $this->assertSame($this->dm, $res); - } -} diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php index 7bd0268c5..4e27bd9b0 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php @@ -7,8 +7,7 @@ use Doctrine\Tests\ODM\PHPCR\PHPCRFunctionalTestCase; use Doctrine\Tests\Models\CMS\CmsPage; use Doctrine\Tests\Models\CMS\CmsItem; -use Doctrine\ODM\PHPCR\Event\PostFlushEventArgs; -use Doctrine\ODM\PHPCR\Event\PreFlushEventArgs; +use Doctrine\ODM\PHPCR\Event\ManagerEventArgs; class EventManagerTest extends PHPCRFunctionalTestCase { @@ -213,12 +212,12 @@ public function onFlush(EventArgs $e) $this->onFlush = true; } - public function postFlush(PostFlushEventArgs $e) + public function postFlush(ManagerEventArgs $e) { $this->postFlush = true; } - public function preFlush(PreFlushEventArgs $e) + public function preFlush(ManagerEventArgs $e) { $this->preFlush = true; } From ba27e253af05234875051de8842b275373aade5d Mon Sep 17 00:00:00 2001 From: dantleech Date: Fri, 1 Mar 2013 14:11:56 +0000 Subject: [PATCH 2/3] Updated Events to extend commons --- .../ODM/PHPCR/Event/LifecycleEventArgs.php | 43 ++++----------- .../Event/LoadClassMetadataEventArgs.php | 53 ++----------------- .../ODM/PHPCR/Event/ManagerEventArgs.php | 35 ++++++++++++ .../ODM/PHPCR/Event/MoveEventArgs.php | 36 ++++--------- lib/Doctrine/ODM/PHPCR/UnitOfWork.php | 2 +- .../PHPCR/Event/LifecycleEventArgsTest.php | 32 +++++++++++ .../Event/LoadClassMetadataEventTest.php | 1 - .../ODM/PHPCR/Event/ManagerEventArgsTest.php | 1 - .../ODM/PHPCR/Event/MoveEventArgsTest.php | 46 ++++++++++++++++ 9 files changed, 139 insertions(+), 110 deletions(-) create mode 100644 lib/Doctrine/ODM/PHPCR/Event/ManagerEventArgs.php create mode 100644 tests/Doctrine/Tests/ODM/PHPCR/Event/LifecycleEventArgsTest.php create mode 100644 tests/Doctrine/Tests/ODM/PHPCR/Event/MoveEventArgsTest.php diff --git a/lib/Doctrine/ODM/PHPCR/Event/LifecycleEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/LifecycleEventArgs.php index 512fbad1d..5b6b4f100 100644 --- a/lib/Doctrine/ODM/PHPCR/Event/LifecycleEventArgs.php +++ b/lib/Doctrine/ODM/PHPCR/Event/LifecycleEventArgs.php @@ -19,50 +19,25 @@ namespace Doctrine\ODM\PHPCR\Event; -class LifecycleEventArgs extends \Doctrine\Common\EventArgs -{ - private $document; - - /** - * @var \Doctrine\ODM\PHPCR\DocumentManager - */ - private $dm; - - public function __construct($document, $dm) - { - $this->document = $document; - $this->dm = $dm; - } +use Doctrine\Common\Persistence\Event\LifecycleEventArgs as BaseLifecycleEventArgs; +class LifecycleEventArgs extends BaseLifecycleEventArgs +{ /** - * @return object + * @deprecated Will be dropped in favor of getObject in 1.0 + * @return object */ public function getDocument() { - return $this->document; + return $this->getEntity(); } /** - * @return \Doctrine\ODM\PHPCR\DocumentManager + * @deprecated Will be dropped in favor of getObjectManager in 1.0 + * @return \Doctrine\ODM\PHPCR\DocumentManager */ public function getDocumentManager() { - return $this->dm; - } - - /** - * @return object - */ - public function getObject() - { - return $this->object; - } - - /** - * @return \Doctrine\ODM\PHPCR\DocumentManager - */ - public function getObjectManager() - { - return $this->dm; + return $this->getObjectManager(); } } diff --git a/lib/Doctrine/ODM/PHPCR/Event/LoadClassMetadataEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/LoadClassMetadataEventArgs.php index c598fbfcb..9ca48d561 100644 --- a/lib/Doctrine/ODM/PHPCR/Event/LoadClassMetadataEventArgs.php +++ b/lib/Doctrine/ODM/PHPCR/Event/LoadClassMetadataEventArgs.php @@ -19,61 +19,18 @@ namespace Doctrine\ODM\PHPCR\Event; -use Doctrine\Common\EventArgs; +use Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs as BaseLoadClassMetadataEventArgs; use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; use Doctrine\ODM\PHPCR\DocumentManager; -class LoadClassMetadataEventArgs extends EventArgs +class LoadClassMetadataEventArgs extends BaseLoadClassMetadataEventArgs { /** - * @var \Doctrine\PHPCR\ODM\Mapping\ClassMetadata - */ - private $classMetadata; - - /** - * @var \Doctrine\PHPCR\ODM\DocumentManager - */ - private $dm; - - /** - * Constructor. - * - * @param \Doctrine\PHPCR\ODM\Mapping\ClassMetadataInfo $classMetadata - * @param \Doctrine\PHPCR\ODM\DocumentManager $dm - */ - public function __construct(ClassMetadata $classMetadata, DocumentManager $dm) - { - $this->classMetadata = $classMetadata; - $this->dm = $dm; - } - - /** - * Retrieve associated ClassMetadata. - * - * @return \Doctrine\PHPCR\ODM\Mapping\ClassMetadataInfo - */ - public function getClassMetadata() - { - return $this->classMetadata; - } - - /** - * Retrieve associated DocumentManager. - * - * @return \Doctrine\PHPCR\ODM\DocumentManager + * @deprecated Will be dropped in favor of getObjectManager in 1.0 + * @return \Doctrine\ODM\PHPCR\DocumentManager */ public function getDocumentManager() { - return $this->dm; - } - - /** - * Retrieve associated ObjectManager. - * - * @return \Doctrine\PHPCR\ODM\ObjectManager - */ - public function getObjectManager() - { - return $this->dm; + return $this->getObjectManager(); } } diff --git a/lib/Doctrine/ODM/PHPCR/Event/ManagerEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/ManagerEventArgs.php new file mode 100644 index 000000000..68215884a --- /dev/null +++ b/lib/Doctrine/ODM/PHPCR/Event/ManagerEventArgs.php @@ -0,0 +1,35 @@ +. +*/ + +namespace Doctrine\ODM\PHPCR\Event; + +use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Common\Persistence\Event\ManagerEventArgs as BaseManagerEventArgs; + +class ManagerEventArgs extends BaseManagerEventArgs +{ + /** + * @deprecated Will be dropped in favor of getObjectManager in 1.0 + * @return \Doctrine\ODM\PHPCR\DocumentManager + */ + public function getDocumentManager() + { + return $this->getObjectManager(); + } +} diff --git a/lib/Doctrine/ODM/PHPCR/Event/MoveEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/MoveEventArgs.php index b09d632f5..ac7723d97 100644 --- a/lib/Doctrine/ODM/PHPCR/Event/MoveEventArgs.php +++ b/lib/Doctrine/ODM/PHPCR/Event/MoveEventArgs.php @@ -20,21 +20,10 @@ namespace Doctrine\ODM\PHPCR\Event; -/** - * MoveEventArgs - */ -class MoveEventArgs extends \Doctrine\Common\EventArgs -{ - /** - * @var object - */ - private $document; - - /** - * @var \Doctrine\ODM\PHPCR\DocumentManager - */ - private $dm; +use Doctrine\Common\Persistence\ObjectManager; +class MoveEventArgs extends LifecycleEventArgs +{ /** * @var string */ @@ -53,32 +42,29 @@ class MoveEventArgs extends \Doctrine\Common\EventArgs * @param string $sourcePath The source path * @param string $targetPath The target path */ - public function __construct($document, $dm, $sourcePath, $targetPath) + public function __construct($document, ObjectManager $om, $sourcePath, $targetPath) { - $this->document = $document; - $this->dm = $dm; + parent::__construct($document, $om); $this->sourcePath = $sourcePath; $this->targetPath = $targetPath; } /** - * Get the document - * - * @return object + * @deprecated Will be dropped in favor of getObject in 1.0 + * @return object */ public function getDocument() { - return $this->document; + return $this->getEntity(); } /** - * Get the document manager - * - * @return \Doctrine\ODM\PHPCR\DocumentManager + * @deprecated Will be dropped in favor of getObjectManager in 1.0 + * @return \Doctrine\ODM\PHPCR\DocumentManager */ public function getDocumentManager() { - return $this->dm; + return $this->getObjectManager(); } /** diff --git a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php index 1d2184c82..c06288fd8 100644 --- a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php +++ b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php @@ -32,6 +32,7 @@ use Doctrine\ODM\PHPCR\Event\PreFlushEventArgs; use Doctrine\ODM\PHPCR\Event\PostFlushEventArgs; use Doctrine\ODM\PHPCR\Event\MoveEventArgs; +use Doctrine\ODM\PHPCR\Event\ManagerEventArgs; use Doctrine\ODM\PHPCR\Proxy\Proxy; use Jackalope\Session as JackalopeSession; @@ -44,7 +45,6 @@ use PHPCR\UnsupportedRepositoryOperationException; use PHPCR\RepositoryException; use PHPCR\Util\UUIDHelper; -use Doctrine\ODM\PHPCR\Event\ManagerEventArgs; /** * Unit of work class diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Event/LifecycleEventArgsTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Event/LifecycleEventArgsTest.php new file mode 100644 index 000000000..5ba9f5aa1 --- /dev/null +++ b/tests/Doctrine/Tests/ODM/PHPCR/Event/LifecycleEventArgsTest.php @@ -0,0 +1,32 @@ +dm = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager') + ->disableOriginalConstructor() + ->getMock(); + $this->object = new \stdClass; + + $this->eventArgs = new LifecycleEventArgs( + $this->object, + $this->dm + ); + } + + public function testGetDocumentManager() + { + $res = $this->eventArgs->getDocumentManager(); + $this->assertSame($this->dm, $res); + } + + public function testGetDocument() + { + $res = $this->eventArgs->getDocument(); + $this->assertSame($this->object, $res); + } +} + diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Event/LoadClassMetadataEventTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Event/LoadClassMetadataEventTest.php index b51ec8a19..8ff2ab651 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Event/LoadClassMetadataEventTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Event/LoadClassMetadataEventTest.php @@ -2,7 +2,6 @@ use Doctrine\ODM\PHPCR\Event\LoadClassMetadataEventArgs; - class LoadClassMetadataEventArgsTest extends \PHPUnit_Framework_TestCase { public function setUp() diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Event/ManagerEventArgsTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Event/ManagerEventArgsTest.php index f83131030..24aee532b 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Event/ManagerEventArgsTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Event/ManagerEventArgsTest.php @@ -2,7 +2,6 @@ use Doctrine\ODM\PHPCR\Event\ManagerEventArgs; - class ManagerEventArgsTest extends \PHPUnit_Framework_TestCase { public function setUp() diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Event/MoveEventArgsTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Event/MoveEventArgsTest.php new file mode 100644 index 000000000..0b65bb15a --- /dev/null +++ b/tests/Doctrine/Tests/ODM/PHPCR/Event/MoveEventArgsTest.php @@ -0,0 +1,46 @@ +dm = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager') + ->disableOriginalConstructor() + ->getMock(); + $this->object = new \stdClass; + + $this->eventArgs = new MoveEventArgs( + $this->object, + $this->dm, + 'source/path', + 'target/path' + ); + } + + public function testGetDocumentManager() + { + $res = $this->eventArgs->getDocumentManager(); + $this->assertSame($this->dm, $res); + } + + public function testGetDocument() + { + $res = $this->eventArgs->getDocument(); + $this->assertSame($this->object, $res); + } + + public function testGetSourcePath() + { + $path = $this->eventArgs->getSourcePath(); + $this->assertEquals('source/path', $path); + } + + public function testGetTargetPath() + { + $path = $this->eventArgs->getTargetPath(); + $this->assertEquals('target/path', $path); + } +} + From 551ee1a63955a923ed776246dfcf2b79a13cafce Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 26 May 2013 20:45:31 +0200 Subject: [PATCH 3/3] trigger deprecation errors, adjust tests and add TODO comments --- CHANGELOG.md | 14 +++++++ .../ODM/PHPCR/Event/LifecycleEventArgs.php | 9 ++++- .../Event/LoadClassMetadataEventArgs.php | 7 +++- .../ODM/PHPCR/Event/ManagerEventArgs.php | 5 ++- .../ODM/PHPCR/Event/MoveEventArgs.php | 38 ++++++------------ lib/Doctrine/ODM/PHPCR/UnitOfWork.php | 6 ++- .../PHPCR/Event/LifecycleEventArgsTest.php | 32 --------------- .../Event/LoadClassMetadataEventTest.php | 33 ---------------- .../ODM/PHPCR/Event/ManagerEventArgsTest.php | 26 ------------- .../ODM/PHPCR/Event/MoveEventArgsTest.php | 13 +++++-- .../PHPCR/Functional/EventComputingTest.php | 25 ++++++------ .../ODM/PHPCR/Functional/EventManagerTest.php | 39 ++++++++++--------- .../Mapping/ClassMetadataFactoryTest.php | 13 +++++-- 13 files changed, 99 insertions(+), 161 deletions(-) delete mode 100644 tests/Doctrine/Tests/ODM/PHPCR/Event/LifecycleEventArgsTest.php delete mode 100644 tests/Doctrine/Tests/ODM/PHPCR/Event/LoadClassMetadataEventTest.php delete mode 100644 tests/Doctrine/Tests/ODM/PHPCR/Event/ManagerEventArgsTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f0a3b0cc..372bd5995 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,20 @@ Changelog ========= +2013-05-27 +---------- + + * #288: Event refactoring to use doctrine commons 2.4 events where possible + Use the doctrine common event argument classes where possible instead of + custom classes. The classes `Doctrine\ODM\PHPCR\Event\LifecycleEventArgs` + and `Doctrine\ODM\PHPCR\Event\ManagerEventArgs` and + `Doctrine\ODM\PHPCR\Event\LoadClassMetadataEventArgs` are deprecated and + will be deleted soon. Switch your code to depend on the classes in namespace + `Doctrine\Common\Persistence\Event\` instead. + The only PHPCR-ODM specific event argument that will remain is MoveEventArgs + because it has additional parameters and the move operation is PHPCR-ODM + specific. + 2013-05-13 ---------- diff --git a/lib/Doctrine/ODM/PHPCR/Event/LifecycleEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/LifecycleEventArgs.php index 5b6b4f100..a9b93a9e3 100644 --- a/lib/Doctrine/ODM/PHPCR/Event/LifecycleEventArgs.php +++ b/lib/Doctrine/ODM/PHPCR/Event/LifecycleEventArgs.php @@ -21,23 +21,30 @@ use Doctrine\Common\Persistence\Event\LifecycleEventArgs as BaseLifecycleEventArgs; +/** + * @deprecated Will be dropped in favor of Doctrine\Common\Persistence\Event\LifecycleEventArgs + */ class LifecycleEventArgs extends BaseLifecycleEventArgs { /** * @deprecated Will be dropped in favor of getObject in 1.0 + * * @return object */ public function getDocument() { - return $this->getEntity(); + trigger_error('The getDocument method is deprecated, use getObject instead', E_USER_DEPRECATED); + return $this->getObject(); } /** * @deprecated Will be dropped in favor of getObjectManager in 1.0 + * * @return \Doctrine\ODM\PHPCR\DocumentManager */ public function getDocumentManager() { + trigger_error('The getDocumentManager method is deprecated, use getObjectManager instead', E_USER_DEPRECATED); return $this->getObjectManager(); } } diff --git a/lib/Doctrine/ODM/PHPCR/Event/LoadClassMetadataEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/LoadClassMetadataEventArgs.php index 9ca48d561..7ef790a87 100644 --- a/lib/Doctrine/ODM/PHPCR/Event/LoadClassMetadataEventArgs.php +++ b/lib/Doctrine/ODM/PHPCR/Event/LoadClassMetadataEventArgs.php @@ -20,17 +20,20 @@ namespace Doctrine\ODM\PHPCR\Event; use Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs as BaseLoadClassMetadataEventArgs; -use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; -use Doctrine\ODM\PHPCR\DocumentManager; +/** + * @deprecated Will be dropped in favor of Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs + */ class LoadClassMetadataEventArgs extends BaseLoadClassMetadataEventArgs { /** * @deprecated Will be dropped in favor of getObjectManager in 1.0 + * * @return \Doctrine\ODM\PHPCR\DocumentManager */ public function getDocumentManager() { + trigger_error('The getDocumentManager method is deprecated, use getObjectManager instead', E_USER_DEPRECATED); return $this->getObjectManager(); } } diff --git a/lib/Doctrine/ODM/PHPCR/Event/ManagerEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/ManagerEventArgs.php index 68215884a..ef0c582ca 100644 --- a/lib/Doctrine/ODM/PHPCR/Event/ManagerEventArgs.php +++ b/lib/Doctrine/ODM/PHPCR/Event/ManagerEventArgs.php @@ -19,9 +19,11 @@ namespace Doctrine\ODM\PHPCR\Event; -use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\Event\ManagerEventArgs as BaseManagerEventArgs; +/** + * @deprecated Will be dropped in favor of Doctrine\Common\Persistence\Event\ManagerEventArgs + */ class ManagerEventArgs extends BaseManagerEventArgs { /** @@ -30,6 +32,7 @@ class ManagerEventArgs extends BaseManagerEventArgs */ public function getDocumentManager() { + trigger_error('The getDocumentManager method is deprecated, use getObjectManager instead', E_USER_DEPRECATED); return $this->getObjectManager(); } } diff --git a/lib/Doctrine/ODM/PHPCR/Event/MoveEventArgs.php b/lib/Doctrine/ODM/PHPCR/Event/MoveEventArgs.php index ac7723d97..906c6f975 100644 --- a/lib/Doctrine/ODM/PHPCR/Event/MoveEventArgs.php +++ b/lib/Doctrine/ODM/PHPCR/Event/MoveEventArgs.php @@ -20,7 +20,7 @@ namespace Doctrine\ODM\PHPCR\Event; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\ODM\PHPCR\DocumentManager; class MoveEventArgs extends LifecycleEventArgs { @@ -37,38 +37,21 @@ class MoveEventArgs extends LifecycleEventArgs /** * Constructor * - * @param object $document The object - * @param \Doctrine\ODM\PHPCR\DocumentManager $dm The document manager - * @param string $sourcePath The source path - * @param string $targetPath The target path + * @param object $document + * @param DocumentManager $dm + * @param string $sourcePath Path the document is moved from + * @param string $targetPath Path the document is moved to, including target name */ - public function __construct($document, ObjectManager $om, $sourcePath, $targetPath) + public function __construct($document, DocumentManager $dm, $sourcePath, $targetPath) { - parent::__construct($document, $om); + parent::__construct($document, $dm); $this->sourcePath = $sourcePath; $this->targetPath = $targetPath; } /** - * @deprecated Will be dropped in favor of getObject in 1.0 - * @return object - */ - public function getDocument() - { - return $this->getEntity(); - } - - /** - * @deprecated Will be dropped in favor of getObjectManager in 1.0 - * @return \Doctrine\ODM\PHPCR\DocumentManager - */ - public function getDocumentManager() - { - return $this->getObjectManager(); - } - - /** - * Get the source path + * Get the path this document is being moved away from, including the + * document name. * * @return string */ @@ -78,7 +61,8 @@ public function getSourcePath() } /** - * Get the target path + * Get the path this document is being moved to, including the new document + * name. * * @return string */ diff --git a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php index 4c55f1850..1f6d1253b 100644 --- a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php +++ b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php @@ -27,8 +27,10 @@ use Doctrine\ODM\PHPCR\Mapping\MappingException; use Doctrine\ODM\PHPCR\Id\IdGenerator; use Doctrine\ODM\PHPCR\Id\IdException; -use Doctrine\ODM\PHPCR\Event\LifecycleEventArgs; use Doctrine\ODM\PHPCR\Event\MoveEventArgs; +// TODO use Doctrine\Common\Persistence\Event\LifecycleEventArgs instead for the next version +use Doctrine\ODM\PHPCR\Event\LifecycleEventArgs; +// TODO use Doctrine\Common\Persistence\Event\ManagerEventArgs instead for the next version use Doctrine\ODM\PHPCR\Event\ManagerEventArgs; use Doctrine\ODM\PHPCR\Exception\CascadeException; use Doctrine\ODM\PHPCR\Exception\MissingTranslationException; @@ -459,7 +461,7 @@ public function getOrCreateDocument($className, NodeInterface $node, array &$hin $class->invokeLifecycleCallbacks(Event::postLoad, $document); } if ($this->evm->hasListeners(Event::postLoad)) { - $this->evm->dispatchEvent(Event::postLoad, new Event\LifecycleEventArgs($document, $this->dm)); + $this->evm->dispatchEvent(Event::postLoad, new LifecycleEventArgs($document, $this->dm)); } return $document; diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Event/LifecycleEventArgsTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Event/LifecycleEventArgsTest.php deleted file mode 100644 index 5ba9f5aa1..000000000 --- a/tests/Doctrine/Tests/ODM/PHPCR/Event/LifecycleEventArgsTest.php +++ /dev/null @@ -1,32 +0,0 @@ -dm = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager') - ->disableOriginalConstructor() - ->getMock(); - $this->object = new \stdClass; - - $this->eventArgs = new LifecycleEventArgs( - $this->object, - $this->dm - ); - } - - public function testGetDocumentManager() - { - $res = $this->eventArgs->getDocumentManager(); - $this->assertSame($this->dm, $res); - } - - public function testGetDocument() - { - $res = $this->eventArgs->getDocument(); - $this->assertSame($this->object, $res); - } -} - diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Event/LoadClassMetadataEventTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Event/LoadClassMetadataEventTest.php deleted file mode 100644 index 8ff2ab651..000000000 --- a/tests/Doctrine/Tests/ODM/PHPCR/Event/LoadClassMetadataEventTest.php +++ /dev/null @@ -1,33 +0,0 @@ -dm = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager') - ->disableOriginalConstructor() - ->getMock(); - $this->classMeta = $this->getMockBuilder('Doctrine\ODM\PHPCR\Mapping\ClassMetadata') - ->disableOriginalConstructor() - ->getMock(); - $this->loadClassMetadataEventArgs = new LoadClassMetadataEventArgs( - $this->classMeta, - $this->dm - ); - } - - public function testGetDocumentManager() - { - $res = $this->loadClassMetadataEventArgs->getDocumentManager(); - $this->assertSame($this->dm, $res); - } - - public function testGetClassMetadata() - { - $res = $this->loadClassMetadataEventArgs->getClassMetadata(); - $this->assertSame($this->classMeta, $res); - } -} - diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Event/ManagerEventArgsTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Event/ManagerEventArgsTest.php deleted file mode 100644 index 24aee532b..000000000 --- a/tests/Doctrine/Tests/ODM/PHPCR/Event/ManagerEventArgsTest.php +++ /dev/null @@ -1,26 +0,0 @@ -dm = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager') - ->disableOriginalConstructor() - ->getMock(); - $this->postFlushEventArgs = new ManagerEventArgs($this->dm); - } - - public function testGetDocumentManager() - { - $res = $this->postFlushEventArgs->getDocumentManager(); - $this->assertSame($this->dm, $res); - } - - public function testGetObjectManager() - { - $res = $this->postFlushEventArgs->getObjectManager(); - $this->assertSame($this->dm, $res); - } -} diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Event/MoveEventArgsTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Event/MoveEventArgsTest.php index 0b65bb15a..2515bf7a2 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Event/MoveEventArgsTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Event/MoveEventArgsTest.php @@ -4,6 +4,13 @@ class MoveEventArgsTest extends \PHPUnit_Framework_TestCase { + private $object; + + private $dm; + + /** @var MoveEventArgs */ + private $eventArgs; + public function setUp() { $this->dm = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager') @@ -21,13 +28,13 @@ public function setUp() public function testGetDocumentManager() { - $res = $this->eventArgs->getDocumentManager(); + $res = $this->eventArgs->getObjectManager(); $this->assertSame($this->dm, $res); } public function testGetDocument() { - $res = $this->eventArgs->getDocument(); + $res = $this->eventArgs->getObject(); $this->assertSame($this->object, $res); } @@ -36,7 +43,7 @@ public function testGetSourcePath() $path = $this->eventArgs->getSourcePath(); $this->assertEquals('source/path', $path); } - + public function testGetTargetPath() { $path = $this->eventArgs->getTargetPath(); diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventComputingTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventComputingTest.php index 2b1adeb06..5c9d99be7 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventComputingTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventComputingTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ODM\PHPCR\Functional; use Doctrine\Common\EventArgs; +use Doctrine\Common\Persistence\Event\LifecycleEventArgs; class EventComputingTest extends \Doctrine\Tests\ODM\PHPCR\PHPCRFunctionalTestCase { @@ -96,41 +97,41 @@ class TestEventDocumentChanger public $postMove = false; public $onFlush = false; - public function prePersist(EventArgs $e) + public function prePersist(LifecycleEventArgs $e) { - $document = $e->getDocument(); + $document = $e->getObject(); $document->name = 'prepersist'; } - public function postPersist(EventArgs $e) + public function postPersist(LifecycleEventArgs $e) { - $document = $e->getDocument(); + $document = $e->getObject(); $document->username = 'postpersist'; } - public function preUpdate(EventArgs $e) + public function preUpdate(LifecycleEventArgs $e) { - $document = $e->getDocument(); + $document = $e->getObject(); $document->name = 'preupdate'; } - public function postUpdate(EventArgs $e) + public function postUpdate(LifecycleEventArgs $e) { - $document = $e->getDocument(); + $document = $e->getObject(); $document->username = 'postupdate'; } - public function preMove(EventArgs $e) + public function preMove(LifecycleEventArgs $e) { $this->preMove = true; - $document = $e->getDocument(); + $document = $e->getObject(); $document->name = 'premove'; // I try to update the name of the document but after move, the document should never be modified $document->username = 'premove'; } - public function postMove(EventArgs $e) + public function postMove(LifecycleEventArgs $e) { - $document = $e->getDocument(); + $document = $e->getObject(); $document->username .= '-postmove'; } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php index a1089baa1..8b8d3b779 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php @@ -2,12 +2,13 @@ namespace Doctrine\Tests\ODM\PHPCR\Functional; -use Doctrine\Common\EventArgs; +use Doctrine\Common\Persistence\Event\LifecycleEventArgs; +use Doctrine\Common\Persistence\Event\ManagerEventArgs; +use Doctrine\ODM\PHPCR\Event\MoveEventArgs; use Doctrine\Tests\ODM\PHPCR\PHPCRFunctionalTestCase; use Doctrine\Tests\Models\CMS\CmsPage; use Doctrine\Tests\Models\CMS\CmsItem; -use Doctrine\ODM\PHPCR\Event\ManagerEventArgs; class EventManagerTest extends PHPCRFunctionalTestCase { @@ -129,9 +130,9 @@ class TestPersistenceListener public $pagePreMove = false; public $pagePostMove = false; - public function prePersist(EventArgs $e) + public function prePersist(LifecycleEventArgs $e) { - $document = $e->getDocument(); + $document = $e->getObject(); if ($document instanceof CmsPage){ $this->pagePrePersist = true; } elseif ($document instanceof CmsItem){ @@ -139,9 +140,9 @@ public function prePersist(EventArgs $e) } } - public function postPersist(EventArgs $e) + public function postPersist(LifecycleEventArgs $e) { - $document = $e->getDocument(); + $document = $e->getObject(); if ($document instanceof CmsPage){ $this->pagePostPersist = true; } elseif ($document instanceof CmsItem){ @@ -149,13 +150,13 @@ public function postPersist(EventArgs $e) } } - public function preUpdate(EventArgs $e) + public function preUpdate(LifecycleEventArgs $e) { - $document = $e->getDocument(); + $document = $e->getObject(); if (! $document instanceof CmsPage ){ return; } - $dm = $e->getDocumentManager(); + $dm = $e->getObjectManager(); foreach ($document->getItems() as $item) { $dm->persist($item); @@ -163,14 +164,14 @@ public function preUpdate(EventArgs $e) $this->preUpdate = true; } - public function postUpdate(EventArgs $e) + public function postUpdate(LifecycleEventArgs $e) { $this->postUpdate = true; } - public function preRemove(EventArgs $e) + public function preRemove(LifecycleEventArgs $e) { - $document = $e->getDocument(); + $document = $e->getObject(); if ($document instanceof CmsPage){ $this->pagePreRemove = true; } elseif ($document instanceof CmsItem){ @@ -178,9 +179,9 @@ public function preRemove(EventArgs $e) } } - public function postRemove(EventArgs $e) + public function postRemove(LifecycleEventArgs $e) { - $document = $e->getDocument(); + $document = $e->getObject(); if ($document instanceof CmsPage){ $this->pagePostRemove = true; } elseif ($document instanceof CmsItem){ @@ -188,9 +189,9 @@ public function postRemove(EventArgs $e) } } - public function preMove(EventArgs $e) + public function preMove(MoveEventArgs $e) { - $document = $e->getDocument(); + $document = $e->getObject(); if ($document instanceof CmsPage){ $this->pagePreMove = true; } elseif ($document instanceof CmsItem){ @@ -198,9 +199,9 @@ public function preMove(EventArgs $e) } } - public function postMove(EventArgs $e) + public function postMove(LifecycleEventArgs $e) { - $document = $e->getDocument(); + $document = $e->getObject(); if ($document instanceof CmsPage){ $this->pagePostMove = true; } elseif ($document instanceof CmsItem){ @@ -208,7 +209,7 @@ public function postMove(EventArgs $e) } } - public function onFlush(EventArgs $e) + public function onFlush(ManagerEventArgs $e) { $this->onFlush = true; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/ClassMetadataFactoryTest.php index ec38f3816..10ffc8bba 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/ClassMetadataFactoryTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping; +use Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs; +use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; use Doctrine\ODM\PHPCR\Mapping\ClassMetadataFactory; use Doctrine\ODM\PHPCR\Event; @@ -12,6 +14,11 @@ class ClassMetadataFactoryTest extends \PHPUnit_Framework_TestCase */ private $dm; + /** + * @param $fqn + * + * @return ClassMetadata + */ protected function getMetadataFor($fqn) { $cache = new \Doctrine\Common\Cache\ArrayCache(); @@ -112,7 +119,7 @@ public function testLoadMetadataClassInheritanceChildCanOverride() } /** - * @expectedException Doctrine\ODM\PHPCR\Mapping\MappingException + * @expectedException \Doctrine\ODM\PHPCR\Mapping\MappingException */ public function testValidateTranslatableNoStrategy() { @@ -143,10 +150,10 @@ class Listener public $meta; public $called = false; - public function loadClassMetadata(\Doctrine\ODM\PHPCR\Event\LoadClassMetadataEventArgs $args) + public function loadClassMetadata(LoadClassMetadataEventArgs $args) { $this->called = true; - $this->dm = $args->getDocumentManager(); + $this->dm = $args->getObjectManager(); $this->meta = $args->getClassMetadata(); } }