1<?php
2
3namespace Sabre\HTTP;
4
5class MessageDecoratorTest extends \PHPUnit_Framework_TestCase {
6
7    protected $inner;
8    protected $outer;
9
10    function setUp() {
11
12        $this->inner = new Request();
13        $this->outer = new RequestDecorator($this->inner);
14
15    }
16
17    function testBody() {
18
19        $this->outer->setBody('foo');
20        $this->assertEquals('foo', stream_get_contents($this->inner->getBodyAsStream()));
21        $this->assertEquals('foo', stream_get_contents($this->outer->getBodyAsStream()));
22        $this->assertEquals('foo', $this->inner->getBodyAsString());
23        $this->assertEquals('foo', $this->outer->getBodyAsString());
24        $this->assertEquals('foo', $this->inner->getBody());
25        $this->assertEquals('foo', $this->outer->getBody());
26
27    }
28
29    function testHeaders() {
30
31        $this->outer->setHeaders([
32            'a' => 'b',
33            ]);
34
35        $this->assertEquals(['a' => ['b']], $this->inner->getHeaders());
36        $this->assertEquals(['a' => ['b']], $this->outer->getHeaders());
37
38        $this->outer->setHeaders([
39            'c' => 'd',
40        ]);
41
42        $this->assertEquals(['a' => ['b'], 'c' => ['d']], $this->inner->getHeaders());
43        $this->assertEquals(['a' => ['b'], 'c' => ['d']], $this->outer->getHeaders());
44
45        $this->outer->addHeaders([
46            'e' => 'f',
47            ]);
48
49        $this->assertEquals(['a' => ['b'], 'c' => ['d'], 'e' => ['f']], $this->inner->getHeaders());
50        $this->assertEquals(['a' => ['b'], 'c' => ['d'], 'e' => ['f']], $this->outer->getHeaders());
51    }
52
53    function testHeader() {
54
55        $this->assertFalse($this->outer->hasHeader('a'));
56        $this->assertFalse($this->inner->hasHeader('a'));
57        $this->outer->setHeader('a', 'c');
58        $this->assertTrue($this->outer->hasHeader('a'));
59        $this->assertTrue($this->inner->hasHeader('a'));
60
61        $this->assertEquals('c', $this->inner->getHeader('A'));
62        $this->assertEquals('c', $this->outer->getHeader('A'));
63
64        $this->outer->addHeader('A', 'd');
65
66        $this->assertEquals(
67            ['c', 'd'],
68            $this->inner->getHeaderAsArray('A')
69        );
70        $this->assertEquals(
71            ['c', 'd'],
72            $this->outer->getHeaderAsArray('A')
73        );
74
75        $this->outer->removeHeader('a');
76
77        $this->assertNull($this->inner->getHeader('A'));
78        $this->assertNull($this->outer->getHeader('A'));
79    }
80
81    function testHttpVersion() {
82
83        $this->outer->setHttpVersion('1.0');
84
85        $this->assertEquals('1.0', $this->inner->getHttpVersion());
86        $this->assertEquals('1.0', $this->outer->getHttpVersion());
87
88    }
89
90}
91