本文整理汇总了PHP中Symfony\Component\HttpKernel\Client类的典型用法代码示例。如果您正苦于以下问题:PHP Client类的具体用法?PHP Client怎么用?PHP Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetSessionDataIncorrectSessionData
/**
* @dataProvider provideIncorrectValues
* @expectedException RuntimeException
*/
public function testGetSessionDataIncorrectSessionData($value)
{
$cookie = new Cookie('TEST', $value);
$client = new Client(new Application());
$client->getCookieJar()->set($cookie);
$this->getSessionData($client, 'TEST');
}
示例2: 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;
}
示例3: 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);
}
示例4: testDoesNotReturn401IfValidToken
public function testDoesNotReturn401IfValidToken()
{
$this->register('chain');
$jwt = JWT::encode(['sub' => 'John'], 'secret', 'HS256');
$client = new Client($this->app);
$client->request('GET', '/?jwt=' . $jwt);
$response = $client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
示例5: testValidJsonData
/**
* @dataProvider provideData
*/
public function testValidJsonData($label, $data, $expectedResponse)
{
$this->app['aiv.input'] = new \AIV\Input\SymfonyRequest\JSONInput();
$client = new Client($this->app, []);
$label = 'Test Case: ' . $label;
$client->request('POST', '/', [], [], [], json_encode(['test-name' => $data]));
$response = $client->getResponse();
$this->assertTrue($response->isOk(), $label);
$this->assertContains($expectedResponse, $response->getContent(), $label);
}
示例6: testError
/**
* @dataProvider provideExceptionsAndCode
*/
public function testError($exception, $code)
{
$app = new Application('test');
$app['dispatcher']->addSubscriber(new ApiExceptionHandlerSubscriber($app));
$app->get('/', function () use($exception) {
throw $exception;
});
$client = new Client($app);
$client->request('GET', '/');
$this->assertEquals($code, $client->getResponse()->getStatusCode());
}
示例7: request
private function request($accept)
{
$app = new Application(Application::ENV_TEST);
$app['dispatcher']->addSubscriber(new ContentNegotiationSubscriber($app['negotiator'], $app['phraseanet.content-negotiation.priorities']));
$app->get('/content/negociation', function () {
return '';
});
$client = new Client($app);
$client->request('GET', '/content/negociation', array(), array(), array('HTTP_Accept' => $accept));
return $client->getResponse();
}
示例8: getAccessToken
public function getAccessToken(Client $client)
{
$app = $this->app;
$this->assertArrayHasKey('session.storage.handler', $app, 'Renegare\\SilexCSH\\CookieSessionServiceProvider has not been registered.');
$sessionStorageHandler = $app['session.storage.handler'];
$this->assertInstanceOf('Renegare\\SilexCSH\\CookieSessionHandler', $sessionStorageHandler, 'Can only support Renegare\\SilexCSH\\CookieSessionHandler sessions');
$cookie = $client->getCookieJar()->get($sessionStorageHandler->getCookieName());
$sessionData = unserialize(unserialize($cookie->getValue())[1]);
$token = unserialize($sessionData['_security_app']);
return $token;
}
示例9: request
private function request($accept)
{
$app = new Application('test');
$app['dispatcher']->addSubscriber(new ContentNegotiationSubscriber($app));
$app->get('/content/negociation', function () {
return '';
});
$client = new Client($app);
$client->request('GET', '/content/negociation', array(), array(), array('HTTP_Accept' => $accept));
return $client->getResponse();
}
示例10: assertLinkRel
protected function assertLinkRel(Client $client, string $linkRel, string $expected)
{
$this->assertTrue($client->getResponse()->isSuccessful(), 'request is successful');
foreach ($client->getResponse()->headers->get('Link', null, false) as $linkValue) {
if (strpos($linkValue, 'rel="' . $linkRel . '"') !== false) {
$this->assertSame($expected, $linkValue);
return;
}
}
$this->fail('No link with rel "' . $linkRel . '" found.');
}
示例11: request
/**
* @param array $conf
* @param string $method
* @param array $extraHeaders
*
* @return \Symfony\Component\HttpFoundation\Response
*/
private function request(array $conf, $method = 'GET', array $extraHeaders = [])
{
$app = new Application('test');
$app['phraseanet.configuration']['api_cors'] = $conf;
$app['dispatcher']->addSubscriber(new ApiCorsSubscriber($app));
$app->get('/api/v1/test-route', function () {
return '';
});
$client = new Client($app);
$client->request($method, '/api/v1/test-route', [], [], array_merge($extraHeaders, ['HTTP_Origin' => $this->origin]));
return $client->getResponse();
}
示例12: testGetVariants
public function testGetVariants()
{
$preferred = null;
$app = new Application();
$app->register(new BadFaithServiceProvider());
$app->get('/', function (Application $app) use(&$preferred) {
$preferred = $app['bad-faith']->headerLists['accept_language']->getPreferred();
});
$client = new Client($app, array());
$client->request('GET', '/', array(), array(), array('HTTP_ACCEPT_ENCODING' => 'gzip,deflate,sdch', 'HTTP_ACCEPT_LANGUAGE' => 'de-DE,en;q=0.8'));
$this->assertEquals('de-DE', $preferred->pref);
}
示例13: testErrorOnOtherRoutes
/**
* @dataProvider provideExceptionsAndCode
*/
public function testErrorOnOtherRoutes($exception, $code, $contentType)
{
$app = new Application('test');
unset($app['exception_handler']);
$app['dispatcher']->addSubscriber(new ApiOauth2ErrorsSubscriber(PhraseaExceptionHandler::register(), $this->createTranslatorMock()));
$app->get('/', function () use($exception) {
throw $exception;
});
$client = new Client($app);
$this->setExpectedException(get_class($exception));
$client->request('GET', '/');
}
示例14: testItCanBeDisabled
public function testItCanBeDisabled()
{
$app = new Application();
$app['exception_handler'] = new PhraseaExceptionHandlerSubscriber(PhraseaExceptionHandler::register());
$app->get('/', function () {
throw new \Exception();
});
$app['exception_handler']->disable();
$client = new Client($app);
$this->setExpectedException('\\Exception');
$client->request('GET', '/');
}
示例15: testNoHeaderNoRedirection
public function testNoHeaderNoRedirection()
{
$app = new Application();
unset($app['exception_handler']);
$app['dispatcher']->addSubscriber(new FirewallSubscriber());
$app->get('/', function () {
throw new HttpException(500);
});
$client = new Client($app);
$this->setExpectedException('Symfony\\Component\\HttpKernel\\Exception\\HttpException');
$client->request('GET', '/');
}