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


PHP Client::request方法代码示例

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


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

示例1: testControllerNoticeToException

 public function testControllerNoticeToException()
 {
     $this->client = $this->createClient();
     $errorOccured = false;
     $syslogProcessorMock = $this->getMockBuilder('Keboola\\Syrup\\Monolog\\Processor\\SyslogProcessor')->disableOriginalConstructor()->getMock();
     $syslogProcessorMock->expects($this->any())->method("processRecord")->with($this->callback(function ($subject) use(&$errorOccured) {
         if ($subject['message'] == 'Notice: Undefined offset: 3') {
             $e = $subject['context']['exception'];
             $errorOccured = true;
             return $e instanceof \Symfony\Component\Debug\Exception\ContextErrorException;
         }
         return true;
     }))->willReturn(['level' => 100]);
     $container = $this->client->getContainer();
     $container->set('syrup.monolog.syslog_processor', $syslogProcessorMock);
     $this->client->request('GET', '/tests/notice');
     $response = $this->client->getResponse();
     $responseJson = json_decode($response->getContent(), true);
     $this->assertEquals('error', $responseJson['status']);
     $this->assertEquals('Application error', $responseJson['error']);
     $this->assertEquals(500, $responseJson['code']);
     $this->assertArrayHasKey('exceptionId', $responseJson);
     $this->assertArrayHasKey('runId', $responseJson);
     $this->assertTrue($errorOccured);
 }
开发者ID:keboola,项目名称:syrup,代码行数:25,代码来源:ErrorHandlingTest.php

示例2: setUp

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

示例3: testSearchPage

 public function testSearchPage()
 {
     $this->client->request('GET', '/search?keyword=samsung sync master');
     $response = $this->client->getResponse();
     $this->assertTrue($response->isSuccessful());
     $this->assertEquals('application/json', $response->headers->get('Content-Type'));
 }
开发者ID:uikolas,项目名称:LT-eshops-search,代码行数:7,代码来源:DefaultControllerTest.php

示例4: testPutPlayerAction

 public function testPutPlayerAction()
 {
     $em = self::$kernel->getContainer()->get('doctrine')->getManager();
     $queryBuilder = $em->createQueryBuilder();
     $players = $queryBuilder->select('p')->from('DraftBundle:Player', 'p')->setMaxResults(1)->getQuery()->execute();
     if (is_array($players)) {
         $player = $players[0];
     } else {
         $player = $players;
     }
     $name = $player->getName();
     $team = $player->getNflTeam();
     $position = $player->getPosition();
     $toEncode = array('name' => 'willy wonka', 'position' => 'QB', 'nflTeam' => 'SF', 'draftYear' => '2016');
     $postData = json_encode($toEncode);
     $this->client->request('PUT', '/api/players/' . $player->getId(), array(), array(), array('CONTENT_TYPE' => 'application/json'), $postData);
     $response = $this->client->getResponse();
     $content = $response->getContent();
     $this->assertTrue($response->isSuccessful());
     $this->assertEmpty($content);
     $updatedPlayer = $em->getRepository('DraftBundle:Player')->find($player->getId());
     $this->assertEquals('willy wonka', $updatedPlayer->getName());
     $updatedPlayer->setName($name);
     $updatedPlayer->setNflTeam($team);
     $updatedPlayer->setPosition($position);
     $em->persist($updatedPlayer);
     $em->flush();
 }
开发者ID:buphmin,项目名称:RookieDraft,代码行数:28,代码来源:PlayerControllerTest.php

示例5: testLogin

 /**
  * @dataProvider provideLoginData
  */
 public function testLogin(Client $client, $securedUrl, $login, $expectedMessage)
 {
     // client follow redirects
     $client->followRedirects();
     // go to secured page -> got login required
     $crawler = $client->request('GET', $securedUrl);
     $this->assertEquals(TrustedSsoController::LOGIN_REQUIRED_MESSAGE, $crawler->filter('#message')->text());
     // click link -> got login form
     $crawler = $client->click($crawler->filter('#url')->link());
     $this->assertEquals('login', $crawler->filter('form')->attr('id'));
     // fill form & submit -> got expected message
     $form = $crawler->filter('input[type=submit]')->form();
     $crawler = $client->submit($form, array('login[username]' => $login, 'login[password]' => $login));
     $this->assertEquals($expectedMessage, $crawler->filter('#message')->text());
     if (!$login === self::LOGIN_INVALID) {
         // check validation attributes
         $attrs = static::$kernel->getContainer()->get('security.context')->getToken()->getValidationAttributes();
         $this->assertEquals(array('attr1' => 'val1', 'attr2' => 'val2'), $attrs);
     }
     // logout -> got logout redirect
     $crawler = $client->request('GET', '/secured/logout');
     $this->assertEquals(TrustedSsoController::LOGOUT_REDIRECT_MESSAGE, $crawler->filter('#message')->text());
     // click link -> got logout done
     $crawler = $client->click($crawler->filter('#url')->link());
     $this->assertEquals(ServerController::LOGOUT_MESSAGE, $crawler->filter('#message')->text());
     // click link -> go to homepage
     $crawler = $client->click($crawler->filter('#url')->link());
     $this->assertEquals(TestController::HOME_MESSAGE, $crawler->filter('#message')->text());
 }
开发者ID:nicolasbui,项目名称:BeSimpleSsoAuthBundle,代码行数:32,代码来源:LoginTest.php

示例6: testTokenCreation

 /**
  * Test token creation and usage
  */
 public function testTokenCreation()
 {
     $headers = array('PHP_AUTH_USER' => 'test_key', 'PHP_AUTH_PW' => 'test_secret', 'HTTP_username' => 'p-admin', 'HTTP_password' => 'p-admin');
     $this->client->request('GET', '/oauth/access_token?grant_type=password', array(), array(), $headers);
     $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
     $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type'));
 }
