public function testCreateService() { $configuration = ['pami_module' => ['connection' => ['default' => ['host' => 'local.host', 'scheme' => 'tcp://', 'port' => 123, 'username' => 'admin', 'secret' => 'foosecret', 'connect_timeout' => 123, 'read_timeout' => 123]]]]; $serviceManager = $this->moduleLoader->getServiceManager(); $serviceManager->setAllowOverride(true); $config = $serviceManager->get('config'); $config = ArrayUtils::merge($config, $configuration); $serviceManager->setService('config', $config); $factory = new ConnectionFactory('default'); $service = $factory->createService($serviceManager); static::assertInstanceOf('PAMI\\Client\\Impl\\ClientImpl', $service); }
/** * 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; }