/**
  * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event
  */
 public function onController(FilterControllerEvent $event)
 {
     if (!isset(static::$accessToken) || !static::$accessToken instanceof TokenInterface) {
         return;
     }
     $this->container->get('security.context')->setToken(static::$accessToken);
 }
Example #2
0
 /**
  * Get service
  *
  * @param string $service
  * @return mixed
  */
 public function getService($service)
 {
     if (!$this->container->hasService($service)) {
         throw new InvalidArgumentException("Service '{$service}' not found");
     }
     return $this->container->getService($service);
 }
Example #3
0
 /**
  * @return null
  */
 public function setUp()
 {
     $this->kernel = new \AppKernel('test', true);
     $this->kernel->boot();
     $this->container = $this->kernel->getContainer();
     $this->entityManager = $this->container->get('doctrine')->getEntityManager();
     $this->generateSchema();
     parent::setUp();
 }
Example #4
0
 protected function setUp()
 {
     $kernel = static::createKernel();
     $kernel->boot();
     $this->container = $kernel->getContainer();
     $this->sut = $this->container->get('social.abusereport.repository');
     $this->coll = $this->container->get('dokudoki.collection');
     $this->repo = $this->container->get('dokudoki.repository');
 }
 public function beforeTestMethod($method)
 {
     $this->kernel = new \AppKernel('test', true);
     $this->kernel->boot();
     // Store the container and the entity manager in test case properties
     $this->container = $this->kernel->getContainer();
     $managerRegistry = $this->container->get('doctrine');
     $this->collection = $managerRegistry->getRepository('AppBundle:Collection')->findOneBy(['collectioncode' => $this->collectionCode]);
     $this->genericEntityManager = new \AppBundle\Manager\GenericEntityManager($managerRegistry);
 }
Example #6
0
 /**
  *
  */
 public function setUp()
 {
     $this->kernel = new \AppKernel('test', true);
     $this->kernel->boot();
     // Store the container and the entity manager in test case properties
     $this->container = $this->kernel->getContainer();
     $this->entityManager = $this->container->get('doctrine')->getManager();
     // Build the schema for sqlite
     $this->generateSchema();
     parent::setUp();
 }
 public function createKernelMock($name)
 {
     $this->em = $this->createTestEntityManager();
     $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');
     $container = new \Symfony\Component\DependencyInjection\Container();
     $container->set(sprintf('doctrine.orm.%s_entity_manager', $name), $this->em);
     $container->set(sprintf('doctrine.dbal.%s_connection', $name), $this->em->getConnection());
     $kernel->expects($this->once())->method('getContainer')->will($this->returnValue($container));
     $kernel->expects($this->once())->method('getBundles')->will($this->returnValue(array()));
     return $kernel;
 }
 /**
  * Initialize kernel app and some Symfony2 services.
  *
  * @see \PHPUnit_Framework_TestCase::setUp()
  */
 protected function setUp()
 {
     // Boot the AppKernel in the test environment and with the debug.
     $this->kernel = new \AppKernel('test', true);
     $this->kernel->boot();
     // Store the container and the entity manager in test case properties
     $this->container = $this->kernel->getContainer();
     $this->entityManager = $this->container->get('doctrine')->getManager();
     $this->entityManager->getConnection()->beginTransaction();
     parent::setUp();
 }
Example #9
0
 /**
  * Get all controllers from all bundles.
  *
  * @return array Controllers list
  */
 protected function getControllers()
 {
     $controllers = array();
     $finder = new ControllerFinder();
     foreach ($this->container->get('kernel')->getBundles() as $bundle) {
         $found = $finder->getControllers($bundle);
         if (!empty($found)) {
             $controllers[$bundle->getName()] = $found;
         }
     }
     return $controllers;
 }
Example #10
0
 public function setUp()
 {
     require_once __DIR__ . '/Fixtures/app/AppKernel.php';
     // Boot the AppKernel in the test environment and with the debug.
     $this->kernel = new \Heri\Bundle\JobQueueBundle\Tests\AppKernel('test', true);
     $this->kernel->boot();
     $this->deleteTmpDir();
     // Store the container and the entity manager in test case properties
     $this->container = $this->kernel->getContainer();
     $this->em = $this->container->get('doctrine')->getManager();
     parent::setUp();
 }
 public function setUp()
 {
     // Boot the AppKernel in the test environment and with the debug.
     $this->myKernel = new \AppKernel('test', true);
     $this->myKernel->boot();
     // Store the container and the entity manager in test case properties
     $this->container = $this->myKernel->getContainer();
     $this->entityManager = $this->container->get('doctrine')->getManager();
     $this->tagRepository = $this->container->get('doctrine')->getRepository("AutomationBundle:Tag");
     // Build the schema for sqlite
     //$this->generateSchema();
     parent::setUp();
 }
