Beispiel #1
0
 /**
  * Verifies that the pre and post events for `setStub` are dispatched.
  */
 public function testSetStub()
 {
     // make sure the events are fired and changes are applied
     $hello = '<?php echo "Hello, world!\\n"; __HALT_COMPILER(); ?>';
     $goodbye = '<?php echo "Goodbye, world!\\n"; __HALT_COMPILER(); ?>';
     $post = null;
     $this->dispatcher->addListener(Events::PRE_SET_STUB, function (PreSetStubEvent $event) use($goodbye) {
         $event->setStub($goodbye);
     });
     $this->dispatcher->addListener(Events::POST_SET_STUB, function (PostSetStubEvent $event) use(&$post) {
         $post = $event;
     });
     $this->builder->setStub($hello);
     self::assertEquals($goodbye, trim($this->builder->getStub()));
     self::assertInstanceOf('Box\\Component\\Builder\\Event\\PostSetStubEvent', $post);
     // make sure the process can be skipped
     $this->removeListeners();
     $this->builder->setStub(Builder::createDefaultStub());
     $this->dispatcher->addListener(Events::PRE_SET_STUB, function (PreSetStubEvent $event) {
         $event->skip();
     });
     $this->builder->setStub($hello);
     self::assertEquals(trim(Builder::createDefaultStub()), trim($this->builder->getStub()));
     // make sure we can skip everything and go straight to `Phar`
     $this->builder->setEventDispatcher(null);
     $post = null;
     $this->builder->setStub($hello);
     self::assertEquals($hello, trim($this->builder->getStub()));
     self::assertNull($post);
 }