/** * @test */ public function validatorBehavesCorrectlyOnDuplicateEntityWithSingleConfiguredIdentityProperty() { $validator = new \Neos\Flow\Validation\Validator\UniqueEntityValidator(['identityProperties' => ['title']]); $post = new Post(); $post->setTitle('The title of the initial post'); $this->postRepository->add($post); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $differentPost = new Post(); $differentPost->setTitle('A different title'); $this->assertFalse($validator->validate($differentPost)->hasErrors()); $nextPost = new Post(); $nextPost->setTitle('The title of the initial post'); $this->assertTrue($validator->validate($nextPost)->hasErrors()); }
/** * @test */ public function shutdownObjectMethodIsRegisterdForDoctrineProxy() { $image = new Fixtures\Image(); $post = new Fixtures\Post(); $post->setImage($image); $this->postRepository->add($post); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $postIdentifier = $this->persistenceManager->getIdentifierByObject($post); unset($post); unset($image); /* * When hydrating the post a DoctrineProxy is generated for the image. * On this proxy __wakeup() is called and the shutdownObject lifecycle method * needs to be registered in the ObjectManager */ $post = $this->persistenceManager->getObjectByIdentifier($postIdentifier, Fixtures\Post::class); /* * The CleanupObject is just a helper object to test that shutdownObject() on the Fixtures\Image is called */ $cleanupObject = new Fixtures\CleanupObject(); $this->assertFalse($cleanupObject->getState()); $post->getImage()->setRelatedObject($cleanupObject); /* * When shutting down the ObjectManager shutdownObject() on Fixtures\Image is called * and toggles the state on the cleanupObject */ \Neos\Flow\Core\Bootstrap::$staticObjectManager->shutdown(); $this->assertTrue($cleanupObject->getState()); }
/** * @test */ public function comlexQueryWithJoinsCanBeExecutedAfterDeserialization() { $postEntityRepository = new Fixtures\PostRepository(); $postEntityRepository->removeAll(); $commentRepository = new Fixtures\CommentRepository(); $commentRepository->removeAll(); $testEntity1 = new Fixtures\Post(); $testEntity1->setTitle('Flow'); $postEntityRepository->add($testEntity1); $testEntity2 = new Fixtures\Post(); $testEntity2->setTitle('Flow with comment'); $comment = new Fixtures\Comment(); $comment->setContent('Flow'); $testEntity2->setComment($comment); $postEntityRepository->add($testEntity2); $commentRepository->add($comment); $this->persistenceManager->persistAll(); $query = new Query(Fixtures\Post::class); $query->matching($query->equals('comment.content', 'Flow')); $serializedQuery = serialize($query); $unserializedQuery = unserialize($serializedQuery); $this->assertEquals(1, $unserializedQuery->execute()->count()); $this->assertEquals([$testEntity2], $unserializedQuery->execute()->toArray()); }