Beispiel #1
0
 /**
  * @covers \OcraServiceManager\ServiceManager\Logger::getLoggedServices
  */
 public function testGetLoggedServices()
 {
     $locator = $this->getMock('Zend\\ServiceManager\\ServiceLocatorInterface');
     $dependency2 = new \stdClass();
     $dependency1 = new \stdClass();
     $instance = new \stdClass();
     $instance2 = new \stdClass();
     $this->listener->registerServiceCall($locator, $dependency2, 'dependency2-canonical-name', 'dependency2\\requested\\name', 'create', array(array('object' => $locator, 'function' => 'get', 'args' => array('dependency2\\requested\\name')), array('object' => $locator, 'function' => 'create', 'args' => array(array('dependency1-canonical-name', 'dependency1\\requested\\name'))), array('object' => $locator, 'function' => 'get', 'args' => array('instance\\requested\\name'))));
     $this->listener->registerServiceCall($locator, $dependency1, 'dependency1-canonical-name', 'dependency1\\requested\\name', 'create', array(array('object' => $locator, 'function' => 'get', 'args' => array('dependency1\\requested\\name')), array('object' => $locator, 'function' => 'get', 'args' => array('instance\\requested\\name'))));
     $this->listener->registerServiceCall($locator, $instance, 'instance-canonical-name', 'instance\\requested\\name', 'create', array(array('object' => $locator, 'function' => 'get', 'args' => array('instance\\requested\\name'))));
     $this->listener->registerServiceCall($locator, $instance, 'instance-canonical-name', 'instance\\second\\requested\\name', 'create', array(array('object' => $locator, 'function' => 'get', 'args' => array('instance\\second\\requested\\name'))));
     $this->listener->registerServiceCall($locator, $instance2, 'instance-canonical-name', 'instance\\third\\requested\\name', 'create', array(array('object' => $locator, 'function' => 'get', 'args' => array('instance\\third\\requested\\name'))));
     $loggedServices = $this->listener->getLoggedServices();
     $instanceHash = spl_object_hash($instance);
     $instance2Hash = spl_object_hash($instance2);
     $dependency1Hash = spl_object_hash($dependency1);
     $dependency2Hash = spl_object_hash($dependency2);
     $this->assertCount(4, $loggedServices);
     $this->assertArrayHasKey($instanceHash, $loggedServices);
     $this->assertArrayHasKey($instance2Hash, $loggedServices);
     $this->assertArrayHasKey($dependency1Hash, $loggedServices);
     $this->assertArrayHasKey($dependency2Hash, $loggedServices);
     $this->assertSame(2, $loggedServices[$instanceHash]['accesses']);
     $this->assertSame('instance-canonical-name', $loggedServices[$instanceHash]['canonical_name']);
     $this->assertCount(2, $loggedServices[$instanceHash]['names']);
     $this->assertSame(1, $loggedServices[$instanceHash]['service_instantiation_idx']);
     $this->assertEmpty($loggedServices[$instanceHash]['depending']);
     $this->assertCount(1, $loggedServices[$instanceHash]['dependencies']);
     $this->assertContains($dependency1Hash, $loggedServices[$instanceHash]['dependencies']);
     $this->assertSame(1, $loggedServices[$instance2Hash]['accesses']);
     $this->assertSame('instance-canonical-name', $loggedServices[$instance2Hash]['canonical_name']);
     $this->assertCount(1, $loggedServices[$instance2Hash]['names']);
     $this->assertSame(2, $loggedServices[$instance2Hash]['service_instantiation_idx']);
     $this->assertEmpty($loggedServices[$instance2Hash]['depending']);
     $this->assertCount(0, $loggedServices[$instance2Hash]['dependencies']);
     $this->assertSame(1, $loggedServices[$dependency1Hash]['accesses']);
     $this->assertSame('dependency1-canonical-name', $loggedServices[$dependency1Hash]['canonical_name']);
     $this->assertCount(1, $loggedServices[$dependency1Hash]['names']);
     $this->assertSame(1, $loggedServices[$dependency1Hash]['service_instantiation_idx']);
     $this->assertCount(1, $loggedServices[$dependency1Hash]['depending']);
     $this->assertContains($instanceHash, $loggedServices[$dependency1Hash]['depending']);
     $this->assertCount(1, $loggedServices[$dependency1Hash]['dependencies']);
     $this->assertContains($dependency2Hash, $loggedServices[$dependency1Hash]['dependencies']);
     $this->assertSame(1, $loggedServices[$dependency2Hash]['accesses']);
     $this->assertSame('dependency2-canonical-name', $loggedServices[$dependency2Hash]['canonical_name']);
     $this->assertCount(1, $loggedServices[$dependency2Hash]['names']);
     $this->assertSame(1, $loggedServices[$dependency2Hash]['service_instantiation_idx']);
     $this->assertCount(1, $loggedServices[$dependency2Hash]['depending']);
     $this->assertContains($dependency1Hash, $loggedServices[$dependency2Hash]['depending']);
     $this->assertEmpty($loggedServices[$dependency2Hash]['dependencies']);
 }
Beispiel #2
0
 /**
  * {@inheritDoc}
  *
  * @todo complete with dependencies
  */
 public function collect(MvcEvent $mvcEvent)
 {
     $this->collectedServices = $this->logger->getLoggedServices();
     $this->collectedServiceLocators = $this->logger->getLoggedServiceLocators();
 }