Returns the CookieJar instance.
public getCookieJar ( ) : Symfony\Component\BrowserKit\CookieJar | ||
Résultat | Symfony\Component\BrowserKit\CookieJar | A CookieJar instance |
public function _before(\Codeception\TestCase $test) { if (!$this->client) { if (!strpos($this->config['url'], '://')) { // not valid url foreach ($this->getModules() as $module) { if ($module instanceof \Codeception\Lib\Framework) { $this->client = $module->client; $this->isFunctional = true; break; } } } else { if (!$this->hasModule('PhpBrowser')) { throw new ModuleConfigException(__CLASS__, "For REST testing via HTTP please enable PhpBrowser module"); } $this->client = $this->getModule('PhpBrowser')->client; } if (!$this->client) { throw new ModuleConfigException(__CLASS__, "Client for REST requests not initialized.\nProvide either PhpBrowser module, or a framework module which shares FrameworkInterface"); } } $this->headers = array(); $this->params = array(); $this->response = ""; $this->client->setServerParameters(array()); if ($this->config['xdebug_remote'] && function_exists('xdebug_is_enabled') && xdebug_is_enabled() && ini_get('xdebug.remote_enable') && !$this->isFunctional) { $cookie = new Cookie('XDEBUG_SESSION', $this->config['xdebug_remote'], null, '/'); $this->client->getCookieJar()->set($cookie); } }
public function _before(\Codeception\TestCase $test) { $this->client =& $this->connectionModule->client; $this->resetVariables(); if ($this->config['xdebug_remote'] && function_exists('xdebug_is_enabled') && ini_get('xdebug.remote_enable') && !$this->isFunctional) { $cookie = new Cookie('XDEBUG_SESSION', $this->config['xdebug_remote'], null, '/'); $this->client->getCookieJar()->set($cookie); } }
protected function setCookiesFromOptions() { if (isset($this->config['cookies']) && is_array($this->config['cookies']) && !empty($this->config['cookies'])) { $domain = parse_url($this->config['url'], PHP_URL_HOST); $cookieJar = $this->client->getCookieJar(); foreach ($this->config['cookies'] as &$cookie) { if (!is_array($cookie) || !array_key_exists('Name', $cookie) || !array_key_exists('Value', $cookie)) { throw new \InvalidArgumentException('Cookies must have at least Name and Value attributes'); } if (!isset($cookie['Domain'])) { $cookie['Domain'] = $domain; } if (!isset($cookie['Expires'])) { $cookie['Expires'] = null; } if (!isset($cookie['Path'])) { $cookie['Path'] = '/'; } if (!isset($cookie['Secure'])) { $cookie['Secure'] = false; } if (!isset($cookie['HttpOnly'])) { $cookie['HttpOnly'] = false; } $cookieJar->set(new \Symfony\Component\BrowserKit\Cookie($cookie['Name'], $cookie['Value'], $cookie['Expires'], $cookie['Path'], $cookie['Domain'], $cookie['Secure'], $cookie['HttpOnly'])); } } }
public function logIn(Client $client) { $session = $client->getContainer()->get('session'); $firewall = 'admin'; $token = new UsernamePasswordToken('admin', null, $firewall, array('ROLE_USER')); $session->set('_security_' . $firewall, serialize($token)); $session->save(); $cookie = new Cookie($session->getName(), $session->getId()); $client->getCookieJar()->set($cookie); }
public function _before(\Codeception\TestCase $test) { if (!$this->client) { if (!strpos($this->config['url'], '://')) { // not valid url foreach ($this->getModules() as $module) { if ($module instanceof \Codeception\Util\Framework) { $this->client = $module->client; $this->is_functional = true; break; } } } else { if (!$this->hasModule('PhpBrowser')) { throw new ModuleConfigException(__CLASS__, "For REST testing via HTTP please enable PhpBrowser module"); } $this->client = $this->getModule('PhpBrowser')->session->getDriver()->getClient(); } if (!$this->client) { throw new ModuleConfigException(__CLASS__, "Client for REST requests not initialized.\nProvide either PhpBrowser module, or a framework module which shares FrameworkInterface"); } } $this->headers = array(); $this->params = array(); $this->response = ""; $this->client->setServerParameters(array()); $timeout = $this->config['timeout']; if ($this->config['xdebug_remote'] && function_exists('xdebug_is_enabled') && xdebug_is_enabled() && ini_get('xdebug.remote_enable')) { $cookie = new Cookie('XDEBUG_SESSION', $this->config['xdebug_remote'], null, '/'); $this->client->getCookieJar()->set($cookie); // timeout is disabled, so we can debug gently :) $timeout = 0; } if (method_exists($this->client, 'getClient')) { $clientConfig = $this->client->getClient()->getConfig(); $curlOptions = $clientConfig->get('curl.options'); $curlOptions[CURLOPT_TIMEOUT] = $timeout; $clientConfig->set('curl.options', $curlOptions); } }
/** * Create authorized client * * @link http://stackoverflow.com/questions/14957807/symfony2-tests-with-fosuserbundle/27223293#27223293 * @return Client */ public static function authorizeClient(Client $client) { $container = $client->getContainer(); $session = $container->get('session'); /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ $userManager = $container->get('fos_user.user_manager'); /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ $loginManager = $container->get('fos_user.security.login_manager'); $firewallName = $container->getParameter('fos_user.firewall_name'); /// @todo create fixture for this $testUser = $container->getParameter('test_user'); $user = $userManager->findUserBy(array('username' => $testUser)); $loginManager->loginUser($firewallName, $user); // save the login token into the session and put it in a cookie $token = $container->get('security.context')->getToken(); $session->set('_security_' . $firewallName, serialize($token)); $session->save(); $cookie = new Cookie($session->getName(), $session->getId()); $client->getCookieJar()->set($cookie); return $client; }
public function resetCookie($name) { $this->client->getCookieJar()->expire($name); $this->debugSection('Cookies', $this->client->getCookieJar()->all()); }
protected function debugCookieJar() { $cookies = $this->client->getCookieJar()->all(); $cookieStrings = array_map('strval', $cookies); $this->debugSection('Cookie Jar', $cookieStrings); }
public function resetCookie($name, array $params = []) { $params = array_merge($this->defaultCookieParameters, $params); $this->client->getCookieJar()->expire($name, $params['path'], $params['domain']); $this->debugSection('Cookies', $this->client->getCookieJar()->all()); }