/** * Generates a url from a given patch * * @param $path * @param $method * @return string */ protected function getUrlFromPath($path, $method = 'GET') { try { $baseUrl = $this->kernel->getContainer()->getParameter('router.request_context.base_url'); } catch (InvalidArgumentException $e) { $baseUrl = ''; } try { $host = $this->kernel->getContainer()->getParameter('router.request_context.host'); } catch (InvalidArgumentException $e) { $host = 'localhost'; } $requestContext = new RequestContext($baseUrl, $method, $host); $router = $this->getRouter(); $router->setContext($requestContext); $urlStack = parse_url($path); $info = $router->match($urlStack['path']); $route = $info['_route']; unset($info['_route']); $url = $this->getUrl($route, $info); if (isset($urlStack['query'])) { $url .= '?' . $urlStack['query']; } return $url; }
/** * Checks if the app can get the service from the container */ public function testServiceIsGettable() { $serviceCallableName = 'open_exchange_rates_service'; $this->assertTrue(static::$kernel->getContainer()->has($serviceCallableName)); static::$kernel->getContainer()->get($serviceCallableName); $this->assertTrue(true); }
public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); $routes = $this->router->getRouteCollection(); $route = $routes->get($request->attributes->get('_route')); if (!$route->getOption('requires_license')) { return; } if ('active' != $request->get('lic') && $this->kernel->getEnvironment() == 'prod') { // Checking for whitelisted users try { $user = $this->tokenStorage->getToken()->getUser(); $today = date('Y-m-d'); if ($user instanceof UserInterface) { $whitelist = $this->kernel->getContainer()->getParameter('license_whitelist'); foreach ($whitelist as $allowed) { if ($allowed['client_key'] == $user->getClientKey() && $today <= $allowed['valid_till']) { return; } } } } catch (\Exception $e) { // Do nothing } $url = $this->router->generate('atlassian_connect_unlicensed'); $response = new RedirectResponse($url); $event->setResponse($response); } }
/** * @Given the system should have the following internet profiles: * * @param PyStringNode $body * */ public function theSystemShouldHaveTheFollowingInternetProfiles(PyStringNode $body) { /** @var CollectProfilesTestWorker $collectProfilesTestWorker */ $collectProfilesTestWorker = $this->kernel->getContainer()->get('muchacuba.internet.collect_profiles_test_worker'); Assert::assertTrue((new SimpleFactory())->createMatcher()->match(iterator_to_array($collectProfilesTestWorker->collect()), (array) json_decode($body->getRaw(), true))); $this->rootContext->ignoreState('Muchacuba\\Internet\\Profile'); }
/** * @Given the system should have the following recharge card profiles debt operations */ public function theSystemShouldHaveTheFollowingDebtOperations(PyStringNode $body) { /** @var CollectOperationsTestWorker $collectOperationsTestWorker */ $collectOperationsTestWorker = $this->kernel->getContainer()->get('muchacuba.recharge_card.profile.debt.collect_operations_test_worker'); Assert::assertTrue((new SimpleFactory())->createMatcher()->match(iterator_to_array($collectOperationsTestWorker->collect()), (array) json_decode($body->getRaw(), true))); $this->rootContext->ignoreState('Muchacuba\\RechargeCard\\Profile\\Debt\\Operation'); }
/** * @param \Jarves\Configuration\Object[] $objects * @param OutputInterface $output * * @param bool $overwrite * @throws ModelBuildException */ public function build(array $objects, OutputInterface $output, $overwrite = false) { /** @var $jarves \Jarves\Jarves */ $jarves = $this->kernel->getContainer()->get('jarves'); $output->writeln('Propel Build'); foreach ($objects as $object) { if ($this->kernel->getContainer()->get($object->getStorageService()) instanceof \Jarves\Storage\Propel) { $output->write('Build object ' . $object->getId() . ' => ' . $object->getTable() . ' ... '); $bundlePath = $jarves->getBundleDir($object->getBundle()->getName()); $modelsFile = sprintf('%sResources/config/schema/%s.schema.xml', $bundlePath, strtolower($object->getTable())); if (!$overwrite && file_exists($modelsFile) && file_get_contents($modelsFile)) { $xml = @simplexml_load_file($modelsFile); if (false === $xml) { $errors = libxml_get_errors(); throw new ModelBuildException(sprintf('Parse error in %s: %s', $modelsFile, json_encode($errors, JSON_PRETTY_PRINT))); } } else { $xml = simplexml_load_string('<database></database>'); } $xml['namespace'] = $object->getBundle()->getNamespace() . '\\Model'; // $xml['package'] = $object->getBundle()->getNamespace() . '\\Model'; $xml['name'] = 'default'; $this->declareTable($xml, $object); if (!is_dir(dirname($modelsFile))) { mkdir(dirname($modelsFile), 0777, true); } file_put_contents($modelsFile, $this->getFormattedXml($xml)); $output->writeln($modelsFile . ' written.'); unset($xml); } } }
public function setUp() { static::$kernel = static::createKernel(); static::$kernel->boot(); $this->dm = static::$kernel->getContainer()->get('doctrine.odm.mongodb.document_manager'); parent::setUp(); }
/** * @Then /^у меня должна быть подписка на все активные ивенты$/ */ public function iMustHaveTicketForAllEvents() { $activeEvents = $this->kernel->getContainer()->get('doctrine')->getManager()->getRepository('StfalconEventBundle:Event')->findBy(array('active' => true)); $user = $this->kernel->getContainer()->get('fos_user.user_manager')->findUserByEmail('*****@*****.**'); $tickets = $this->kernel->getContainer()->get('doctrine')->getManager()->getRepository('StfalconEventBundle:Ticket')->findBy(array('user' => $user->getId())); assertEquals(count($tickets), count($activeEvents)); }
/** * @return string|null */ protected function getFallBackTheme() { if (null !== $this->kernel->getContainer()) { return $this->kernel->getContainer()->getParameter('fallback_theme'); } return null; }
/** * @Then the system should have the following info sms subscription low balance reminder logs: * * @param PyStringNode $body */ public function theSystemShouldHaveTheFollowingOperations(PyStringNode $body) { /** @var CollectLogsTestWorker $collectLogsTestWorker */ $collectLogsTestWorker = $this->kernel->getContainer()->get('muchacuba.info_sms.subscription.low_balance_reminder.collect_logs_test_worker'); Assert::assertTrue((new SimpleFactory())->createMatcher()->match(iterator_to_array($collectLogsTestWorker->collect()), (array) json_decode($body->getRaw(), true))); $this->rootContext->ignoreState('Muchacuba\\InfoSms\\Subscription\\LowBalanceReminder\\Log'); }
/** * @Given the system should have the following uniquenesses: */ public function theSystemShouldHaveTheFollowingUniquenesses(PyStringNode $body) { /** @var CollectUniquenessTestWorker $collectUniquenessTestWorker */ $collectUniquenessTestWorker = $this->kernel->getContainer()->get('cubalider.unique.collect_uniqueness_test_worker'); Assert::assertTrue((new SimpleFactory())->createMatcher()->match(iterator_to_array($collectUniquenessTestWorker->collect()), (array) json_decode($body->getRaw(), true))); $this->rootContext->ignoreState('Cubalider\\Uniqueness'); }
/** * @BeforeScenario */ public function init($event) { $this->translationsApi = $this->kernel->getContainer()->get('jlaso_translations.client.api'); $apiConfig = $this->kernel->getContainer()->getParameter('jlaso_translations_api_access'); $this->project_id = 1; // cuando se crea de cero siempre es el uno - $apiConfig['project_id']; $this->em = $this->kernel->getContainer()->get('doctrine.orm.default_entity_manager'); }
/** * @return ContainerInterface */ protected function getContainer() { if ($this->kernel === NULL) { $this->kernel = $this->createKernel(); $this->kernel->boot(); } return $this->kernel->getContainer(); }
private static function initKernel() { static::$kernel = static::createKernel(); static::$kernel->boot(); static::$container = static::$kernel->getContainer(); static::$doctrine = static::$container->get('doctrine'); static::$om = static::$doctrine->getManager(); }
/** * Build client * * @return $this Self object */ public function buildClient() { $this->kernel = new \AppKernel('test', false); $this->kernel->boot(); $this->session->clear(); $this->client = $this->kernel->getContainer()->get('test.client'); $this->environmentBuilder->setUp($this->kernel); }
/** * @return ContainerInterface */ private function getContainer() { if ($this->kernel === null) { $this->kernel = $this->createKernel(); $this->kernel->boot(); } return $this->kernel->getContainer(); }
/** * @Given /^there are following resources added to resource map$/ */ public function thereAreFollowingResourcesAddedToResourceMap(TableNode $resources) { foreach ($resources->getHash() as $resource) { expect($this->kernel->getContainer()->get('fsi_resource_repository.map_builder')->hasResource($resource['Key']))->toBe(true); if (isset($resource['Type'])) { expect($this->kernel->getContainer()->get('fsi_resource_repository.map_builder')->getResource($resource['Key']))->toBeAnInstanceOf(sprintf('FSi\\Bundle\\ResourceRepositoryBundle\\Repository\\Resource\\Type\\%sType', ucfirst($resource['Type']))); } } }
/** * Warms up the cache. * * @param string $cacheDir The cache directory */ public function warmUp($cacheDir) { $pages = $this->kernel->getContainer()->get('kunstmaan_extra.content_type')->getAllContentTypeClasses(); $pageparts = $this->kernel->getContainer()->getParameter('kunstmaan_page_part.page_parts_presets'); $classes = array_unique(array_filter(iterator_to_array($this->getClasses($pages, $pageparts)))); $controllerName = basename($this->path, '.php'); $code = $this->generateCode($classes, $controllerName); file_put_contents($this->path, $code); }
/** * @Then the system should have the following info sms message stats: * * @param PyStringNode $body */ public function theSystemShouldHaveTheFollowingStats(PyStringNode $body) { $expected = (array) json_decode($body->getRaw(), true); /** @var CollectStatsTestWorker $collectStatsTestWorker */ $collectStatsTestWorker = $this->kernel->getContainer()->get('muchacuba.info_sms.message.collect_stats_test_worker'); $actual = iterator_to_array($collectStatsTestWorker->collect()); (new SimpleFactory())->createMatcher()->match($actual, $expected) ?: (new \PHPUnit_Framework_Constraint_IsEqual($expected))->evaluate($actual); $this->rootContext->ignoreState('Muchacuba\\InfoSms\\Message\\Stat'); }
/** * @When the system has the following user accounts: * * @param PyStringNode $body */ public function theSystemHasTheFollowingUserAccounts(PyStringNode $body) { /** @var CreateAccountTestWorker $createAccountTestWorker */ $createAccountTestWorker = $this->kernel->getContainer()->get('muchacuba.user.create_account_test_worker'); $items = json_decode($body->getRaw(), true); foreach ($items as $item) { $createAccountTestWorker->create($item['id'], $item['username'], $item['password'], $item['roles']); } }
/** * @Given /^I have players:$/ */ public function iHavePlayers(TableNode $table) { $playerManager = $this->kernel->getContainer()->get('cytron_babitch.player.manager'); foreach ($table->getRows() as $row) { $player = new Player(); $player->setName($row[0]); $player->setEmail($row[1]); $playerManager->persist($player, true); } }
/** * @BeforeScenario */ public function resetSphinx() { if ($this->kernel->getContainer()->has('acts.sphinx_realtime.resetter')) { $resetter = $this->kernel->getContainer()->get('acts.sphinx_realtime.resetter'); $indexManager = $this->kernel->getContainer()->get('acts.sphinx_realtime.index_manager'); foreach ($indexManager->getIndexes() as $index) { $resetter->resetIndex($index->getId()); } } }
/** * @BeforeScenario */ public function beforeScen() { $loader = new Loader(); $this->getMainContext()->getSubcontext('DoctrineFixturesContext')->loadFixtureClass($loader, 'Stfalcon\\Bundle\\SponsorBundle\\DataFixtures\\ORM\\LoadEventSponsorData'); /** @var $em \Doctrine\ORM\EntityManager */ $em = $this->kernel->getContainer()->get('doctrine.orm.entity_manager'); $purger = new ORMPurger(); $executor = new ORMExecutor($em, $purger); $executor->purge(); $executor->execute($loader->getFixtures(), true); }
/** * Creates a Client. * * @param array $options An array of options to pass to the createKernel class * @param array $server An array of server parameters * * @return Client A Client instance */ protected static function createClient(array $options = array(), array $server = array()) { if (null !== static::$kernel) { static::$kernel->shutdown(); } static::$kernel = static::createKernel($options); static::$kernel->boot(); $client = static::$kernel->getContainer()->get('test.client'); $client->setServerParameters($server); return $client; }
public 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')->getEntityManager(); // Build the schema for sqlite $this->generateSchema(); parent::setUp(); }
/** * @Then I want the calculator result to be persisted */ public function iWantTheCalculatorResultToBePersisted() { $em = $this->kernel->getContainer()->get('doctrine')->getManager(); $results = $em->getRepository('AppBundle:Calculator')->findAll(); if (count($results) === 1 && $results[0] instanceof Calculator) { $calculator = $results[0]; if ($calculator->getResult() == $this->calculatorService->getResult()) { return true; } } throw new \Exception('Result not persisted'); }
protected function setUp() { if (!isset($this->serviceName)) { throw new Exception("Service name has to be set"); } $this->_kernel = $this->createKernel(); $this->_kernel->boot(); try { $this->manager = $this->_kernel->getContainer()->get($this->serviceName); } catch (ServiceNotFoundException $notFoundException) { throw new Exception("The service " . $this->serviceName . " has to be registered."); } }
/** * @BeforeScenario */ public function setUp() { Date::setTestingNow(new \DateTime("now")); $container = $this->kernel->getContainer(); $entityManager = $container->get('doctrine.orm.default_entity_manager'); $metadatas = $entityManager->getMetadataFactory()->getAllMetadata(); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $schemaTool->dropSchema($metadatas); $schemaTool->createSchema($metadatas); // Load fixtures here $entityManager->flush(); $entityManager->clear(); }
/** * @BeforeScenario */ public function beforeScenario(BeforeScenarioScope $scope) { if (file_exists(self::getConfigurationFile())) { unlink(self::getConfigurationFile()); } $this->clearDiCache(); $this->manager = $this->kernel->getContainer()->get('doctrine_phpcr.odm.document_manager'); $this->session = $this->manager->getPhpcrSession(); if ($this->session->getRootNode()->hasNode('tests')) { $this->session->removeItem('/tests'); $this->session->save(); } }
/** * Runs the current application. * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * * @return int */ public function doRun(InputInterface $input, OutputInterface $output) { // register commands $this->registerCommands(); // inject container $container = $this->kernel->getContainer(); foreach ($this->all() as $command) { if ($command instanceof ContainerAwareInterface) { $command->setContainer($container); } } return parent::doRun($input, $output); }