protected function loadConfiguration($container, $array, $compile = true)
 {
     $extension = new SynchronizedExtension();
     $extension->load($array, $container);
     $container->registerExtension($extension);
     $container->addDefinitions(array('test_service' => new Definition('Emag\\SynchronizedBundle\\Tests\\Stubs\\TestService')));
     $bundle = new SynchronizedBundle();
     $bundle->build($container);
     $compile && $container->compile();
     return $container;
 }
 public function testLoadLogger()
 {
     $container = $this->getContainer();
     $container->addDefinitions(array('test_service' => new Definition('Emag\\SynchronizedBundle\\Tests\\Stubs\\TestService')));
     $loggerDefinition = new Definition('Emag\\SynchronizedBundle\\Tests\\Stubs\\TestLogger');
     $container->addDefinitions(array('logger' => $loggerDefinition));
     $extension = new SynchronizedExtension();
     $extension->load(array(array('locks' => array('lock1' => array('service' => 'test_service', 'method' => 'doNothing', 'driver' => 'debug')))), $container);
     $container->registerExtension($extension);
     $container->compile();
     $testService = $container->get('test_service');
     $logger = $container->get('logger');
     $testService->doNothing();
     $this->assertEquals($this->expectedLogs, $logger->getLogs());
 }
 public function testGetLockEvents()
 {
     $container = $this->getContainer();
     $container->addDefinitions(array('test_service' => new Definition('Emag\\SynchronizedBundle\\Tests\\Stubs\\TestService')));
     $eventDispatcherDefinition = new Definition('Emag\\SynchronizedBundle\\Tests\\Stubs\\TestEventDispatcher');
     $container->addDefinitions(array('event_dispatcher' => $eventDispatcherDefinition));
     $extension = new SynchronizedExtension();
     $extension->load(array(array('locks' => array('lock1' => array('service' => 'test_service', 'method' => 'doNothing', 'driver' => 'debug')))), $container);
     $container->registerExtension($extension);
     $container->compile();
     $testService = $container->get('test_service');
     $eventDispatcher = $container->get('event_dispatcher');
     $testService->doNothing();
     $events = $eventDispatcher->getEvents();
     $this->assertArrayHasKey(LockEvent::EVENT_BEFORE_GET_LOCK, $events);
     $this->assertArrayHasKey(LockEvent::EVENT_SUCCESS_GET_LOCK, $events);
     $this->assertArrayHasKey(LockEvent::EVENT_BEFORE_RELEASE_LOCK, $events);
     $this->assertArrayHasKey(LockEvent::EVENT_AFTER_RELEASE_LOCK, $events);
     $event = $events[LockEvent::EVENT_BEFORE_GET_LOCK];
     $this->assertEquals($event->getLock()->getMethod(), 'doNothing');
     $this->assertTrue($event->getDecorated() instanceof TestService);
 }