Example #1
0
 /**
  * @param ContainerBuilder $container
  * @param array $loggerStore
  * @param float $totalTime
  */
 private function logResult(ContainerBuilder $container, array $loggerStore, float $totalTime)
 {
     $container->reset();
     /** @var Logger $logger */
     $logger = $container->get('logger');
     $logger->debug('DIC: start', ['channel' => 'dic']);
     foreach ($loggerStore as $log) {
         $logger->debug($log, ['channel' => 'dic']);
     }
     $logger->debug(sprintf('DIC: %0.2fms total time', $totalTime * 1000), ['channel' => 'dic']);
 }
Example #2
0
 protected function getContainer()
 {
     if (isset(self::$containers[$this->getTestBasePath()])) {
         // Use cached container (creating a new container from yml is too slow)
         $this->setContainer(self::$containers[$this->getTestBasePath()]);
         $this->container->reset();
         $this->configureContainer();
     } elseif (!$this->container) {
         // Create new container
         $this->setContainer(new ContainerBuilder());
         $this->configureContainer();
         $locator = new FileLocator($this->getTestBasePath());
         $this->loader = new YamlFileLoader($this->container, $locator);
         $this->loader->load('config.yml');
         try {
             $this->loader->load('config.local.yml');
         } catch (\InvalidArgumentException $e) {
             // No local config found
         }
         // Cache container
         self::$containers[$this->getTestBasePath()] = $this->container;
     }
     return $this->container;
 }
Example #3
0
 public function testContainerWithoutCloning()
 {
     $container = new ContainerBuilder();
     $locator = new FileLocator(__DIR__);
     $loader = new YamlFileLoader($container, $locator);
     $loader->load('container.yml');
     $container->setParameter('fixture.path', __DIR__ . '/foo/');
     $container->setParameter('base.path', __DIR__);
     $this->assertEquals(__DIR__ . '/foo/', $container->getParameter('fixture.path'));
     $this->assertEquals(__DIR__, $container->getParameter('base.path'));
     $buzz = $container->get('buzz.fixture');
     $this->assertInstanceOf('TestTools\\Buzz\\Client', $buzz);
     $this->assertEquals($container->getParameter('fixture.path'), $buzz->getFixturePath());
     $container->reset();
     $container->setParameter('fixture.path', __DIR__ . '/bar/');
     $container->setParameter('base.path', __DIR__);
     $this->assertEquals(__DIR__ . '/bar/', $container->getParameter('fixture.path'));
     $this->assertEquals(__DIR__, $container->getParameter('base.path'));
     $buzz = $container->get('buzz.fixture');
     $this->assertInstanceOf('TestTools\\Buzz\\Client', $buzz);
     $this->assertEquals($container->getParameter('fixture.path'), $buzz->getFixturePath());
 }