public function testSimpleReferenceSubstitution()
 {
     $dependency = new \stdClass();
     $factory = $this->getMockBuilder(ServicesFactory::class)->getMock();
     $factory->expects($this->once())->method('get')->with('dependency.id')->willReturn($dependency);
     $builder = new ClassServiceBuilder();
     $builder->setServicesFactory($factory);
     $serviceDefinition = new ClassServiceSpecs('main.service', 'stdClass');
     $serviceDefinition->setParams(['dependency' => new ServiceReference('dependency.id')]);
     $builder->build($serviceDefinition);
 }
 /**
  * @param ApplicationInterface $app
  */
 public function registerServices(ApplicationInterface $app)
 {
     $servers = $app->getConfig()->subset(BeanstalkServer::class);
     foreach ($servers as $service => $data) {
         $serviceName = self::SERVICE_PREFIX . $service;
         $service = new ClassServiceSpecs($serviceName, Pheanstalk::class);
         $service->setParams([$data['host'], $data['port'], $data['timeout'], $data['persistent']]);
         $service->setSetters(['useTube' => [$data['tube']]]);
         $app->getServicesFactory()->registerService($service);
     }
 }
 /**
  * Service definition factory
  *
  * IT IS NOT RECOMMENDED TO CALL THIS METHOD EXPLICITLY
  *
  * Please call AbstractServiceSpecs::factory(), that will
  * forward to the appropriate factory after having performed
  * basic sanity checks ('id' presence)
  *
  * @param array|Collection $rawDefinition
  * @throws Exception
  */
 public static function factory($rawDefinition)
 {
     $rawDefinition = Collection::cast($rawDefinition);
     // then check check a class has been provided
     if (!$rawDefinition->has('class')) {
         throw new Exception('Missing \'class\' parameter', Exception::INCOMPLETE_SERVICE_SPECS);
     }
     if (!is_string($class = $rawDefinition['class'])) {
         throw new Exception('\'class\' parameter has to be a string', Exception::INVALID_SERVICE_SPECS);
     }
     $serviceDefinition = new ClassServiceSpecs($rawDefinition['id'], $class);
     // constructor params
     if ($rawDefinition->has('params')) {
         $serviceDefinition->setParams($rawDefinition['params']);
     }
     // setters
     if ($rawDefinition->has('setters')) {
         $serviceDefinition->setSetters($rawDefinition['setters']);
     }
     return $serviceDefinition;
 }
 public function testIsServiceRegistered()
 {
     $factory = new ServicesFactory();
     $serviceSpecs = new ClassServiceSpecs('service.id', \Fancy\Service\TestService::class);
     $serviceSpecs->setParams(['param' => 'default']);
     $factory->registerService($serviceSpecs);
     $this->assertTrue($factory->isServiceRegistered('service.id'));
     $this->assertFalse($factory->isServiceRegistered(uniqid(uniqid())));
 }