当前位置: 首页>>代码示例>>PHP>>正文


PHP BrowserKit\Client类代码示例

本文整理汇总了PHP中Symfony\Component\BrowserKit\Client的典型用法代码示例。如果您正苦于以下问题:PHP Client类的具体用法?PHP Client怎么用?PHP Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Initializes Goutte driver.
  *
  * @param Symfony\Component\BrowserKit\Client $client BrowserKit client instance
  */
 public function __construct(Client $client = null)
 {
     // create new kernel, that could be easily rebooted
     $class = get_class($client->getKernel());
     $kernel = new $class('Behat', 'config.yml', $client->getKernel()->getEnvironment(), $client->getKernel()->isDebug());
     $kernel->boot();
     parent::__construct($kernel->getContainer()->get('test.client'));
 }
开发者ID:rampelli,项目名称:FOSCommentBundle,代码行数:13,代码来源:SymfonyDriver.php

示例2: __construct

 /**
  * Initializes BrowserKit driver.
  *
  * @param Client      $client  BrowserKit client instance
  * @param string|null $baseUrl Base URL for HttpKernel clients
  */
 public function __construct(Client $client, $baseUrl = null)
 {
     $this->client = $client;
     $this->client->followRedirects(true);
     if ($baseUrl !== null && $client instanceof HttpKernelClient) {
         $client->setServerParameter('SCRIPT_FILENAME', parse_url($baseUrl, PHP_URL_PATH));
     }
 }
开发者ID:penguinclub,项目名称:penguinweb_drupal8,代码行数:14,代码来源:BrowserKitDriver.php

示例3: testIndex

 public function testIndex()
 {
     $this->client = static::createClient();
     $this->client->setServerParameters(['CONTENT_TYPE' => 'application/json', 'HTTP_HOST' => 'localhost:8000']);
     // create user
     $userName = md5(microtime());
     $registration = $this->makeRequest('/user/create', ["user" => ["name" => $userName]]);
     $this->assertEquals($registration->getMessage(), 'Ok');
     $userId = $registration->getData()->id;
     // try to create duplicate
     $registration = $this->makeRequest('/user/create', ["user" => ["name" => $userName]]);
     $this->assertEquals($registration->getMessage(), 'User already exists');
     // create opponents
     for ($i = 0; $i <= 10; $i++) {
         $registration = $this->makeRequest('/user/create', ["user" => ["name" => md5(microtime() + $i)]]);
         $this->assertEquals($registration->getMessage(), 'Ok');
     }
     // login
     $login = $this->makeRequest('/user/login', ["token" => $userName]);
     $this->assertEquals($login->getMessage(), 'Ok');
     $this->assertEquals($login->getData()->id, $userId);
     // opponent
     $opponents = $this->makeRequest('/user/opponents', ["token" => $userName]);
     $this->assertEquals($opponents->getMessage(), 'Ok');
     $opponentId = $opponents->getData()[0]->id;
     $opponentName = $opponents->getData()[0]->name;
     // invite
     $response = $this->makeRequest('/combat/invite', ["token" => $userName, "id" => $opponentId]);
     $this->assertEquals($response->getMessage(), 'Ok');
     $combatId = $response->getData()->combatId;
     $attackFirst = $response->getData()->youFirst;
     // attack
     $response = $this->makeRequest('/combat/attack', ["token" => $attackFirst ? $opponentName : $userName, "combatId" => $combatId, "skillId" => 2]);
     $this->assertEquals($response->getMessage(), 'It is not your turn');
     // attack
     $response = $this->makeRequest('/combat/attack', ["token" => $attackFirst ? $userName : $opponentName, "combatId" => $combatId, "skillId" => 2]);
     $this->assertEquals($response->getMessage(), 'Ok');
     // attack
     $response = $this->makeRequest('/combat/attack', ["token" => $attackFirst ? $opponentName : $userName, "combatId" => $combatId, "skillId" => 2]);
     $this->assertEquals($response->getMessage(), 'This skill already used');
     // collect
     $response = $this->makeRequest('/combat/collect', ["token" => $attackFirst ? $opponentName : $userName, "combatId" => $combatId]);
     $this->assertEquals($response->getMessage(), 'Combat is not finished');
     // attack
     $response = $this->makeRequest('/combat/attack', ["token" => $attackFirst ? $opponentName : $userName, "combatId" => $combatId, "skillId" => 1]);
     $this->assertEquals($response->getMessage(), 'Ok');
     // attack
     $response = $this->makeRequest('/combat/attack', ["token" => $attackFirst ? $userName : $opponentName, "combatId" => $combatId, "skillId" => 3]);
     $this->assertEquals($response->getMessage(), 'Ok');
     // attack
     $response = $this->makeRequest('/combat/attack', ["token" => $attackFirst ? $opponentName : $userName, "combatId" => $combatId, "skillId" => 1]);
     $this->assertEquals($response->getMessage(), 'Combat was finished');
     // collect
     $response = $this->makeRequest('/combat/collect', ["token" => $opponentName, "combatId" => $combatId]);
     // collect
     $response = $this->makeRequest('/combat/collect', ["token" => $userName, "combatId" => $combatId]);
 }
