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

namespace GuzzleTestsPluginRedirect;

use 
GuzzleHttpClient;
use 
GuzzleHttpStaticClient;
use 
GuzzlePluginMockMockPlugin;
use 
GuzzleHttpMessageResponse;
use 
GuzzleStreamStream;

/**
 * @covers GuzzleHttpStaticClient
 */
class StaticClientTest extends GuzzleTestsGuzzleTestCase
{
    public function 
testMountsClient()
    {
        
$client = new Client();
        
StaticClient::mount('FooBazBar'$client);
        
$this->assertTrue(class_exists('FooBazBar'));
        
$this->assertSame($client$this->readAttribute('GuzzleHttpStaticClient''client'));
    }

    public function 
requestProvider()
    {
        return 
array_map(
            function (
$m) { return array($m); },
            array(
'GET''POST''PUT''DELETE''PATCH''HEAD''OPTIONS')
        );
    }

    
/**
     * @dataProvider requestProvider
     */
    
public function testSendsRequests($method)
    {
        
$mock = new MockPlugin(array(new Response(200)));
        
call_user_func('GuzzleHttpStaticClient::' $method'http://foo.com', array(
            
'plugins' => array($mock)
        ));
        
$requests $mock->getReceivedRequests();
        
$this->assertCount(1$requests);
        
$this->assertEquals($method$requests[0]->getMethod());
    }

    public function 
testCanCreateStreamsUsingDefaultFactory()
    {
        
$this->getServer()->enqueue(array("HTTP/1.1 200 OKrnContent-Length: 4rnrntest"));
        
$stream StaticClient::get($this->getServer()->getUrl(), array('stream' => true));
        
$this->assertInstanceOf('GuzzleStreamStreamInterface'$stream);
        
$this->assertEquals('test', (string) $stream);
    }

    public function 
testCanCreateStreamsUsingCustomFactory()
    {
        
$stream $this->getMockBuilder('GuzzleStreamStreamRequestFactoryInterface')
            ->
setMethods(array('fromRequest'))
            ->
getMockForAbstractClass();
        
$resource = new Stream(fopen('php://temp''r+'));
        
$stream->expects($this->once())
            ->
method('fromRequest')
            ->
will($this->returnValue($resource));
        
$this->getServer()->enqueue(array("HTTP/1.1 200 OKrnContent-Length: 4rnrntest"));
        
$result StaticClient::get($this->getServer()->getUrl(), array('stream' => $stream));
        
$this->assertSame($resource$result);
    }
}
Онлайн: 2
Реклама