本文整理汇总了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();
}
示例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);
}
示例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;
}
示例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();
}
示例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));
}
示例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);
}
示例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));
}
}
示例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');
}
示例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();
}
示例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();
}
示例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());
}
示例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());
});
}
示例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');
}
示例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());
}
示例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);
}