开发者ID:jced-artem,项目名称:test_game,代码行数:57,代码来源:UserControllerTest.php

示例4: setUp

 public function setUp()
 {
     parent::setUp();
     $this->db('ORM')->purgeDatabase();
     $this->client = $this->createAuthenticatedClient();
     $this->searchManager = $this->client->getContainer()->get('massive_search.search_manager');
     $this->entityManager = $this->getContainer()->get('doctrine.orm.entity_manager');
     $this->createUser();
     $this->indexProducts();
 }
开发者ID:kriswillis,项目名称:sulu,代码行数:10,代码来源:SearchControllerTest.php

示例5: 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);
 }
开发者ID:saro0h,项目名称:sf2c2,代码行数:10,代码来源:AbstractTest.php

示例6: addToCart

 private function addToCart($mealName, $quantity, Crawler $crawler, Client $client)
 {
     $titles = $crawler->filter('h4')->reduce(function ($crawler) use($mealName) {
         return false !== strpos($crawler->text(), $mealName);
     });
     if (count($titles) !== 1) {
         throw new \RuntimeException(sprintf('Expected 1 title containing "%s", found %s.', $mealName, count($titles)));
     }
     $link = $titles->eq(0)->parents()->first()->filter('input[data-meal]');
     $mealId = $link->attr('data-meal');
     $client->request('POST', '/cart', array('meal' => $mealId, 'mode' => 'add', 'quantity' => $quantity));
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
 }
开发者ID:sroze,项目名称:site-de-maman,代码行数:13,代码来源:CartControllerTest.php

示例7: 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;
 }
开发者ID:hikmahtiar6,项目名称:drafterbit,代码行数:27,代码来源:WebTestCase.php

示例8: login

 protected function login(Client $client, $username = 'admin', $password = 'password')
 {
     $client->restart();
     $crawler = $client->request('GET', '/login');
     $this->assertTrue($client->getResponse()->isSuccessful(), 'Response should be successful');
     $form = $crawler->selectButton('Login')->form();
     $client->submit($form, array('_username' => $username, '_password' => $password));
     $this->assertTrue($client->getResponse()->isRedirect(), 'Response should be redirect');
     $crawler = $client->followRedirect();
     $this->assertGreaterThan(0, $crawler->filter('html:contains("Benvenuto")')->count());
 }
开发者ID:risinglf,项目名称:UniversiBO,代码行数:11,代码来源:BaseControllerTest.php

示例9: authenticate

 /**
  * @return AuthenticateResponse
  */
 public function authenticate()
 {
     $this->client->request('POST', self::SING_IN_URI, ['username' => $this->username, 'password' => $this->password], [], ['HTTP_ACCEPT' => 'application/json']);
     $loginResponse = json_decode($this->client->getResponse()->getContent());
     $authenticateHeaders = ['HTTP_TOKEN' => isset($loginResponse->Token) ? $loginResponse->Token : null, 'HTTP_EXPIREAT' => isset($loginResponse->ExpireAt) ? $loginResponse->ExpireAt : null, 'HTTP_USERNAME' => isset($loginResponse->Username) ? $loginResponse->Username : null];
     return new AuthenticateResponse([], $authenticateHeaders);
 }
