Вход Регистрация
Файл: vkolhoze.com/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/DefaultResponseParserTest.php
Строк: 103
<?php

namespace GuzzleTestsServiceCommand;

use 
GuzzleHttpMessageResponse;
use 
GuzzleServiceClient;
use 
GuzzleServiceCommandDefaultResponseParser;
use 
GuzzleServiceCommandOperationCommand;
use 
GuzzleServiceDescriptionOperation;

/**
 * @covers GuzzleServiceCommandDefaultResponseParser
 */
class DefaultResponseParserTest extends GuzzleTestsGuzzleTestCase
{
    public function 
testParsesXmlResponses()
    {
        
$op = new OperationCommand(array(), new Operation());
        
$op->setClient(new Client());
        
$request $op->prepare();
        
$request->setResponse(new Response(200, array(
            
'Content-Type' => 'application/xml'
        
), '<Foo><Baz>Bar</Baz></Foo>'), true);
        
$this->assertInstanceOf('SimpleXMLElement'$op->execute());
    }

    public function 
testParsesJsonResponses()
    {
        
$op = new OperationCommand(array(), new Operation());
        
$op->setClient(new Client());
        
$request $op->prepare();
        
$request->setResponse(new Response(200, array(
            
'Content-Type' => 'application/json'
        
), '{"Baz":"Bar"}'), true);
        
$this->assertEquals(array('Baz' => 'Bar'), $op->execute());
    }

    
/**
     * @expectedException GuzzleCommonExceptionRuntimeException
     */
    
public function testThrowsExceptionWhenParsingJsonFails()
    {
        
$op = new OperationCommand(array(), new Operation());
        
$op->setClient(new Client());
        
$request $op->prepare();
        
$request->setResponse(new Response(200, array('Content-Type' => 'application/json'), '{"Baz":ddw}'), true);
        
$op->execute();
    }

    public function 
testAddsContentTypeWhenExpectsIsSetOnCommand()
    {
        
$op = new OperationCommand(array(), new Operation());
        
$op['command.expects'] = 'application/json';
        
$op->setClient(new Client());
        
$request $op->prepare();
        
$request->setResponse(new Response(200null'{"Baz":"Bar"}'), true);
        
$this->assertEquals(array('Baz' => 'Bar'), $op->execute());
    }
}
Онлайн: 2
Реклама