/**
  * @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 modificationsOnRetrievedEntitiesArePersistedIfUpdateHasBeenCalled()
 {
     $this->postRepository = $this->objectManager->get(Fixtures\PostRepository::class);
     $post = new Fixtures\Post();
     $post->setTitle('Sample');
     $this->postRepository->add($post);
     $this->persistenceManager->persistAll();
     $post = $this->postRepository->findOneByTitle('Sample');
     $post->setTitle('Modified Sample');
     $this->postRepository->update($post);
     $this->persistenceManager->persistAll();
     $post = $this->postRepository->findOneByTitle('Modified Sample');
     $this->assertNotNull($post);
     $this->assertEquals('Modified Sample', $post->getTitle());
 }
 /**
  * @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());
 }
Пример #4
0
 /**
  * @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());
 }
 /**
  * This test fixes FLOW-296 but is only affecting MySQL.
  *
  * @test
  */
 public function valueObjectsAreNotCascadeRemovedWhenARelatedEntityIsDeleted()
 {
     $post1 = new Fixtures\Post();
     $post1->setAuthor(new Fixtures\TestValueObject('Some Name'));
     $post2 = new Fixtures\Post();
     $post2->setAuthor(new Fixtures\TestValueObject('Some Name'));
     $this->postRepository->add($post1);
     $this->postRepository->add($post2);
     $this->persistenceManager->persistAll();
     $this->postRepository->remove($post1);
     $this->persistenceManager->persistAll();
     // if all goes well the value object is not deleted
     $this->assertTrue(true);
 }