summaryrefslogtreecommitdiff
path: root/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Exception/MultiTransferExceptionTest.php
blob: fa4ec2626300c73d51146bc8b2b2788811894e81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php

namespace Guzzle\Tests\Http\Exception;

use Guzzle\Http\Exception\MultiTransferException;
use Guzzle\Http\Curl\CurlHandle;
use Guzzle\Http\Message\Request;

/**
 * @covers Guzzle\Http\Exception\MultiTransferException
 */
class MultiTransferExceptionTest extends \Guzzle\Tests\GuzzleTestCase
{
    public function testHasRequests()
    {
        $r1 = new Request('GET', 'http://www.foo.com');
        $r2 = new Request('GET', 'http://www.foo.com');
        $e = new MultiTransferException();
        $e->addSuccessfulRequest($r1);
        $e->addFailedRequest($r2);
        $this->assertEquals(array($r1), $e->getSuccessfulRequests());
        $this->assertEquals(array($r2), $e->getSuccessfulRequests());
        $this->assertEquals(array($r1, $r2), $e->getAllRequests());
        $this->assertTrue($e->containsRequest($r1));
        $this->assertTrue($e->containsRequest($r2));
        $this->assertFalse($e->containsRequest(new Request('POST', '/foo')));
    }

    public function testCanSetRequests()
    {
        $s = array($r1 = new Request('GET', 'http://www.foo.com'));
        $f = array($r2 = new Request('GET', 'http://www.foo.com'));
        $e = new MultiTransferException();
        $e->setSuccessfulRequests($s);
        $e->setFailedRequests($f);
        $this->assertEquals(array($r1), $e->getSuccessfulRequests());
        $this->assertEquals(array($r2), $e->getSuccessfulRequests());
    }

    public function testAssociatesExceptionsWithRequests()
    {
        $r1 = new Request('GET', 'http://www.foo.com');
        $re1 = new \Exception('foo');
        $re2 = new \Exception('bar');
        $e = new MultiTransferException();
        $e->add($re2);
        $e->addFailedRequestWithException($r1, $re1);
        $this->assertSame($re1, $e->getExceptionForFailedRequest($r1));
        $this->assertNull($e->getExceptionForFailedRequest(new Request('POST', '/foo')));
    }
}