本文整理汇总了PHP中Symfony\Bundle\FrameworkBundle\Client类的典型用法代码示例。如果您正苦于以下问题:PHP Client类的具体用法?PHP Client怎么用?PHP Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$this->client = static::createClient();
$this->client->followRedirects();
$this->container = $this->client->getContainer();
$this->loadFixtures($this->getFixtures());
}
示例2: 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);
}
示例3: setUpBeforeClass
public static function setUpBeforeClass()
{
static::$client = static::createClient();
static::$router = self::$client->getContainer()->get('router');
static::$em = self::$client->getContainer()->get('doctrine.orm.entity_manager');
static::$container = self::getContainer();
}
示例4: createClient
/**
* {@inheritdoc}
*/
protected static function createClient(array $options = array(), array $server = array())
{
static::bootKernel($options);
$client = new Client(static::$kernel);
$client->setServerParameters($server);
return $client;
}
示例5: getErrorMessage
/**
* @param \Symfony\Bundle\FrameworkBundle\Client $client
*
* @return string
*/
protected function getErrorMessage(Client $client)
{
/** @var $profile \Symfony\Component\HttpKernel\Profiler\Profile */
$profile = $client->getProfile();
if (!$profile) {
return '';
}
/** @var $exception \Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector */
$exception = $profile->getCollector('exception');
if (!$exception->hasException()) {
return '';
}
$arrayTrace = array();
foreach (array_slice($exception->getTrace(), 0, 10) as $position => $traceLine) {
if (isset($traceLine['class'])) {
$arrayTrace[] = sprintf('[%d] %s(%d) %s%s%s(%s)', $position, $traceLine['file'], $traceLine['line'], $traceLine['short_class'], $traceLine['type'], $traceLine['function'], isset($traceLine['args']) ? implode(', ', array_map(function ($v) {
switch ($v[0]) {
case 'array':
return 'array(' . count($v[1]) . ')';
case 'object':
return $v[1];
default:
return $v[1];
}
}, $traceLine['args'])) : '');
}
}
if (count($arrayTrace) < count($exception->getTrace())) {
$arrayTrace[] = '...';
}
return $exception->getMessage() . PHP_EOL . PHP_EOL . implode(PHP_EOL, $arrayTrace) . PHP_EOL;
}
示例6: logoutAction
/**
* Performs logout action and returns same client after log out.
*
* @param Client $client
*
* @return Client
*/
public function logoutAction(Client $client)
{
$crawler = $client->request('GET', '/settings/login');
$link = $crawler->filter('a:contains("Logout")')->link();
$client->click($link);
return $client;
}
示例7: setSettingsCookie
/**
* Create settings cookies and set it in the cookie jar.
*
* @param Client $client
* @param array $cookies
*/
public static function setSettingsCookie(Client $client, array $cookies)
{
foreach ($cookies as $name => $cookieSettings) {
$cookie = new Cookie($name, json_encode($cookieSettings));
$client->getCookieJar()->set($cookie);
}
}
示例8: makeJsonRequest
/**
* Create a JSON request
*
* @param Client $client
* @param string $method
* @param string $url
* @param string $content
* @param string $token
*/
public function makeJsonRequest(Client $client, $method, $url, $content = null, $token = null, $files = array())
{
$headers = ['HTTP_ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json'];
if (!empty($token)) {
$headers['HTTP_X-JWT-Authorization'] = 'Token ' . $token;
}
$client->request($method, $url, [], $files, $headers, $content);
}
示例9: setUp
/**
* {@inheritDoc}
*/
public function setUp()
{
$this->client = static::createClient();
$this->container = $this->client->getContainer();
$this->em = $this->container->get('doctrine')->getManager();
$this->validator = $this->container->get('validator');
$this->setCurrentShop();
}
示例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);
}
示例11: 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;
}
示例12: 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'));
}
示例13: 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'));
}
示例14: 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());
}
示例15: 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();
}