Returns the container.
public getContainer ( ) : Symfony\Component\DependencyInjection\ContainerInterface | ||
return | Symfony\Component\DependencyInjection\ContainerInterface |
public function setUp() { $this->client = static::createClient(); $this->client->followRedirects(); $this->container = $this->client->getContainer(); $this->loadFixtures($this->getFixtures()); }
public function testControllerNoticeToException() { $this->client = $this->createClient(); $errorOccured = false; $syslogProcessorMock = $this->getMockBuilder('Keboola\\Syrup\\Monolog\\Processor\\SyslogProcessor')->disableOriginalConstructor()->getMock(); $syslogProcessorMock->expects($this->any())->method("processRecord")->with($this->callback(function ($subject) use(&$errorOccured) { if ($subject['message'] == 'Notice: Undefined offset: 3') { $e = $subject['context']['exception']; $errorOccured = true; return $e instanceof \Symfony\Component\Debug\Exception\ContextErrorException; } return true; }))->willReturn(['level' => 100]); $container = $this->client->getContainer(); $container->set('syrup.monolog.syslog_processor', $syslogProcessorMock); $this->client->request('GET', '/tests/notice'); $response = $this->client->getResponse(); $responseJson = json_decode($response->getContent(), true); $this->assertEquals('error', $responseJson['status']); $this->assertEquals('Application error', $responseJson['error']); $this->assertEquals(500, $responseJson['code']); $this->assertArrayHasKey('exceptionId', $responseJson); $this->assertArrayHasKey('runId', $responseJson); $this->assertTrue($errorOccured); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); $this->client = static::createClient(); $this->twig = $this->client->getContainer()->get('twig'); $this->loginHelper = new LoginTestHelper($this->client); }
public static function setUpBeforeClass() { static::$client = static::createClient(); static::$router = self::$client->getContainer()->get('router'); static::$em = self::$client->getContainer()->get('doctrine.orm.entity_manager'); static::$container = self::getContainer(); }
public function testGetUnpublished() { /** @var $service PhpcrBlockLoader */ $service = $this->client->getContainer()->get('cmf.block.service'); $this->assertInstanceOf('Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\SimpleBlock', $service->load(array('name' => '/test/blocks/block-1'))); // this block is not published, should be empty $this->assertInstanceOf('Sonata\BlockBundle\Model\EmptyBlock', $service->load(array('name' => '/test/blocks/block-2'))); }
/** * {@inheritDoc} */ public function setUp() { $this->client = static::createClient(); $this->container = $this->client->getContainer(); $this->em = $this->container->get('doctrine')->getManager(); $this->validator = $this->container->get('validator'); $this->setCurrentShop(); }
protected function setUp() { static::$client = static::createClient(); $container = static::$client->getContainer(); $sapiToken = $container->getParameter('storage_api.test.token'); $sapiUrl = $container->getParameter('storage_api.test.url'); static::$client->setServerParameters(array('HTTP_X-StorageApi-Token' => $sapiToken)); }
protected function setUp() { if (!self::$container) { self::$client = static::createClient(); self::$container = self::$client->getContainer(); // self::loginAsUser(); } }
public function tearDown() { foreach ($this->client->getContainer()->getMockedServices() as $id => $service) { $this->client->getContainer()->unmock($id); } \Mockery::close(); $this->client = null; parent::tearDown(); }
public function setUp() { parent::setUp(); $this->client = static::createClient(); $this->client->restart(); if ($this->logger === null) { $this->logger = $this->client->getContainer()->get('monolog.logger.devel'); } }
protected function setUp() { parent::setUp(); $this->client = static::createClient(); $this->client->followRedirects(); $this->kern = $this->client->getKernel(); $this->container = $this->client->getContainer(); $this->em = $this->container->get('doctrine.orm.entity_manager'); }
private function executeCommand(Command $command, Input $input) { $command->setApplication($this->application); $input->setInteractive(false); if ($command instanceof ContainerAwareCommand) { $command->setContainer($this->client->getContainer()); } $command->run($input, new NullOutput()); }
/** * @return \Symfony\Bundle\FrameworkBundle\Client */ protected static function getInitClient() { if (self::$client) { return self::$client; } self::$client = self::createClient(); static::$kernel = self::$client->getKernel(); self::$container = self::$client->getContainer(); return self::$client; }
/** * */ protected function signInAsAdmin() { $session = $this->client->getContainer()->get('session'); $firewall = 'main'; $token = new UsernamePasswordToken('admin', null, $firewall, array('ROLE_ADMIN')); $session->set('_security_' . $firewall, serialize($token)); $session->save(); $cookie = new Cookie($session->getName(), $session->getId()); $this->client->getCookieJar()->set($cookie); }
/** * @param User $user */ protected function logIn(User $user) { $session = $this->client->getContainer()->get('session'); $firewall = 'main'; $token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles()); $session->set('_security_' . $firewall, serialize($token)); $session->save(); $cookie = new Cookie($session->getName(), $session->getId()); $this->client->getCookieJar()->set($cookie); }
public function setUp() { self::$client = static::createClient(); $container = static::$client->getContainer(); $request = Request::create('/syrup/run', 'POST'); $container->get('request_stack')->push($request); $this->controller = new ApiController(); $this->controller->setContainer($container); $this->container = $container; }
public function setUp() { self::$client = static::createClient(); $container = static::$client->getContainer(); $request = Request::create('/syrup/run', 'POST'); $request->headers->set('X-StorageApi-Token', $container->getParameter('storage_api.test.token')); $container->get('request_stack')->push($request); $this->controller = new ApiController(); $this->controller->setContainer($container); $this->container = $container; }
/** {@inheritdoc} */ public function setUp() { $this->client = $this->createClient(); $this->container = $this->client->getContainer(); $application = new Application(); $mysqlDumperCommand = new MysqlDumperCommand(); $mysqlDumperCommand->setContainer($this->container); $application->add($mysqlDumperCommand); $this->command = $application->find('cdwv:database:dump'); $this->commandTester = new CommandTester($this->command); }
/** * @return bool */ public function isElasticSearchAvailable() { try { $info = $this->client->getContainer()->get('elasticsearch.client')->info(); if (!isset($info['status']) || $info['status'] !== 200) { return false; } } catch (\Exception $e) { return false; } return true; }
protected function logIn() { $session = $this->client->getContainer()->get('session'); $userManager = $this->client->getContainer()->get('fos_user.user_manager'); $user = $userManager->findUserByUsername('admin'); $firewall = 'main'; $token = new UsernamePasswordToken($user, null, $firewall, array('ROLE_ADMIN')); $session->set('_security_' . $firewall, serialize($token)); $session->save(); $cookie = new Cookie($session->getName(), $session->getId()); $this->client->getCookieJar()->set($cookie); }
public function testFind() { $container = $this->client->getContainer(); $fakeDirectoryUser = ['firstName' => 'first', 'lastName' => 'last', 'email' => 'email', 'telephoneNumber' => 'phone', 'campusId' => 'abc']; $mockUser = m::mock('Ilios\\CoreBundle\\Entity\\User')->shouldReceive('getCampusId')->once()->andReturn('abc')->mock(); $container->mock('ilioscore.directory', 'Ilios\\CoreBundle\\Service\\Directory')->shouldReceive('findByCampusId')->with('abc')->once()->andReturn($fakeDirectoryUser); $container->mock('ilioscore.user.manager', 'Ilios\\CoreBundle\\Entity\\Manager\\User')->shouldReceive('findOneBy')->with(['id' => 1])->once()->andReturn($mockUser); $this->makeJsonRequest($this->client, 'GET', $this->getUrl('ilios_web_directory_find', ['id' => '1']), null, $this->getAuthenticatedUserToken()); $response = $this->client->getResponse(); $content = $response->getContent(); $this->assertEquals(Codes::HTTP_OK, $response->getStatusCode(), var_export($content, true)); $this->assertEquals(array('result' => $fakeDirectoryUser), json_decode($content, true), var_export($content, true)); }
/** * Test form login with invalid user */ public function testLoginWithInvalidUser() { $userName = '******'; $password = '******'; $crawler = $this->client->request('GET', '/login'); $form = $crawler->selectButton('Log in')->form(); $form['_username'] = $userName; $form['_password'] = $password; $this->client->submit($form); $this->assertEquals(302, $this->client->getResponse()->getStatusCode()); $token = $this->client->getContainer()->get('security.token_storage')->getToken(); $this->assertNull($token); }
protected function logIn(Client $client) { $em = $client->getContainer()->get('doctrine')->getManager(); $user = $em->getRepository('VidalMainBundle:User')->findOneByUsername('*****@*****.**'); $session = $client->getContainer()->get('session'); $firewall = 'everything'; $token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles()); $token->setUser($user); $session->set('_security_' . $firewall, serialize($token)); $session->save(); $cookie = new Cookie($session->getName(), $session->getId()); $client->getCookieJar()->set($cookie); }
public static function setUpBeforeClass() { self::$client = static::createClient(); self::$container = self::$client->getContainer(); self::$hasDefinitions = self::$container->hasParameter('featureTypes'); self::$definitions = self::$hasDefinitions ? self::$container->getParameter('featureTypes') : array(); if (!self::$hasDefinitions) { self::markTestSkipped("No feature declaration found"); return; } self::$featureType = self::$container->get('features')->get(key(self::$definitions)); self::$fieldName = current(self::$featureType->getFields()); }
/** * Authenticate selected user. * If you want to test another firewall, look name for it * in the security.yml file for "context" value. * * @param $userName * @param $roles * @param null $firewallName * @return \FOS\UserBundle\Model\UserInterface */ protected function authenticateUser($userName, $roles, $firewallName = null) { $session = $this->client->getContainer()->get('session'); if (!$firewallName) { $firewallName = $this->getFirewallName(); } $user = $this->container->get('fos_user.user_manager')->findUserByUsername($userName); $token = new UsernamePasswordToken($user, null, $firewallName, $roles); $session->set('_security_' . $firewallName, serialize($token)); $session->save(); $cookie = new Cookie($session->getName(), $session->getId()); $this->client->getCookieJar()->set($cookie); return $user; }
/** * Log user with username */ protected function logIn() { $container = $this->client->getContainer(); $userManager = $container->get('fos_user.user_manager'); $user = $userManager->findUserByUsername($this->username); $session = $this->client->getContainer()->get('session'); $firewall = 'openorchestra'; $token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles()); $session->set('_security_' . $firewall, serialize($token)); $session->save(); $container->get('fos_user.security.login_manager')->logInUser($firewall, $user); $cookie = new Cookie($session->getName(), $session->getId()); $this->client->getCookieJar()->set($cookie); }
public function testExecute() { $this->client = $this->getClient(); $mockedProducer = $this->prophet->prophesize('\\OldSound\\RabbitMqBundle\\RabbitMq\\Producer'); $container = $this->client->getContainer(); $container->set('old_sound_rabbit_mq.weaving_the_web_amqp.twitter.user_status_producer', $mockedProducer); $this->commandClass = $this->getParameter('weaving_the_web_amqp.produce_lists_members_command.class'); $this->setUpApplicationCommand(); $this->commandTester = $this->getCommandTester('wtw:amqp:tw:prd:lm'); $options = ['command' => $this->getCommandName(), '--screen_name' => 'Firefox', '--list' => 'Type']; $this->commandTester->execute($options); $commandDisplay = $this->commandTester->getDisplay(); $this->assertNotContains('Exception', $commandDisplay); }
private function logClient(User $user, Client $client, $firewall = 'main') { $tokenStorage = $client->getContainer()->get('security.token_storage'); $token = new UsernamePasswordToken($user, $user->getPlainPassword(), $firewall, $user->getRoles()); $tokenStorage->setToken($token); //now we generate the cookie ! //@see http://symfony.com/doc/current/cookbook/testing/simulating_authentication.html $session = $client->getContainer()->get('session'); $session->set('_security_' . $firewall, serialize($token)); $session->save(); $cookie = new Cookie($session->getName(), $session->getId()); $client->getCookieJar()->set($cookie); return $client; }
/** * @Given I am authenticated as :login */ public function iAmAuthenticatedAs($login) { /** @var User $user */ $user = $this->getContainer()->get('fos_user.user_manager')->findUserByUsername($login); $session = $this->client->getContainer()->get('session'); $this->client->getCookieJar()->set(new Cookie($session->getName(), true)); $firewall = 'main'; $token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles()); $this->getContainer()->get('security.context')->setToken($token); $session->set('_security_' . $firewall, serialize($token)); $session->save(); $cookie = new Cookie($session->getName(), $session->getId()); $this->client->getCookieJar()->set($cookie); }
/** * Setup HTTP client, command runner and Storage API client for each test */ protected function setUp() { $this->httpClient = static::createClient(); $container = $this->httpClient->getContainer(); if (!$this->storageApiToken) { $this->storageApiToken = $container->getParameter('storage_api.test.token'); } $this->httpClient->setServerParameters(['HTTP_X-StorageApi-Token' => $this->storageApiToken]); $this->jobMapper = $container->get('syrup.elasticsearch.current_component_job_mapper'); $application = new Application($this->httpClient->getKernel()); $application->add(new JobCommand()); $command = $application->find('syrup:run-job'); $this->commandTester = new CommandTester($command); $this->storageApiClient = new StorageApiClient(['token' => $this->storageApiToken, 'url' => $container->getParameter('storage_api.test.url')]); }