本文整理汇总了PHP中Symfony\Component\BrowserKit\Client::getCookieJar方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getCookieJar方法的具体用法?PHP Client::getCookieJar怎么用?PHP Client::getCookieJar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\BrowserKit\Client
的用法示例。
在下文中一共展示了Client::getCookieJar方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _before
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);
}
}
示例2: _before
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);
}
}
示例3: setCookiesFromOptions
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']));
}
}
}
示例4: logIn
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);
}
示例5: _before
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);
}
}
示例6: authorizeClient
/**
* 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;
}
示例7: resetCookie
public function resetCookie($name)
{
$this->client->getCookieJar()->expire($name);
$this->debugSection('Cookies', $this->client->getCookieJar()->all());
}
示例8: debugCookieJar
protected function debugCookieJar()
{
$cookies = $this->client->getCookieJar()->all();
$cookieStrings = array_map('strval', $cookies);
$this->debugSection('Cookie Jar', $cookieStrings);
}
示例9: resetCookie
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());
}