public function testCanDetachListenersFromEventManager()
 {
     $events = new EventManager();
     $events->attachAggregate($this->strategy);
     $this->assertEquals(1, count($events->getListeners(MvcEvent::EVENT_RENDER)));
     $events->detachAggregate($this->strategy);
     $this->assertEquals(0, count($events->getListeners(MvcEvent::EVENT_RENDER)));
 }
 public function testDetachesListeners()
 {
     $events = new EventManager();
     $events->attachAggregate($this->listener);
     $listeners = $events->getListeners('dispatch');
     $this->assertEquals(1, count($listeners));
     $events->detachAggregate($this->listener);
     $listeners = $events->getListeners('dispatch');
     $this->assertEquals(0, count($listeners));
 }
 public function testDetachesListeners()
 {
     $events = new EventManager();
     $events->attachAggregate($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH);
     $this->assertEquals(2, count($listeners));
     $events->detachAggregate($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH);
     $this->assertEquals(0, count($listeners));
 }
 /**
  * @SWG\Property(name="station_id",type="integer",description="Unique identifier of the gas station")
  * @SWG\Property(name="name",type="string",description="Name of the gas station")
  * @SWG\Property(name="social_reason",type="string",description="Official name of the gas station")
  * @SWG\Property(name="address_line_1",type="string",description="Street name and number of the gas station")
  * @SWG\Property(name="address_line_2",type="string",description="Neighborhood name of the gas station")
  * @SWG\Property(name="location",type="string",description="State and city name where the gas station is located")
  * @SWG\Property(name="latitude",type="double",description="Latitude coordinate")
  * @SWG\Property(name="longitude",type="double",description="Longitude coordinate")
  * @SWG\Property(name="created_at",type="string",format="date-format",description="Registration date of the gas station")
  * @SWG\Property(name="last_updated_at",type="string",format="date-format",description="Most recent date in which the gas station was edited")
  */
 public function register(Slim $app)
 {
     $app->container->singleton('station', function () use($app) {
         return new Model($app->stationTable, $app->stationValidator, $app->paginatorFactory);
     });
     $app->container->singleton('stationFormatter', function () use($app) {
         return new ResourceFormatter($app->urlHelper, 'station', 'station_id');
     });
     $app->container->singleton('stationsFormatter', function () use($app) {
         return new CollectionFormatter($app->urlHelper, 'stations', $app->stationFormatter);
     });
     $app->container->singleton('stationEvents', function () use($app) {
         $eventManager = new EventManager();
         $specification = new ChainedSpecification();
         $specification->addSpecification(new PaginationSpecification($app->config('defaultPageSize')));
         $specification->addSpecification(new GeolocationSpecification());
         $eventManager->attach('postFindAll', new QuerySpecificationListener($specification));
         $eventManager->attachAggregate(new HasTimestampListener());
         $eventManager->attachAggregate(new CacheListener($app->cache, $app->request()->getPathInfo()));
         return $eventManager;
     });
     $app->container->singleton('stationTable', function () use($app) {
         $stationTable = new StationTable('stations', $app->connection);
         $factory = new TableProxyFactory($app->proxiesConfiguration, $app->stationEvents);
         $stationTable = $factory->createProxy($stationTable);
         $factory->addEventManagement($stationTable);
         return $stationTable;
     });
     $app->container->singleton('stationValidator', function () use($app) {
         return new ValitronValidator(require 'config/validations/stations.config.php');
     });
     $app->container->singleton('stationController', function () use($app) {
         $app->controller->setModel($app->station);
         $app->controllerEvents->attach('postDispatch', new FormatResourceListener($app->stationFormatter));
         return $app->controller;
     });
     $app->container->singleton('stationsController', function () use($app) {
         $app->controller->setModel($app->station);
         $app->controllerEvents->attach('postDispatch', new FormatResourceListener($app->stationsFormatter));
         return $app->controller;
     });
 }
 public function testDetachesListeners()
 {
     $events = new EventManager();
     $events->attachAggregate($this->strategy);
     $listeners = $events->getListeners('renderer');
     $this->assertEquals(1, count($listeners));
     $listeners = $events->getListeners('response');
     $this->assertEquals(1, count($listeners));
     $events->detachAggregate($this->strategy);
     $listeners = $events->getListeners('renderer');
     $this->assertEquals(0, count($listeners));
     $listeners = $events->getListeners('response');
     $this->assertEquals(0, count($listeners));
 }
 public function testListenerAttachesDispatchEventAtExpectedPriority()
 {
     $events = new EventManager();
     $events->attachAggregate($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH);
     $expectedCallback = [$this->listener, 'injectActionHandles'];
     $expectedPriority = 1000;
     $found = false;
     foreach ($listeners as $listener) {
         $callback = $listener->getCallback();
         if ($callback === $expectedCallback) {
             if ($listener->getMetadatum('priority') == $expectedPriority) {
                 $found = true;
                 break;
             }
         }
     }
     $this->assertTrue($found, 'Listener not found');
 }
Example #7
0
 /**
  * 
  * @param ListenerAggregateInterface $listener
  */
 public function attach(ListenerAggregateInterface $listener)
 {
     $this->eventManager->attachAggregate($listener);
 }
Example #8
0
 public function testPrepareExceptionRendersPreviousMessages()
 {
     $events = new EventManager();
     $events->attachAggregate($this->strategy);
     $messages = array('message foo', 'message bar', 'deepest message');
     $exception = null;
     $i = 0;
     do {
         $exception = new \Exception($messages[$i], null, $exception);
         $i++;
     } while ($i < count($messages));
     $event = new MvcEvent(MvcEvent::EVENT_DISPATCH_ERROR, null, array('exception' => $exception));
     $event->setError('user-defined-error');
     $events->trigger($event, null, array('exception' => $exception));
     //$this->strategy->prepareExceptionViewModel($event);
     foreach ($messages as $message) {
         $this->assertContains($message, $event->getResult()->getResult(), sprintf('Not all errors are rendered'));
     }
 }