Beispiel #1
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());
 }
Beispiel #2
0
 public function shutdownObject()
 {
     if ($this->relatedObject instanceof CleanupObject) {
         $this->relatedObject->toggleState();
     }
 }