Example #1
0
 public function testClient()
 {
     $pami = $this->getMockBuilder('PAMI\\Client\\Impl\\ClientImpl')->disableOriginalConstructor()->getMock();
     $eventManager = $this->getMockBuilder('Zend\\EventManager\\EventManager')->getMock();
     /* @var \PAMI\Client\Impl\ClientImpl $pami */
     /* @var \Zend\EventManager\EventManager $eventManager */
     $client = new Client('host', $pami);
     $client->setEventManager($eventManager);
     static::assertSame($pami, $client->getConnection());
     static::assertEquals('host', $client->getHost());
     // Test attach EventManager
     $eventManager = $client->getEventManager();
     static::assertSame($eventManager, $client->getEventManager());
     $params = ['foo' => 'bar'];
     $client->setParams($params);
     static::assertEquals($params, $client->getParams());
 }
 /**
  * Create an object.
  *
  * @param ContainerInterface $container
  * @param string             $requestedName
  * @param null|array         $options
  *
  * @throws \RuntimeException
  * @throws \Interop\Container\Exception\NotFoundException
  * @throws ServiceNotFoundException                       if unable to resolve the service
  * @throws ServiceNotCreatedException                     if an exception is raised when
  *                                                        creating a service
  * @throws ContainerException                             if any other error occurs
  *
  * @return Client
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $options = null;
     $connectionName = $this->getName();
     if ($this->hasOptions($container, 'client', $this->getName())) {
         /** @var ClientOptions $options */
         $options = $this->getOptions($container, 'client');
         $connectionName = $options->getConnection() ?: $this->getName();
     }
     $connectionFactory = new ConnectionFactory($connectionName);
     /** @var Connection $connectionOptions */
     $connectionOptions = $connectionFactory->getOptions($container, 'connection');
     /** @var ClientImpl $connection */
     $connection = $container->get(sprintf('pami.connection.%s', $connectionName));
     $client = new Client($connectionOptions->getHost(), $connection);
     $client->setEventManager($this->createEventManager($container));
     if ($options) {
         $client->setParams($options->getParams());
     }
     $eventForwarder = new EventForwarder($client);
     $client->getConnection()->registerEventListener($eventForwarder);
     return $client;
 }