/** * {@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 testDumpContainerCompile() { $this->assertFalse($this->dump['is_compiled']); $this->dump = unserialize($this->dumper->dump(['do_compile' => true])); $this->assertTrue($this->dump['is_compiled']); $this->assertTrue($this->container->isFrozen()); }
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()); }
/** * 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()); }
/** * Replace services and container parameters keys by their values for the provided section. * * @param string|null $section The selected configuration section, can be null * * @return array */ private function compileParameters($section = null) { if (null === $section) { return $this->compileAllParameters(); } if (!array_key_exists($section, $this->raw_parameters)) { return; } if (!array_key_exists($section, $this->parameters)) { $value = $this->raw_parameters[$section]; if (is_array($value)) { array_walk_recursive($value, array($this->container, 'getContainerValues')); } else { $this->container->getContainerValues($value); } $this->parameters[$section] = $value; } return $this->parameters[$section]; }
/** * @depends testGetContainerWithContextAndEnvironmentAndDebugFalse * * @covers ::tryParseContainerDump */ public function testDumpAndRestoreContainer(Container $container) { $dump_directory = $container->getParameter('container.dump_directory'); $dump_filename = $container->getParameter('container.filename'); $dumper = new PhpArrayDumper($container); $dump = $dumper->dump(array('do_compile' => true)); $container_proxy = new ContainerProxy(); $dump = unserialize($dump); $container_proxy->init($dump); $container_proxy->setParameter('services_dump', serialize($dump['services'])); $container_proxy->setParameter('is_compiled', $dump['is_compiled']); file_put_contents($dump_directory . DIRECTORY_SEPARATOR . $dump_filename . '.php', (new PhpDumper($container_proxy))->dump(array('class' => $dump_filename, 'base_class' => 'BackBee\\DependencyInjection\\ContainerProxy'))); $this->assertFileExists($dump_directory . DIRECTORY_SEPARATOR . $dump_filename . '.php'); $this->assertTrue(is_readable($dump_directory . DIRECTORY_SEPARATOR . $dump_filename . '.php')); $this->application->setContext('test'); $this->application->setEnvironment('test'); $this->application->setRepository($this->application->getBaseRepository() . DIRECTORY_SEPARATOR . $this->application->getContext()); $container_builder = new ContainerBuilder($this->application); $container_proxy = $container_builder->getContainer(); $this->assertInstanceOf($dump_filename, $container_proxy); $this->assertInstanceOf('BackBee\\DependencyInjection\\ContainerProxy', $container_proxy); }
/** * Test config with container. * * @covers ::setContainer * @covers ::getRawSection * @covers ::compileParameters * @covers ::compileAllParameters */ public function testConfigWithContainer() { $container = new Container(); $container->setParameter('brand', 'LP Digital'); $config = new Config(realpath($this->test_base_dir . '/test_container')); $this->assertEquals($config->getSection('parameters'), array('brand' => '%brand%')); $config->setContainer($container); $this->assertEquals($config->getRawSection('parameters'), array('brand' => '%brand%')); $this->assertEquals($config->getSection('parameters'), array('brand' => 'LP Digital')); }
/** * @see Symfony\Component\DependencyInjection\ContainerBuilder::getDefinitions */ public function getDefinitions() { $this->loadRawDefinitions(); return parent::getDefinitions(); }