开发者ID:open-orchestra,项目名称:open-orchestra,代码行数:10,代码来源:AuthorizationControllersTest.php

示例7: testDeleteMultiple

 /**
  * @depends testPut
  */
 public function testDeleteMultiple()
 {
     $data = [2, 3];
     $uri = self::$router->generate('post_assets') . '.json';
     self::$client->request('DELETE', $uri, ['images' => json_encode($data)]);
     $this->assertTrue(self::$client->getResponse()->isRedirect());
 }
开发者ID:gorvelyfab,项目名称:KoopaBaseAdminer,代码行数:10,代码来源:MediaControllerTest.php

示例8: assertApiGetResponse

 protected function assertApiGetResponse($apiUri, $expectedStatusCode, $expectedJsonString)
 {
     static::$client->request('GET', $apiUri);
     $this->assertStatusCode($expectedStatusCode, static::$client);
     $responseBody = static::$client->getResponse()->getContent();
     static::assertJson($responseBody);
     static::assertJsonStringEqualsJsonString($expectedJsonString, $responseBody);
 }
开发者ID:RedDevilHat,项目名称:symfony2,代码行数:8,代码来源:ApiTestCase.php

示例9: testCreateTransAndRedirectToTpv

 public function testCreateTransAndRedirectToTpv()
 {
     $this->transaction = new Transaction(1);
     $this->manager->update($this->transaction);
     /** @var $crawler */
     $crawler = $this->client->request('GET', $this->route_index);
     $this->assertEquals($crawler->filter('body:contains(form)')->count(), 1);
 }
开发者ID:krixer,项目名称:ServiredBundle,代码行数:8,代码来源:DefaultControllerTest.php

示例10: testAjaxDeleteFromBookmarkAction

 /**
  * Test AjaxDeleteFromBookmark action
  */
 public function testAjaxDeleteFromBookmarkAction()
 {
     $fixtures = $this->loadFixtures(['AppBundle\\DataFixtures\\ORM\\LoadUserData', 'AppBundle\\DataFixtures\\ORM\\LoadUserGroupData', 'AppBundle\\DataFixtures\\ORM\\LoadGroupData'])->getReferenceRepository();
     $this->loginAs($fixtures->getReference('user-admin'), 'main');
     $this->client = static::makeClient();
     $this->client->request('GET', '/group/jinjer/bookmark/delete', [], [], ['HTTP_X-Requested-With' => 'XMLHttpRequest']);
     $this->assertStatusCode(Response::HTTP_OK, $this->client);
 }
开发者ID:stfalcon-studio,项目名称:rock-events,代码行数:11,代码来源:GroupControllerTest.php

示例11: request

 /**
  * @param string $method
  * @param string $url
  * @param array $params
  * @param array $headers
  */
 private function request(string $method, string $url, array $params = [], array $headers = [])
 {
     if (is_null($this->client)) {
         $this->client = static::createClient();
     }
     $headers['HTTP_X_ACCEPT_VERSION'] = self::API_VERSION;
     $this->client->request($method, $url, $params, [], $headers);
 }
开发者ID:Eraac,项目名称:rest-project,代码行数:14,代码来源:AbstractControllerTest.php

示例12: open

 /**
  * @param string $method
  * @param array $parameters
  * @return Page
  */
 public function open($method = 'GET', $parameters = [])
 {
     $this->crawler = $this->client->request($method, $this->unmaskUrl($parameters));
     if (!in_array($this->client->getResponse()->getStatusCode(), [200, 302])) {
         throw new \RuntimeException(sprintf("Can't open \"%s\"", $this->getUrl()));
     }
     return $this;
 }
开发者ID:karion,项目名称:mydrinks,代码行数:13,代码来源:BasePage.php

示例13: callApi

 /**
  * Request to API, return result
  * @param string $url URL of API call
  * @param string $method HTTP method of API call
  * @param array $params parameters of POST call
  * @return array
  */
 protected function callApi($url, $method = 'POST', $params = array())
 {
     $this->httpClient->request($method, $url, [], [], [], json_encode($params));
     $response = $this->httpClient->getResponse();
     /* @var \Symfony\Component\HttpFoundation\Response $response */
     $responseJson = json_decode($response->getContent(), true);
     $this->assertNotEmpty($responseJson, sprintf("Response of API call '%s' after json decoding should not be empty. Raw response:\n%s\n", $url, $response->getContent()));
     return $responseJson;
 }
开发者ID:ErikZigo,项目名称:syrup,代码行数:16,代码来源:AbstractFunctionalTest.php

示例14: setUp

 /**
  * @return void
  */
 protected function setUp()
 {
     $this->logout();
     $this->client = static::createClient();
     $this->client->setMaxRedirects(1);
     $this->client->request('GET', self::URL_UPLOAD_THEME);
     $this->login();
     $this->client->request('GET', self::URL_UPLOAD_THEME);
 }
开发者ID:forkcms,项目名称:forkcms,代码行数:12,代码来源:UploadThemeTest.php

示例15: loginAsUser

 /**
  * @return Crawler
  * @throws \Exception
  */
 protected static function loginAsUser()
 {
     $uri = self::$container->get('router')->generate('login_route');
     $crawler = self::$client->request('GET', $uri);
     $form = $crawler->selectButton('login_btn')->form(['_username' => 'test', '_password' => '12345678']);
     self::$client->submit($form);
     self::assertTrue(self::$client->getResponse()->isRedirection());
     return self::$client->followRedirect();
 }
开发者ID:Gemorroj,项目名称:forum,代码行数:13,代码来源:ForumWebTestCase.php


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