开发者ID:glavweb,项目名称:rest-demo-app,代码行数:10,代码来源:Authenticator.php

示例10: getDocument

 /**
  * @param $uri
  * @param $format
  * @return \PHPExcel
  */
 protected function getDocument($uri, $format = 'xlsx')
 {
     // generate source
     static::$client->request('GET', $uri);
     $source = static::$client->getResponse()->getContent();
     // create source directory if necessary
     if (!file_exists(__DIR__ . static::$TEMP_PATH)) {
         mkdir(__DIR__ . static::$TEMP_PATH);
     }
     // save source
     file_put_contents(__DIR__ . static::$TEMP_PATH . 'simple' . '.' . $format, $source);
     // load source
     switch ($format) {
         case 'ods':
             $reader = new PHPExcel_Reader_OOCalc();
             break;
         case 'xls':
             $reader = new PHPExcel_Reader_Excel5();
             break;
         case 'xlsx':
             $reader = new PHPExcel_Reader_Excel2007();
             break;
         default:
             throw new InvalidArgumentException();
     }
     return $reader->load(__DIR__ . static::$TEMP_PATH . 'simple' . '.' . $format);
 }
开发者ID:darookee,项目名称:TwigExcelBundle,代码行数:32,代码来源:AbstractControllerTest.php

示例11: 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']));
         }
     }
 }
开发者ID:neronmoon,项目名称:Codeception,代码行数:28,代码来源:InnerBrowser.php

示例12: followRedirect

 /**
  *  override to allow redirect history recording
  *     
  *  @see  parent::followRedirect
  */
 public function followRedirect()
 {
     if (!empty($this->redirect)) {
         $this->redirect_list[] = $this->redirect;
     }
     //if
     return parent::followRedirect();
 }
开发者ID:Jaymon,项目名称:Montage,代码行数:13,代码来源:FrameworkClient.php

示例13: seeResponseCodeIs

 /**
  * Checks response code.
  *
  * @param $num
  */
 public function seeResponseCodeIs($num)
 {
     if (method_exists($this->client->getResponse(), 'getStatusCode')) {
         \PHPUnit_Framework_Assert::assertEquals($num, $this->client->getResponse()->getStatusCode());
     } else {
         \PHPUnit_Framework_Assert::assertEquals($num, $this->client->getResponse()->getStatus());
     }
 }
开发者ID:pfz,项目名称:codeception,代码行数:13,代码来源:REST.php

示例14: __construct

    /**
     * Constructor.
     *
     * @param HttpKernelInterface $kernel    An HttpKernel instance
     * @param array               $server    The server parameters (equivalent of $_SERVER)
     * @param History             $history   A History instance to store the browser history
     * @param CookieJar           $cookieJar A CookieJar instance to store the cookies
     */
    public function __construct(HttpKernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null)
    {
        $this->kernel = $kernel;

        parent::__construct($server, $history, $cookieJar);

        $this->followRedirects = false;
    }
开发者ID:nysander,项目名称:symfony,代码行数:16,代码来源:Client.php

示例15: testSavePerDiemAction

 /**
  * testing savePerDiem action.
  */
 public function testSavePerDiemAction()
 {
     // Empty request
     $crawler = $this->client->request('POST', '/secured/travel/admin/save/perdiem');
     $this->assertJson($this->client->getResponse()->getContent(), 'testSavePerDiemAction: The response\'s content is not a JSON object.');
     $this->assertTrue($this->client->getResponse()->headers->contains('Content-Type', 'application/json'), 'testSavePerDiemAction: The content-type is not a json.');
     // Filled up request
     $crawler = $this->client->request('POST', '/secured/travel/admin/save/perdiem', array('perdiem' => array(0 => array('id' => 1, 'hours' => 14, 'amount' => 24), 1 => array('id' => null, 'hours' => 12, 'amount' => 12))));
     $this->assertTrue($this->client->getResponse()->headers->contains('Content-Type', 'text/html; charset=UTF-8'), 'testSavePerDiemAction: The content-type is not html.');
 }
开发者ID:hkmshb,项目名称:OpitHrm,代码行数:13,代码来源:AdminControllerTest.php


注:本文中的Symfony\Component\BrowserKit\Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。