Selaa lähdekoodia

additional test case

gediminasm 14 vuotta sitten
vanhempi
commit
fe4b935e3e

+ 5 - 0
README.markdown

@@ -182,6 +182,10 @@ After these changes translations will be generated, but article in database
 will not change it`s title to "my title in ru". Nevertheless translations in
 ru_ru locale will be available to it.
 
+**Notice:** Using **Translatable** behavior on concurrent updates and inserts flush may
+result in exception. In that case try flushing only inserts and then updates. The test
+case is in unit tests;
+
 ## Sluggable
 
 **Sluggable** behavior will build the slug of predefined fields on a given field
@@ -289,4 +293,5 @@ To save **Article** and generate slug simply use:
 
     echo $article->getSlug();
     // prints: the-title-my-slug
+    
     

+ 3 - 1
lib/DoctrineExtensions/Translatable/Exception.php

@@ -31,6 +31,8 @@ class Exception extends \Exception
     
     static public function pendingInserts()
     {
-        return new self("Unit of work has pending inserts, cannot request query execute");
+        return new self("UnitOfWork has pending inserts, cannot request query execution.
+            TranslationListener does not support Concurrent inserts and updates together,
+            on Doctrine 2 Beta4 yet. Try flushing only inserts or updates");
     }
 }

+ 1 - 1
lib/DoctrineExtensions/Translatable/TranslationListener.php

@@ -331,7 +331,7 @@ class TranslationListener implements EventSubscriber
      */
     protected function _findTranslation(EntityManager $em, $entityId, $entityClass, $locale, $field, $contentOnly = false)
     {
-    	// @TODO: cannot use query if doctrine has pending inserts, this is annoying
+    	// @TODO: cannot use query if doctrine has pending inserts
     	if ($em->getUnitOfWork()->hasPendingInsertions()) {
     		throw Exception::pendingInserts();
     	}

+ 16 - 1
tests/DoctrineExtensions/Sluggable/TranslatableSlugTest.php

@@ -113,11 +113,26 @@ class TranslatableSlugTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals('title-in-de-code-in-de', $translations['de_de']['slug']);
     }
     
-    public function testConcurentChanges()
+    public function testConcurrentChanges()
     {
     	$page = new Page;
     	$page->setContent('cont test');
     	
+    	$a0Page = new Page;
+    	$a0Page->setContent('bi vv');
+    	
+    	$article0 = $this->em->find(self::TEST_CLASS, $this->articleId);
+    	$article0->setCode('cell');
+    	$article0->setTitle('xx gg');
+    	$a0Page->addArticle($article0);
+    	
+    	$a0Comment = new Comment;
+    	$a0Comment->setMessage('the xx message');
+    	$article0->addComment($a0Comment);
+    	$this->em->persist($a0Comment);
+    	$this->em->persist($article0);
+    	$this->em->persist($a0Page);
+    	
     	$article1 = new TranslatableArticle();
         $article1->setTitle('art1 test');
         $article1->setCode('cd1 test');