/** * @test */ public function entitiesWithinAggregateAreRemovedAutomaticallyWithItsRootEntity() { $image = new Fixtures\Image(); $post = new Fixtures\Post(); $post->setImage($image); $this->postRepository->add($post); $this->persistenceManager->persistAll(); $imageIdentifier = $this->persistenceManager->getIdentifierByObject($image); $retrievedImage = $this->persistenceManager->getObjectByIdentifier($imageIdentifier, Fixtures\Image::class); $this->assertSame($image, $retrievedImage); $this->postRepository->remove($post); $this->persistenceManager->persistAll(); $this->assertTrue($this->persistenceManager->isNewObject($retrievedImage)); }
/** * @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()); }