Example #12
0
 /**
  * {@inheritDoc}
  *
  * @throws \LogicException When the container is not present yet.
  *
  * @throws IOException When the directory is not writable.
  */
 public function getLogDir()
 {
     if (!$this->container) {
         throw new \LogicException('The container has not been set yet.');
     }
     $logDir = $this->container->get('tenside.home')->homeDir() . '/tenside/logs';
     if (!is_dir($logDir)) {
         $fileSystem = new Filesystem();
         $fileSystem->mkdir($logDir);
     }
     if (!is_writable($logDir)) {
         throw new IOException(sprintf('The directory "%s" is not writable.', $logDir), 0, null, $logDir);
     }
     return $this->container->get('tenside.home')->homeDir() . '/tenside/logs';
 }
Example #13
0
 /**
  * Return the controller class name.
  *
  * @param $action
  */
 private function getControllerClass($action)
 {
     list($bundleName, $controllerName) = explode('_', $action);
     $bundleName .= 'Bundle';
     $bundle = $this->container->get('kernel')->getBundle($bundleName);
     $namespace = $bundle->getNamespace() . '\\Controller';
     $class = $namespace . '\\' . $controllerName . 'Controller';
     return $class;
 }
 public function testExecute()
 {
     $kernelMockBuilder = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel');
     $kernelMockBuilder->disableOriginalConstructor();
     $kernelMockBuilder->setMethods(['getContainer']);
     $kernelMock = $kernelMockBuilder->getMockForAbstractClass();
     $container = new \Symfony\Component\DependencyInjection\Container();
     $finderMockBuilder = $this->getMockBuilder(Finder::class);
     $finderMockBuilder->disableOriginalConstructor();
     $finderMockBuilder->setMethods(['find']);
     $finderMock = $finderMockBuilder->getMock();
     $finderMock->expects($this->once())->method('find')->willReturn([new \SplFileInfo('testFile')]);
     $container->set('myTestService', $finderMock);
     $kernelMock->expects($this->any())->method('getContainer')->willReturn($container);
     $application = new Application($kernelMock);
     $application->add(new FindCommand());
     $command = $application->find('potaka:search');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['service' => 'myTestService', 'directories' => '/tmp', 'content' => 'php']);
     $this->assertRegExp('/testFile/', $commandTester->getDisplay());
 }
Example #15
0
 /**
  * Resolve the called controller from action.
  * 
  * @param  string $action
  * @return <type>
  */
 private function resolveController($action)
 {
     list($bundleName, $controllerName) = explode('_', $action);
     $bundleName .= "Bundle";
     $bundle = $this->container->get('kernel')->getBundle($bundleName);
     $namespace = $bundle->getNamespace() . "\\Controller";
     $class = $namespace . "\\" . $controllerName . "Controller";
     try {
         $controller = new $class();
         if ($controller instanceof ContainerAware) {
             $controller->setContainer($this->container);
         }
         return $controller;
     } catch (Exception $e) {
         // todo: handle exception
     }
 }
Example #16
0
 public function getContentFields()
 {
     return $this->container->getParameter('fields');
 }
 public function beforeTestMethod($method)
 {
     $this->kernel = new \AppKernel('test', true);
     $this->kernel->boot();
     // Store the container and the entity manager in test case properties
     $this->container = $this->kernel->getContainer();
     $managerRegistry = $this->container->get('doctrine');
     $this->exportManager = new \AppBundle\Manager\ExportManager($managerRegistry, $this->container->get('session'), $this->container->get('genericentitymanager'), $this->container->getParameter('maxitemperpage')[1], $this->container->get('diff.computer'), $this->container->getParameter('user_group'));
     $user = new User('tpateffoz', $this->container->getParameter('api_recolnat_base_uri'), $this->container->getParameter('api_recolnat_user_path'), $this->container->getParameter('user_group'));
     $user->setExportPath($this->container->getParameter('export_path'));
     $collection = $this->container->get('utility')->getCollection('MHNAIX', 'AIX');
     $this->exportManager->init($user)->setCollection($collection);
 }
 public function get($serviceId)
 {
     return self::$container->get($serviceId);
 }