From 71982667841568d9cb6305d02f4092b0def55011 Mon Sep 17 00:00:00 2001 From: dantleech Date: Tue, 11 Oct 2016 15:33:54 +0100 Subject: [PATCH] Added missing tests --- benchmark/DoctrinePhpcrBench.php | 2 +- .../Subscriber/CollectionSubscriber.php | 2 +- tests/Functional/Container.php | 4 +- ...enceField.php => ObjectReferenceField.php} | 2 +- .../Storage/Doctrine/PhpcrOdm/Article.php | 3 +- .../PhpcrOdm/ImageNotAssignedGenerator.php | 27 ++++++++++++ .../PhpcrOdm/CollectionType/ObjectTest.php | 42 ++++++++++++++++++- .../Storage/Doctrine/PhpcrOdm/GeneralTest.php | 2 +- 8 files changed, 75 insertions(+), 9 deletions(-) rename tests/Functional/Example/Field/{ImageReferenceField.php => ObjectReferenceField.php} (93%) create mode 100644 tests/Functional/Example/Storage/Doctrine/PhpcrOdm/ImageNotAssignedGenerator.php diff --git a/benchmark/DoctrinePhpcrBench.php b/benchmark/DoctrinePhpcrBench.php index d8937f4..d889a56 100644 --- a/benchmark/DoctrinePhpcrBench.php +++ b/benchmark/DoctrinePhpcrBench.php @@ -40,7 +40,7 @@ public function setUp() 'type' => 'datetime', ], 'referencedImage' => [ - 'type' => 'image_reference', + 'type' => 'object_reference', ], 'paragraphs' => [ 'type' => 'collection', diff --git a/src/Storage/Doctrine/PhpcrOdm/Subscriber/CollectionSubscriber.php b/src/Storage/Doctrine/PhpcrOdm/Subscriber/CollectionSubscriber.php index c434e2a..c82c2e9 100644 --- a/src/Storage/Doctrine/PhpcrOdm/Subscriber/CollectionSubscriber.php +++ b/src/Storage/Doctrine/PhpcrOdm/Subscriber/CollectionSubscriber.php @@ -66,7 +66,7 @@ public function preFlush(ManagerEventArgs $args) throw new \InvalidArgumentException(sprintf( 'Currently, all documents which belong to a mapped collection must use the ' . 'assigned ID generator strategy, "%s" is using "%s".', - $childMetadata->getClass(), $idGenerator + $childMetadata->getName(), $idGenerator )); } diff --git a/tests/Functional/Container.php b/tests/Functional/Container.php index f257afb..a2d0d02 100644 --- a/tests/Functional/Container.php +++ b/tests/Functional/Container.php @@ -40,7 +40,7 @@ use Psi\Component\ContentType\Storage\Mapping\TypeFactory; use Psi\Component\ContentType\Storage\Mapping\TypeRegistry; use Psi\Component\ContentType\Tests\Functional\Example\Field\ImageField; -use Psi\Component\ContentType\Tests\Functional\Example\Field\ImageReferenceField; +use Psi\Component\ContentType\Tests\Functional\Example\Field\ObjectReferenceField; use Psi\Component\ContentType\Tests\Functional\Example\View\ImageView; use Psi\Component\ContentType\View\ScalarView; use Psi\Component\ContentType\ViewRegistry; @@ -101,7 +101,7 @@ private function loadPsiContentType() $registry->register('integer', new IntegerField()); $registry->register('datetime', new DateTimeField()); $registry->register('image', new ImageField()); - $registry->register('image_reference', new ImageReferenceField()); + $registry->register('object_reference', new ObjectReferenceField()); $registry->register('collection', new CollectionField($registry)); return $registry; diff --git a/tests/Functional/Example/Field/ImageReferenceField.php b/tests/Functional/Example/Field/ObjectReferenceField.php similarity index 93% rename from tests/Functional/Example/Field/ImageReferenceField.php rename to tests/Functional/Example/Field/ObjectReferenceField.php index a266cfe..9777de4 100644 --- a/tests/Functional/Example/Field/ImageReferenceField.php +++ b/tests/Functional/Example/Field/ObjectReferenceField.php @@ -9,7 +9,7 @@ use Psi\Component\ContentType\View\ScalarView; use Symfony\Component\Form\Extension\Core\Type\TextType; -class ImageReferenceField implements FieldInterface +class ObjectReferenceField implements FieldInterface { public function getViewType(): string { diff --git a/tests/Functional/Example/Storage/Doctrine/PhpcrOdm/Article.php b/tests/Functional/Example/Storage/Doctrine/PhpcrOdm/Article.php index 8aa0e98..f206350 100644 --- a/tests/Functional/Example/Storage/Doctrine/PhpcrOdm/Article.php +++ b/tests/Functional/Example/Storage/Doctrine/PhpcrOdm/Article.php @@ -5,7 +5,7 @@ use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; /** - * @PHPCR\Document() + * @PHPCR\Document(referenceable=true) */ class Article { @@ -22,4 +22,5 @@ class Article public $referencedImage; public $numbers; public $paragraphs = []; + public $objectReferences; } diff --git a/tests/Functional/Example/Storage/Doctrine/PhpcrOdm/ImageNotAssignedGenerator.php b/tests/Functional/Example/Storage/Doctrine/PhpcrOdm/ImageNotAssignedGenerator.php new file mode 100644 index 0000000..716afa7 --- /dev/null +++ b/tests/Functional/Example/Storage/Doctrine/PhpcrOdm/ImageNotAssignedGenerator.php @@ -0,0 +1,27 @@ + 'image', ], ], + 'objectReferences' => [ + 'type' => 'collection', + 'options' => [ + 'field' => 'object_reference', + ], + ], ], ], ], @@ -185,17 +192,48 @@ public function testCollectionPersistNoUpdater() /** * It should throw an exception when a document in a collection does not have the "ASSIGNED" ID generator. + * + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Currently, all documents which belong to a mapped collection must use the assigned ID generator strategy */ public function testCollectionPersistNoAssignedGenerator() { - $this->markTestIncomplete('TODO'); + $image1 = new ImageNotAssignedGenerator(); + $article = new Article(); + $article->id = '/test/article'; + $article->slideshow = [ $image1 ]; + $this->updater->update($this->documentManager, $article); + $this->documentManager->persist($article); + $this->documentManager->flush(); } + /** * It should store arrays of references. */ public function testStoreArrayOfReferences() { - $this->markTestIncomplete('TODO'); + $article = new Article(); + $article->id = '/test/article'; + + $article1 = new Article(); + $article1->id = '/test/article1'; + + $article2 = new Article(); + $article2->id = '/test/article2'; + + $this->documentManager->persist($article1); + $this->documentManager->persist($article2); + $this->documentManager->flush(); + + $article->objectReferences = [ $article1, $article2 ]; + $this->documentManager->persist($article); + $this->documentManager->flush(); + $this->documentManager->clear(); + + $article = $this->documentManager->find(null, '/test/article'); + $this->assertCount(2, $article->objectReferences); + $this->assertEquals('/test/article1', $article->objectReferences[0]->id); + $this->assertEquals('/test/article2', $article->objectReferences[1]->id); } private function createArticleSlideshow() diff --git a/tests/Functional/Storage/Doctrine/PhpcrOdm/GeneralTest.php b/tests/Functional/Storage/Doctrine/PhpcrOdm/GeneralTest.php index d93e2e8..665ec3d 100644 --- a/tests/Functional/Storage/Doctrine/PhpcrOdm/GeneralTest.php +++ b/tests/Functional/Storage/Doctrine/PhpcrOdm/GeneralTest.php @@ -27,7 +27,7 @@ public function setUp() 'type' => 'datetime', ], 'referencedImage' => [ - 'type' => 'image_reference', + 'type' => 'object_reference', ], ], ],