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


PHP Client::request方法代码示例

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


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

示例1: setUp

 protected function setUp()
 {
     $this->client = static::createClient();
     $this->client->followRedirects(true);
     $this->crawler = $this->client->request('GET', self::LOGIN_URL);
     $this->loginForm = $this->crawler->selectButton(self::LOGIN_BUTTON)->form();
 }
开发者ID:GrossumUA,项目名称:Symfony3-Base-Instance,代码行数:7,代码来源:AbstractLoginTest.php

示例2: testLoginSuccess

 /**
  * test login
  */
 public function testLoginSuccess()
 {
     $data = array('username' => 'user', 'password' => 'password');
     $this->client->request('POST', $this->getUrl('api_login_check'), $data);
     $this->assertJsonResponse($this->client->getResponse(), 200);
     $response = json_decode($this->client->getResponse()->getContent(), true);
     $this->assertArrayHasKey('token', $response);
     // check token from query string work
     $client = static::createClient();
     $client->request('HEAD', $this->getUrl('api_ping', array($this->queryParameterName => $response['token'])));
     $this->assertJsonResponse($client->getResponse(), 200, false);
     // check token work
     $client = static::createClient();
     $client->setServerParameter('HTTP_Authorization', sprintf('%s %s', $this->authorizationHeaderPrefix, $response['token']));
     $client->request('HEAD', $this->getUrl('api_ping'));
     $this->assertJsonResponse($client->getResponse(), 200, false);
     // check token works several times, as long as it is valid
     $client = static::createClient();
     $client->setServerParameter('HTTP_Authorization', sprintf('%s %s', $this->authorizationHeaderPrefix, $response['token']));
     $client->request('HEAD', $this->getUrl('api_ping'));
     $this->assertJsonResponse($client->getResponse(), 200, false);
     // check a bad token does not work
     $client = static::createClient();
     $client->setServerParameter('HTTP_Authorization', sprintf('%s %s', $this->authorizationHeaderPrefix, $response['token'] . 'changed'));
     $client->request('HEAD', $this->getUrl('api_ping'));
     $this->assertJsonResponse($client->getResponse(), 401, false);
     // check error if no authorization header
     $client = static::createClient();
     $client->request('HEAD', $this->getUrl('api_ping'));
     $this->assertJsonResponse($client->getResponse(), 401, false);
 }
开发者ID:sev28,项目名称:flyaround_s2,代码行数:34,代码来源:ApiSecurityControllerTest.php

示例3: makeRequest

 protected function makeRequest($method, $uri, $annotationOptions = array())
 {
     $this->getClient($annotationOptions);
     $this->client->request($method, $uri, array(), array(), $this->requestOptions);
     $response = $this->client->getResponse();
     return $response;
 }
开发者ID:jsmith07,项目名称:silex-annotation-provider,代码行数:7,代码来源:AnnotationTestBase.php

示例4: doLogin

 /**
  * Do login with username
  *
  * @param string $username
  */
 private function doLogin($username = 'admin')
 {
     $crawler = $this->client->request('GET', $this->getUrl('fos_user_security_login', array()));
     $form = $crawler->selectButton('_submit')->form(array('_username' => $username, '_password' => 'qwerty'));
     $this->client->submit($form);
     $this->assertTrue($this->client->getResponse()->isRedirect());
     $this->client->followRedirects();
 }
开发者ID:alienpham,项目名称:portfolio,代码行数:13,代码来源:UploadControllerTest.php

示例5: sendRequest

 /**
  * @param string $method
  * @param string $url
  * @param array|null $content
  */
 private function sendRequest($method, $url, $content = null)
 {
     $header = array('HTTP_ACCEPT' => 'application/json');
     if ($method == 'POST') {
         $header['CONTENT_TYPE'] = 'application/json';
     }
     $this->client->request($method, $url, array(), array(), $header, json_encode($content));
 }
开发者ID:famfij,项目名称:TP-BilletsDuLouvre,代码行数:13,代码来源:PaymentControllerTest.php

示例6: testLoginSuccess

 /**
  * test login
  */
 public function testLoginSuccess()
 {
     $data = array('username' => 'user', 'password' => 'password');
     $this->client->request('POST', $this->getUrl('login_check'), $data);
     $this->assertJsonResponse($this->client->getResponse(), 200);
     $response = json_decode($this->client->getResponse()->getContent(), true);
     $this->assertArrayHasKey('token', $response);
     $this->assertArrayHasKey('data', $response);
 }
开发者ID:jpsymfony,项目名称:REST-BEHAT,代码行数:12,代码来源:AuthenticationControllerTest.php

示例7: navigateToPageAndAssertSuccess

 /**
  * @param string $uri
  * @param string $responseType
  */
 public function navigateToPageAndAssertSuccess($uri, $responseType = null)
 {
     $this->client->request('GET', $uri);
     $this->assertTrue($this->client->getResponse()->isSuccessful(), 'Navigation to ' . $uri . ' did not trigger a successful response.');
     if (null !== $responseType) {
         $responseTypeIsTheOneExpected = $this->client->getResponse()->headers->contains('Content-Type', $responseType);
         $this->assertTrue($responseTypeIsTheOneExpected, 'The content type of the response was not ' . $responseType . '. The header provided was: ' . var_export($this->client->getResponse()->headers, true));
     }
 }
