File: AbstractTransferEventTest.php

package info (click to toggle)
php-guzzlehttp 5.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,560 kB
  • ctags: 2,519
  • sloc: php: 11,610; makefile: 182; python: 22; sh: 6
file content (49 lines) | stat: -rw-r--r-- 1,729 bytes parent folder | download
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
<?php
namespace GuzzleHttp\Tests\Event;

use GuzzleHttp\Client;
use GuzzleHttp\Message\Response;
use GuzzleHttp\Transaction;
use GuzzleHttp\Message\Request;

/**
 * @covers GuzzleHttp\Event\AbstractTransferEvent
 */
class AbstractTransferEventTest extends \PHPUnit_Framework_TestCase
{
    public function testHasStats()
    {
        $t = new Transaction(new Client(), new Request('GET', '/'));
        $t->transferInfo = ['foo' => 'bar'];
        $e = $this->getMockBuilder('GuzzleHttp\Event\AbstractTransferEvent')
            ->setConstructorArgs([$t])
            ->getMockForAbstractClass();
        $this->assertNull($e->getTransferInfo('baz'));
        $this->assertEquals('bar', $e->getTransferInfo('foo'));
        $this->assertEquals($t->transferInfo, $e->getTransferInfo());
    }

    public function testHasResponse()
    {
        $t = new Transaction(new Client(), new Request('GET', '/'));
        $t->response = new Response(200);
        $e = $this->getMockBuilder('GuzzleHttp\Event\AbstractTransferEvent')
            ->setConstructorArgs([$t])
            ->getMockForAbstractClass();
        $this->assertTrue($e->hasResponse());
        $this->assertSame($t->response, $e->getResponse());
    }

    public function testCanInterceptWithResponse()
    {
        $t = new Transaction(new Client(), new Request('GET', '/'));
        $r = new Response(200);
        $e = $this->getMockBuilder('GuzzleHttp\Event\AbstractTransferEvent')
            ->setConstructorArgs([$t])
            ->getMockForAbstractClass();
        $e->intercept($r);
        $this->assertSame($t->response, $r);
        $this->assertSame($t->response, $e->getResponse());
        $this->assertTrue($e->isPropagationStopped());
    }
}