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


PHP HttpKernel\Client类代码示例

本文整理汇总了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');
 }
开发者ID:renegare,项目名称:silexcsh,代码行数:11,代码来源:CookieSessionTestTraitTest.php

示例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;
 }
开发者ID:jsmith07,项目名称:silex-annotation-provider,代码行数:7,代码来源:AnnotationTestBase.php

示例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);
 }
开发者ID:sev28,项目名称:flyaround_s2,代码行数:34,代码来源:ApiSecurityControllerTest.php

示例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());
 }
开发者ID:evaneos,项目名称:silex-jwt-provider,代码行数:9,代码来源:SecurityJWTServiceProviderTest.php

示例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);
 }
开发者ID:renegare,项目名称:aiv,代码行数:13,代码来源:SilexProviderNamespacedTest.php

示例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());
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:14,代码来源:ApiExceptionHandlerSubscriberTest.php

示例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();
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:11,代码来源:ContentNegotiationSubscriberTest.php

示例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;
 }
开发者ID:renegare,项目名称:weblet-client,代码行数:11,代码来源:WebletTestCase.php

示例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();
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:11,代码来源:ContentNegotiationSubscriberTest.php

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

示例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();
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:19,代码来源:ApiCorsSubscriberTest.php

示例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);
 }
开发者ID:romainneutron,项目名称:BadFaith-ServiceProvider,代码行数:12,代码来源:BadFaithServiceProviderTest.php

示例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', '/');
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:15,代码来源:ApiOauth2ErrorsSubscriberTest.php

示例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', '/');
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:12,代码来源:PhraseaExceptionHandlerSubscriberTest.php

示例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', '/');
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:12,代码来源:FirewallSubscriberTest.php


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