public function testDetachSharedDetachAttachedListener()
 {
     $sharedEventManager = new SharedEventManager();
     $sharedEventManager->attachAggregate($this->listener);
     $sharedEventManager->detachAggregate($this->listener);
     $listener = $sharedEventManager->getListeners('ZF\\Rest\\RestController', MvcEvent::EVENT_DISPATCH);
     $this->assertEquals(0, $listener->count());
 }
 public function _attachStateful(SharedEventManager $sm, $target, $method)
 {
     $i = 100;
     foreach (['pre' => 'pre', '' => 'on', 'post' => 'post'] as $prefix => $state) {
         try {
             if (method_exists($this, $prefix . $method)) {
                 $this->listeners[] = $sm->attach($target, "{$method}.{$state}", array($this, $prefix . $method), $i);
             }
         } catch (\Exception $e) {
         }
         $i -= 100;
     }
 }
Example #3
0
 public function testSharedEventManagerAttachReturnsCallbackHandler()
 {
     $shared = new SharedEventManager();
     $callbackHandler = $shared->attach('foo', 'bar', function ($e) {
         return true;
     });
     $this->assertTrue($callbackHandler instanceof CallbackHandler);
 }
Example #4
0
 public function index10Action()
 {
     $shareEventManager = new SharedEventManager();
     //Giống abstract
     $shareEventManager->attach("emOne", "eventOne", function ($e) {
         echo "<h3 style='color:red;font-weight:bold'>eventManagerOne - eventOne - Do 1</h3>";
     });
     $shareEventManager->attach(array("emTwo", "emThree"), "eventNew", function ($e) {
         echo "<h3 style='color:red;font-weight:bold'>eventManagerOne - eventNew - Do 1</h3>";
     });
     $eventManager = new EventManager(array("emOne", "emThree"));
     $eventManager->setSharedManager($shareEventManager);
     $eventManager->trigger("eventOne");
     $eventManager->trigger("eventNew");
     $eventManager = new EventManager("emTwo");
     $eventManager->setSharedManager($shareEventManager);
     $eventManager->trigger("eventNew");
     return false;
 }
Example #5
0
 public function testEventManagerListensOnClassNameByDefault()
 {
     $response = new Response();
     $response->setContent('short circuited!');
     $events = new SharedEventManager();
     $events->attach(get_class($this->controller), 'dispatch', function($e) use ($response) {
         return $response;
     }, 10);
     $this->controller->events()->setSharedManager($events);
     $result = $this->controller->dispatch($this->request, $this->response);
     $this->assertSame($response, $result);
 }
 /**
  * @group 166
  */
 public function testPatchOfADbConnectedServiceUpdatesDbConnectedConfiguration()
 {
     $moduleManager = $this->moduleManager;
     $modulePathSpec = $this->modules;
     $writer = $this->writer;
     $configResourceFactory = $this->configFactory;
     $moduleModel = new ModuleModel($moduleManager, [], []);
     $sharedEvents = new SharedEventManager();
     $restServiceModelFactory = new RestServiceModelFactory($modulePathSpec, $configResourceFactory, $sharedEvents, $moduleModel);
     $resource = new RestServiceResource($restServiceModelFactory, $this->filter, $this->docs);
     $sharedEvents->attach('ZF\\Apigility\\Admin\\Model\\RestServiceModel', 'fetch', 'ZF\\Apigility\\Admin\\Model\\DbConnectedRestServiceModel::onFetch');
     $r = new ReflectionObject($resource);
     $prop = $r->getProperty('moduleName');
     $prop->setAccessible(true);
     $prop->setValue($resource, 'BarConf');
     $entity = $resource->create(['adapter_name' => 'Db\\Test', 'table_name' => 'test']);
     $this->assertInstanceOf('ZF\\Apigility\\Admin\\Model\\DbConnectedRestServiceEntity', $entity);
     $id = $entity->controllerServiceName;
     $updateData = ['entity_identifier_name' => 'test_id', 'hydrator_name' => 'Zend\\Hydrator\\ObjectProperty'];
     $resource->patch($id, $updateData);
     $config = (include __DIR__ . '/TestAsset/module/BarConf/config/module.config.php');
     $this->assertInternalType('array', $config);
     $this->assertArrayHasKey('BarConf\\V1\\Rest\\Test\\TestEntity', $config['zf-hal']['metadata_map']);
     $this->assertArrayHasKey('BarConf\\V1\\Rest\\Test\\TestResource', $config['zf-apigility']['db-connected']);
     $halConfig = $config['zf-hal']['metadata_map']['BarConf\\V1\\Rest\\Test\\TestEntity'];
     $agConfig = $config['zf-apigility']['db-connected']['BarConf\\V1\\Rest\\Test\\TestResource'];
     $this->assertEquals('test_id', $halConfig['entity_identifier_name']);
     $this->assertEquals('test_id', $agConfig['entity_identifier_name']);
     $this->assertEquals('Zend\\Hydrator\\ObjectProperty', $halConfig['hydrator']);
     $this->assertEquals('Zend\\Hydrator\\ObjectProperty', $agConfig['hydrator_name']);
 }