开发者ID:cegeka,项目名称:symfony-toolkit,代码行数:13,代码来源:FunctionalBase.php

示例8: testDoRequest

 public function testDoRequest()
 {
     $client = new Client(new TestHttpKernel());
     $client->request('GET', '/');
     $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
     $client->request('GET', 'http://www.example.com/');
     $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
     $this->assertEquals('www.example.com', $client->getRequest()->getHost(), '->doRequest() uses the request handler to make the request');
 }
开发者ID:notbrain,项目名称:symfony,代码行数:9,代码来源:ClientTest.php

示例9: logInBackend

 public function logInBackend($username = 'backenduser', $password = 'backenduser')
 {
     if ($this->um->isAuthenticated() === false) {
         $this->client->request('GET', '/' . $this->api['backend'] . '/user/login/?username=' . $username . '&password=' . $password, [], [], ['CONTENT_TYPE' => 'application/json']);
         $response = $this->client->getResponse();
         $content = $response->getContent();
         $result = json_decode($content, true);
         if ($result['status'] !== true) {
             throw new \LogicException('Authentication failed.');
         }
     }
     return $this->um->isAuthenticated();
 }
开发者ID:gitye,项目名称:Aisel,代码行数:13,代码来源:AbstractWebTestCase.php

示例10: logInFrontend

 public function logInFrontend($username = 'frontenduser', $password = 'frontenduser')
 {
     if ($this->um->isAuthenticated() === false) {
         $data = ['username' => $username, 'password' => $password];
         $this->client->request('POST', '/' . $this->api['frontend'] . '/user/login/', [], [], ['CONTENT_TYPE' => 'application/json'], json_encode($data));
         $response = $this->client->getResponse();
         $content = $response->getContent();
         $result = json_decode($content, true);
         if ($result['status'] !== true) {
             throw new \LogicException('Authentication failed.');
         }
     }
     return $this->um->isAuthenticated();
 }
开发者ID:Nameless0ne,项目名称:Aisel,代码行数:14,代码来源:AbstractWebTestCase.php

示例11: testTicketReplyErrors

 /**
  * Отображение ошибки при ответе
  */
 public function testTicketReplyErrors()
 {
     $crawler = $this->client->request('GET', '/ticket/6/show?_locale=ru');
     $form = $crawler->selectButton('Message[submit]')->form();
     $crawler = $this->client->submit($form);
     static::assertGreaterThan(0, $crawler->filter('html:contains("Заполните поле Сообщение или загрузите изображение")')->count());
 }
开发者ID:dreamlex,项目名称:ticketbundle,代码行数:10,代码来源:TicketControllerTest.php

示例12: testListBucket

 public function testListBucket()
 {
     $this->authorize();
     $listUrl = $this->urlGenerator->generate('list', ['bucket' => 'foo']);
     $listBuckets = new Result(['Buckets' => [['Name' => 'foo', 'CreationDate' => '2014-08-01T14:00:00.000Z'], ['Name' => 'bar', 'CreationDate' => '2014-07-31T20:30:40.000Z']]]);
     $listObjects = new Result(['Contents' => [['Key' => 'baz', 'ETag' => '"' . md5('baz') . '"', 'LastModified' => '2014-09-10T11:12:13.000Z', 'Size' => 1024], ['Key' => 'qux', 'ETag' => '"' . md5('qux') . '"', 'LastModified' => '2014-09-11T21:22:23.000Z', 'Size' => 2048], ['Key' => 'quxx', 'ETag' => '"' . md5('quxx') . '"', 'LastModified' => '2014-09-12T00:00:00.000Z', 'Size' => 512]], 'IsTruncated' => false]);
     $this->s3ClientMock->expects($this->once())->method('listBuckets')->willReturn($listBuckets);
     $this->s3ClientMock->expects($this->once())->method('listObjects')->willReturn($listObjects);
     $crawler = $this->client->request('GET', $listUrl);
     $this->assertTrue($this->client->getResponse()->isOk());
     // buckets
     $list = $crawler->filter('#list-bucket li');
     $active = $list->filter('.active');
     $this->assertCount(count($listBuckets['Buckets']), $list);
     $this->assertCount(1, $active);
     $this->assertEquals($list->eq(0), $active);
     $urlGenerator = $this->urlGenerator;
     $list->each(function (Crawler $bucket, $index) use($urlGenerator, $listBuckets) {
         $link = $bucket->filter('a');
         $expectedName = $listBuckets['Buckets'][$index]['Name'];
         $this->assertEquals($expectedName, $link->text());
         $this->assertEquals($urlGenerator->generate('list', ['bucket' => $expectedName]), $link->attr('href'));
     });
     // objects
     $list = $crawler->filter('#list-object tbody tr');
     $this->assertCount(count($listObjects['Contents']), $list);
     $list->each(function (Crawler $object, $index) use($listObjects) {
         $link = $object->filter('td')->eq(0)->filter('a');
         $expectedKey = $listObjects['Contents'][$index]['Key'];
         $this->assertEquals($expectedKey, $link->text());
         $this->assertEquals('http://foo.s3.amazonaws.com/' . $expectedKey, $link->attr('href'));
         $this->assertEquals($listObjects['Contents'][$index]['Size'], $object->filter('td')->eq(1)->text());
     });
 }
