123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
-
- namespace Gedmo\Tree;
-
- use Doctrine\Common\EventManager;
- use Tool\BaseTestCaseMongoODM;
- use Doctrine\Common\Util\Debug;
- use Tree\Fixture\RootCategory;
- use Tree\Fixture\Mock\TreeListenerMock;
-
-
- class MaterializedPathODMMongoDBTreeLockingTest extends BaseTestCaseMongoODM
- {
- const ARTICLE = "Tree\\Fixture\\Document\\Article";
-
- protected $config;
- protected $listener;
-
- protected function setUp()
- {
- parent::setUp();
-
- $this->listener = new TreeListenerMock;
-
- $evm = new EventManager;
- $evm->addEventSubscriber($this->listener);
-
- $this->getMockDocumentManager($evm);
-
- $meta = $this->dm->getClassMetadata(self::ARTICLE);
- $this->config = $this->listener->getConfiguration($this->dm, $meta->name);
- }
-
-
-
- public function modifyingANodeWhileItsTreeIsLockedShouldThrowAnException()
- {
-
-
- $this->setExpectedException('Gedmo\Exception\TreeLockingException');
-
- $article = $this->createArticle();
- $article->setTitle('1');
- $article2 = $this->createArticle();
- $article2->setTitle('2');
- $article2->setParent($article);
-
- $this->dm->persist($article);
- $this->dm->persist($article2);
- $this->dm->flush();
-
- $this->dm->refresh($article);
- $this->dm->refresh($article2);
-
- $article2->setTitle('New title');
- $this->dm->flush();
- }
-
-
-
- public function modifyingANodeWhileItsTreeIsNotLockedShouldNotThrowException()
- {
- $article = $this->createArticle();
- $article->setTitle('1');
- $article2 = $this->createArticle();
- $article2->setTitle('2');
- $article2->setParent($article);
-
-
- $this->dm->persist($article);
- $this->dm->persist($article2);
- $this->dm->flush();
- $this->dm->clear();
-
-
- $this->listener->setReleaseLocks(true);
-
- $article3 = $this->createArticle();
- $article3->setTitle('3');
-
- $this->dm->persist($article3);
- $this->dm->flush();
-
-
- $article3->setTitle('New title');
- $this->dm->flush();
-
-
- $this->setExpectedException('Gedmo\Exception\TreeLockingException');
-
- $repo = $this->dm->getRepository(self::ARTICLE);
- $article2 = $repo->findOneByTitle('2');
- $article2->setTitle('New title 2');
-
- $this->dm->flush();
- }
-
- public function createArticle()
- {
- $class = self::ARTICLE;
- return new $class;
- }
- }
|