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

namespace GuzzleTestsPluginErrorResponse;

use 
GuzzleServiceClient;
use 
GuzzleHttpMessageResponse;
use 
GuzzlePluginErrorResponseErrorResponsePlugin;
use 
GuzzleServiceDescriptionServiceDescription;
use 
GuzzleTestsMockErrorResponseMock;

/**
 * @covers GuzzlePluginErrorResponseErrorResponsePlugin
 */
class ErrorResponsePluginTest extends GuzzleTestsGuzzleTestCase
{
    protected 
$client;

    public static function 
tearDownAfterClass()
    {
        
self::getServer()->flush();
    }

    public function 
setUp()
    {
        
$mockError 'GuzzleTestsMockErrorResponseMock';
        
$description ServiceDescription::factory(array(
            
'operations' => array(
                
'works' => array(
                    
'httpMethod' => 'GET',
                    
'errorResponses' => array(
                        array(
'code' => 500'class' => $mockError),
                        array(
'code' => 503'reason' => 'foo''class' => $mockError),
                        array(
'code' => 200'reason' => 'Error!''class' => $mockError)
                    )
                ),
                
'bad_class' => array(
                    
'httpMethod' => 'GET',
                    
'errorResponses' => array(
                        array(
'code' => 500'class' => 'Does\Not\Exist')
                    )
                ),
                
'does_not_implement' => array(
                    
'httpMethod' => 'GET',
                    
'errorResponses' => array(
                        array(
'code' => 500'class' => __CLASS__)
                    )
                ),
                
'no_errors' => array('httpMethod' => 'GET'),
                
'no_class' => array(
                    
'httpMethod' => 'GET',
                    
'errorResponses' => array(
                        array(
'code' => 500)
                    )
                ),
            )
        ));
        
$this->client = new Client($this->getServer()->getUrl());
        
$this->client->setDescription($description);
    }

    
/**
     * @expectedException GuzzleHttpExceptionServerErrorResponseException
     */
    
public function testSkipsWhenErrorResponsesIsNotSet()
    {
        
$this->getServer()->enqueue("HTTP/1.1 500 FoornContent-Length: 0rnrn");
        
$this->client->addSubscriber(new ErrorResponsePlugin());
        
$this->client->getCommand('no_errors')->execute();
    }

    public function 
testSkipsWhenErrorResponsesIsNotSetAndAllowsSuccess()
    {
        
$this->getServer()->enqueue("HTTP/1.1 200 OKrnContent-Length: 0rnrn");
        
$this->client->addSubscriber(new ErrorResponsePlugin());
        
$this->client->getCommand('no_errors')->execute();
    }

    
/**
     * @expectedException GuzzlePluginErrorResponseExceptionErrorResponseException
     * @expectedExceptionMessage DoesNotExist does not exist
     */
    
public function testEnsuresErrorResponseExists()
    {
        
$this->getServer()->enqueue("HTTP/1.1 500 FoornContent-Length: 0rnrn");
        
$this->client->addSubscriber(new ErrorResponsePlugin());
        
$this->client->getCommand('bad_class')->execute();
    }

    
/**
     * @expectedException GuzzlePluginErrorResponseExceptionErrorResponseException
     * @expectedExceptionMessage must implement GuzzlePluginErrorResponseErrorResponseExceptionInterface
     */
    
public function testEnsuresErrorResponseImplementsInterface()
    {
        
$this->getServer()->enqueue("HTTP/1.1 500 FoornContent-Length: 0rnrn");
        
$this->client->addSubscriber(new ErrorResponsePlugin());
        
$this->client->getCommand('does_not_implement')->execute();
    }

    public function 
testThrowsSpecificErrorResponseOnMatch()
    {
        try {
            
$this->getServer()->enqueue("HTTP/1.1 500 FoornContent-Length: 0rnrn");
            
$this->client->addSubscriber(new ErrorResponsePlugin());
            
$command $this->client->getCommand('works');
            
$command->execute();
            
$this->fail('Exception not thrown');
        } catch (
ErrorResponseMock $e) {
            
$this->assertSame($command$e->command);
            
$this->assertEquals(500$e->response->getStatusCode());
        }
    }

    
/**
     * @expectedException GuzzleTestsMockErrorResponseMock
     */
    
public function testThrowsWhenCodeAndPhraseMatch()
    {
        
$this->getServer()->enqueue("HTTP/1.1 200 Error!rnContent-Length: 0rnrn");
        
$this->client->addSubscriber(new ErrorResponsePlugin());
        
$this->client->getCommand('works')->execute();
    }

    public function 
testSkipsWhenReasonDoesNotMatch()
    {
        
$this->getServer()->enqueue("HTTP/1.1 200 OKrnContent-Length: 0rnrn");
        
$this->client->addSubscriber(new ErrorResponsePlugin());
        
$this->client->getCommand('works')->execute();
    }

    public function 
testSkipsWhenNoClassIsSet()
    {
        
$this->getServer()->enqueue("HTTP/1.1 200 OKrnContent-Length: 0rnrn");
        
$this->client->addSubscriber(new ErrorResponsePlugin());
        
$this->client->getCommand('no_class')->execute();
    }
}
Онлайн: 0
Реклама