开发者ID:ossinkine,项目名称:amazon-s3-client,代码行数:34,代码来源:ApplicationTest.php

示例13: testRememberMeAuthentication

 public function testRememberMeAuthentication()
 {
     $app = $this->createApplication();
     $client = new Client($app);
     $client->request('get', '/');
     $client->request('post', '/login_check', array('_username' => 'fabien', '_password' => 'foo', '_remember_me' => 'true'));
     $client->followRedirect();
     $this->assertEquals('AUTHENTICATED_FULLY', $client->getResponse()->getContent());
     $this->assertNotNull($client->getCookiejar()->get('REMEMBERME'), 'The REMEMBERME cookie is set');
     $client->getCookiejar()->expire('MOCKSESSID');
     $client->request('get', '/');
     $this->assertEquals('AUTHENTICATED_REMEMBERED', $client->getResponse()->getContent());
     $client->request('get', '/logout');
     $client->followRedirect();
     $this->assertNull($client->getCookiejar()->get('REMEMBERME'), 'The REMEMBERME cookie has been removed');
 }
开发者ID:syntropysoftware,项目名称:cryptoffice-frontend,代码行数:16,代码来源:RememberMeServiceProviderTest.php

示例14: execute

 protected function execute($method = 'GET', $url, $parameters = array(), $files = array())
 {
     foreach ($this->headers as $header => $val) {
         $header = str_replace('-', '_', strtoupper($header));
         $this->client->setServerParameter("HTTP_{$header}", $val);
         # Issue #827 - symfony foundation requires 'CONTENT_TYPE' without HTTP_
         if ($this->isFunctional and $header == 'CONTENT_TYPE') {
             $this->client->setServerParameter($header, $val);
         }
     }
     // allow full url to be requested
     $url = (strpos($url, '://') === false ? $this->config['url'] : '') . $url;
     $parameters = $this->encodeApplicationJson($method, $parameters);
     if (is_array($parameters) || $method == 'GET') {
         if (!empty($parameters) && $method == 'GET') {
             $url .= '?' . http_build_query($parameters);
         }
         if ($method == 'GET') {
             $this->debugSection("Request", "{$method} {$url}");
         } else {
             $this->debugSection("Request", "{$method} {$url} " . json_encode($parameters));
         }
         $this->client->request($method, $url, $parameters, $files);
     } else {
         $this->debugSection("Request", "{$method} {$url} " . $parameters);
         $this->client->request($method, $url, array(), $files, array(), $parameters);
     }
     $this->response = $this->client->getInternalResponse()->getContent();
     $this->debugSection("Response", $this->response);
     if (count($this->client->getInternalRequest()->getCookies())) {
         $this->debugSection('Cookies', $this->client->getInternalRequest()->getCookies());
     }
     $this->debugSection("Headers", $this->client->getInternalResponse()->getHeaders());
     $this->debugSection("Status", $this->client->getInternalResponse()->getStatus());
 }
开发者ID:huynt57,项目名称:bluebee-uet.com,代码行数:35,代码来源:REST.php

示例15: execute

 protected function execute($method = 'GET', $url, $parameters = array(), $files = array())
 {
     foreach ($this->headers as $header => $val) {
         $this->client->setServerParameter("HTTP_{$header}", $val);
     }
     // allow full url to be requested
     $url = (strpos($url, '://') === false ? $this->config['url'] : '') . $url;
     if (is_array($parameters) || $parameters instanceof \ArrayAccess) {
         $parameters = $this->scalarizeArray($parameters);
         if (array_key_exists('Content-Type', $this->headers) && $this->headers['Content-Type'] === 'application/json' && $method != 'GET') {
             $parameters = json_encode($parameters);
         }
     }
     if (is_array($parameters) || $method == 'GET') {
         if ($method == 'GET' && !empty($parameters)) {
             $url .= '?' . http_build_query($parameters);
             $this->debugSection("Request", "{$method} {$url}");
         } else {
             $this->debugSection("Request", "{$method} {$url}?" . http_build_query($parameters));
         }
         $this->client->request($method, $url, $parameters, $files);
     } else {
         $this->debugSection("Request", "{$method} {$url} " . $parameters);
         $this->client->request($method, $url, array(), $files, array(), $parameters);
     }
     $this->response = $this->client->getResponse()->getContent();
     $this->debugSection("Response", $this->response);
 }
开发者ID:pfz,项目名称:codeception,代码行数:28,代码来源:REST.php


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