protected function setUp() { if (!class_exists('Assetic\\AssetManager')) { $this->markTestSkipped('Assetic is not available.'); } if (!class_exists('Twig_Environment')) { $this->markTestSkipped('Twig is not available.'); } $this->kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\KernelInterface')->getMock(); $this->container = new ContainerBuilder(); // Symfony 2.3 BC if (!method_exists('Symfony\\Component\\DependencyInjection\\Definition', 'setShared')) { $this->container->addScope(new Scope('request')); $this->container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request'); } // Symfony <2.7 BC if (class_exists('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\AssetsHelper')) { $this->container->register('assets.packages', $this->getMockClass('Symfony\\Component\\Asset\\Packages')); $this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\AssetsHelper'))->addArgument(new Reference('assets.packages')); } elseif (class_exists('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper')) { $this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Templating\\Asset\\PackageInterface'))); } $this->container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Routing\\RouterInterface'))); $this->container->register('twig', 'Twig_Environment')->addArgument(new Definition($this->getMockClass('Twig_LoaderInterface'))); $this->container->setParameter('kernel.bundles', array()); $this->container->setParameter('kernel.cache_dir', __DIR__); $this->container->setParameter('kernel.debug', false); $this->container->setParameter('kernel.root_dir', __DIR__); $this->container->setParameter('kernel.charset', 'UTF-8'); $this->container->set('kernel', $this->kernel); $this->container->addCompilerPass(new StaticAsseticHelperPass()); }
/** * @expectedException \RuntimeException * @group legacy */ public function testProcessDetectsCrossScopeHierarchyReference() { $container = new ContainerBuilder(); $container->addScope(new Scope('a')); $container->addScope(new Scope('b')); $container->register('a')->setScope('a')->addArgument(new Reference('b')); $container->register('b')->setScope('b'); $this->process($container); }
/** * {@inheritdoc} */ protected function setUp() { $this->requestMock = $this->getMock('Symfony\\Component\\HttpFoundation\\Request'); $this->container = new ContainerBuilder(); $this->container->addScope(new Scope('request')); $this->container->setParameter('templating.engines', array('php', 'twig')); $this->container->set('request', $this->requestMock); $this->container->registerExtension(new IvoryGoogleMapExtension()); $this->container->registerExtension($httpAdapterExtension = new WidopHttpAdapterExtension()); $this->container->loadFromExtension($httpAdapterExtension->getAlias()); }
protected function setUp() { $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface'); $this->container = new ContainerBuilder(); $this->container->addScope(new Scope('request')); $this->container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request'); $this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\AssetsHelper')); $this->container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Routing\\RouterInterface'))); $this->container->register('twig', 'Twig_Environment'); $this->container->setParameter('kernel.bundles', array()); $this->container->setParameter('kernel.cache_dir', __DIR__); $this->container->setParameter('webroot', __DIR__); $this->container->setParameter('kernel.debug', false); $this->container->setParameter('kernel.root_dir', __DIR__); $this->container->setParameter('kernel.charset', 'UTF-8'); $this->container->set('kernel', $this->kernel); }
/** * Tests the onKernelController method without a request scope. */ public function testWithoutRequestScope() { $this->container->addScope(new Scope(ContaoCoreBundle::SCOPE_BACKEND, 'request')); /** @var HttpKernelInterface $kernel */ $kernel = $this->getMockForAbstractClass('Symfony\\Component\\HttpKernel\\Kernel', ['test', false]); $listener = new ContainerScopeListener($this->container); $listener->onKernelRequest(new GetResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST)); $this->assertTrue($this->container->hasScope(ContaoCoreBundle::SCOPE_BACKEND)); $this->assertFalse($this->container->isScopeActive(ContaoCoreBundle::SCOPE_BACKEND)); }
/** * Tests the boot() method. */ public function testBoot() { $container = new ContainerBuilder(); $container->addScope(new Scope('request')); $bundle = new ContaoCoreBundle(); $bundle->setContainer($container); $bundle->boot(); $this->assertTrue($container->hasScope(ContaoCoreBundle::SCOPE_BACKEND)); $this->assertTrue($container->hasScope(ContaoCoreBundle::SCOPE_FRONTEND)); }
public function testProcessInlinesOnlyIfSameScope() { $container = new ContainerBuilder(); $container->addScope(new Scope('foo')); $a = $container->register('a')->setPublic(false)->setScope('foo'); $b = $container->register('b')->addArgument(new Reference('a')); $this->process($container); $arguments = $b->getArguments(); $this->assertEquals(new Reference('a'), $arguments[0]); $this->assertTrue($container->hasDefinition('a')); }
protected function createContainerMock($render) { $templatingMock = $this->getMockBuilder('Symfony\\Bundle\\TwigBundle\\TwigEngine')->disableOriginalConstructor()->getMock(); $templatingMock->expects($this->exactly($render))->method('render'); $container = new ContainerBuilder(); $container->set('templating', $templatingMock); $container->addScope(new Scope('request')); $container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request'); $container->enterScope('request'); return $container; }
protected function createContainerMock() { $container = new ContainerBuilder(); $container->addScope(new Scope('request')); $container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request'); $container->enterScope('request'); $container->set('templating', $this->createTemplatingMock()); $container->set('router', $this->createRouterMock()); $container->setParameter('thrace_media.jwplayer.options', array('key' => '123', 'html5player' => 'path_to_file', 'flashplayer' => 'path_to_file')); return $container; }
private function getContainer() { $container = new ContainerBuilder(); $container->addScope(new Scope('request')); $container->set('request', $this->request); $container->set('templating', $this->templating); $container->setParameter('kernel.bundles', array()); $container->setParameter('kernel.cache_dir', __DIR__); $container->setParameter('kernel.root_dir', __DIR__); $container->set('kernel', $this->kernel); return $container; }
protected function getContainerBuilder() { // \sys_get_temp_dir() $container = new ContainerBuilder(); $container->addScope(new Scope('request')); $container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request'); $container->setParameter('kernel.debug', false); $container->setParameter('kernel.root_dir', __DIR__ . '/temp'); $container->setParameter('kernel.cache_dir', __DIR__ . '/temp'); $container->setParameter('kernel.bundles', array()); return $container; }
private function getContainer() { $container = new ContainerBuilder(); $container->addScope(new Scope('request')); $container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request'); $container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\AssetsHelper')); $container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Routing\\RouterInterface'))); $container->register('twig', 'Twig_Environment'); $container->register('templating.engine.twig', $this->getMockClass('Symfony\\Bundle\\TwigBundle\\TwigEngine'))->addArgument($this->getMock('Twig_Environment'))->addArgument($this->getMock('Symfony\\Component\\Templating\\TemplateNameParserInterface'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Config\\FileLocatorInterface')))->addArgument($this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\GlobalVariables', array(), array($this->getMock('Symfony\\Component\\DependencyInjection\\Container')))); $container->setAlias('templating', 'templating.engine.twig'); $container->setParameter('kernel.bundles', array()); $container->setParameter('kernel.cache_dir', __DIR__); $container->setParameter('kernel.root_dir', __DIR__); $container->set('kernel', $this->kernel); return $container; }
<?php use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Scope; $container = new ContainerBuilder(); $container->addScope(new Scope('request')); $container->register('foo', 'FooClass')->setScope('request'); $container->compile(); return $container;
public function addScope(ScopeInterface $scope) { return $this->delegate->addScope($scope); }
private function cloneContainer() { $parameterBag = new ParameterBag($this->container->getParameterBag()->all()); $container = new ContainerBuilder($parameterBag); $container->setDefinitions($this->container->getDefinitions()); $container->setAliases($this->container->getAliases()); $container->setResources($this->container->getResources()); foreach ($this->container->getScopes() as $scope => $parentScope) { $container->addScope(new Scope($scope, $parentScope)); } foreach ($this->container->getExtensions() as $extension) { $container->registerExtension($extension); } return $container; }
public function build(ContainerBuilder $container) { // add request scope $container->addScope(new Scope('request')); }
public function testSynchronizedServiceWithScopes() { $container = new ContainerBuilder(); $container->addScope(new Scope('foo')); $container->register('baz', 'BazClass')->setSynthetic(true)->setSynchronized(true)->setScope('foo'); $container->register('bar', 'BarClass')->addMethodCall('setBaz', array(new Reference('baz', ContainerInterface::NULL_ON_INVALID_REFERENCE, false))); $container->compile(); $container->enterScope('foo'); $container->set('baz', $outerBaz = new \BazClass(), 'foo'); $this->assertSame($outerBaz, $container->get('bar')->getBaz()); $container->enterScope('foo'); $container->set('baz', $innerBaz = new \BazClass(), 'foo'); $this->assertSame($innerBaz, $container->get('bar')->getBaz()); $container->leaveScope('foo'); $this->assertNotSame($innerBaz, $container->get('bar')->getBaz()); $this->assertSame($outerBaz, $container->get('bar')->getBaz()); $container->leaveScope('foo'); }
/** * @param ContainerBuilder $container */ private function declareScenarioScope(ContainerBuilder $container) { if (!$container->hasScope('scenario')) { $container->addScope(new Scope('scenario')); } }