Пример #1
0
 /**
  * test every new and overrided method provided by BackBee\DependencyInjection\Container.
  *
  * @covers ::get
  * @covers ::getContainerValues
  * @covers ::getContainerParameters
  * @covers ::getContainerServices
  * @covers ::isLoaded
  */
 public function testContainerOverridedAndNewMethods()
 {
     // build container to apply every tests on
     $container = new Container();
     // setting random parameters
     $container->setParameter('random_parameter', 'this is a test');
     // creating a definition without any tag (definition of service with id `date_without_tag`)
     $definition = new Definition('DateTime');
     $container->setDefinition('date_without_tag', $definition);
     // creating a definition with one tag, `test` (definition of service with id `date_with_tag`)
     $definition = new Definition('BackBee\\DependencyInjection\\Tests\\ContainerTest_Resources\\DateTime');
     $definition->addTag('test');
     $container->setDefinition('date_with_tag', $definition);
     // creating a definition for a synthetic service (definition of service with id `synthetic_service`)
     $definition = new Definition();
     $definition->setSynthetic(true);
     $container->setDefinition('synthetic_service', $definition);
     // setting into container a service as listener with id `listener`
     $container->set('listener', new TestListener());
     // creating a new event dispatcher and prepare it for testing the dispatch of event on get of tagged service
     // from the container
     $event_dispatcher = new Dispatcher();
     $event_dispatcher->setContainer($container);
     $event_dispatcher->addListener('service.tagged.test', array('@listener', 'onGetServiceTaggedTestEvent'));
     $container->set('event.dispatcher', $event_dispatcher);
     // basic test for the listener
     $this->assertEquals('bar', $container->get('listener')->getFoo());
     // tests of Container::isLoaded() method
     $this->assertFalse($container->isLoaded('date_without_tag'));
     $container->get('date_without_tag');
     $this->assertTrue($container->isLoaded('date_without_tag'));
     // checks that getting a service without the `test` tag won't change listener's foo value
     $this->assertEquals('bar', $container->get('listener')->getFoo());
     // tests to get a service with tag to check if the value of foo from listener has changed
     // and if the timestamp of the service `date_with_tag` has changed correctly
     $container->get('date_with_tag');
     $this->assertEquals('foo', $container->get('listener')->getFoo());
     $this->assertEquals(self::NEW_DATE_WITH_TAG_VALUE, $container->get('date_with_tag')->getTimestamp());
     // tests that if we get a synthetic service which we didn't define it yet Container::get() will return null
     $this->assertEquals(null, $container->get('synthetic_service'));
     // test for Container::getContainerValues()
     $paramter_key_string = '%random_parameter%';
     $this->assertEquals('this is a test', $container->getContainerValues($paramter_key_string));
     $service_string_id = '@listener';
     $this->assertEquals($container->get('listener')->getFoo(), $container->getContainerValues($service_string_id)->getFoo());
     // Test that there is no events to dispatch if the tag name is `dumpable`
     $container->set('listener', new TestListener());
     $event_dispatcher->addListener('service.tagged.dumpable', array('@listener', 'onGetServiceTaggedTestEvent'));
     $definition = new Definition('DateTime');
     $definition->addTag('dumpable', array('dispatch_event' => false));
     $container->setDefinition('dumpable_date', $definition);
     $container->get('dumpable_date');
     $this->assertEquals('bar', $container->get('listener')->getFoo());
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $definition = new Definition('BackBee\\Bundle\\ToolbarBundle\\Tests\\Plugin\\TestPlugin');
     $container = new Container();
     $container->setDefinition('test_plugin', $definition->addTag(PluginManager::PLUGIN_SERVICE_TAG));
     $this->plugin_manager = new PluginManager($container);
     $this->controller = new ConfigController(new Config(__DIR__), $this->plugin_manager);
 }
 public function testGetPluginConfiguration()
 {
     $definition = new Definition(__NAMESPACE__ . '\\TestPlugin');
     $definition->addTag(PluginManager::PLUGIN_SERVICE_TAG);
     $this->container->setDefinition('test_plugin', $definition->setArguments(['test_plugin']));
     $definition = new Definition(__NAMESPACE__ . '\\TestPlugin');
     $definition->addTag(PluginManager::PLUGIN_SERVICE_TAG);
     $this->container->setDefinition('another_test_plugin', $definition->setArguments(['another_test_plugin']));
     $this->assertEquals(['plugin' => ['namespace' => ['test_plugin' => TestPlugin::TEST_NAMESPACE, 'another_test_plugin' => TestPlugin::TEST_NAMESPACE], 'config' => ['test_plugin' => TestPlugin::$test_configuration, 'another_test_plugin' => TestPlugin::$test_configuration]]], $this->plugin_manager->getPluginConfiguration());
 }
Пример #4
0
 public function testNotDumpableService()
 {
     $id = 'not.dumpable_service';
     $definition = new Definition();
     $definition->setClass('DateTime');
     $definition->addTag('dumpable');
     $definition->addArgument('now');
     $definition->addArgument(new Reference('timezone'));
     $this->container->setDefinition($id, $definition);
     $not_dumpable_service = $this->container->get($id);
     try {
         $this->dumper->dump();
         $this->fail('Raise of ServiceNotDumpableException expected.');
     } catch (\Exception $e) {
         $this->assertInstanceOf('BackBee\\DependencyInjection\\Exception\\ServiceNotDumpableException', $e);
     }
 }