1 | <?php |
||
13 | class HttpRequestTest extends PHPUnit_Framework_TestCase |
||
14 | { |
||
15 | /** |
||
16 | * An overview of how to use the RPCRequest class. |
||
17 | * @test |
||
18 | */ |
||
19 | public function synopsis() |
||
43 | |||
44 | /** |
||
45 | * Tests successful input stream set and fetch cases |
||
46 | */ |
||
47 | public function testInputStream() |
||
48 | { |
||
49 | $tempStream = fopen('php://memory', 'w'); |
||
50 | fwrite($tempStream, "test"); |
||
51 | rewind($tempStream); |
||
52 | |||
53 | /* Mock a stream in memory */ |
||
54 | $request = new HttpRequest('TestService', 'TestMethod', 'GET', $tempStream); |
||
55 | $this->assertEquals("test", $request->getBody()); |
||
56 | fclose($tempStream); |
||
57 | |||
58 | /* Fetch previously stored value */ |
||
59 | $this->assertEquals("test", $request->getBody()); |
||
60 | |||
61 | /* Specify php://memory as a string */ |
||
62 | $request = new HttpRequest('TestService', 'TestMethod', 'GET', 'php://memory'); |
||
63 | $this->assertEquals("", $request->getBody()); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Tests the input stream functionality where the stream source is not a string or a stream |
||
68 | * @expectedException Vectorface\SnappyRouter\Exception\InternalErrorException |
||
69 | */ |
||
70 | public function testInputStreamIncorrectTypeFailure() |
||
71 | { |
||
72 | $request = new HttpRequest('TestService', 'TestMethod', 'GET', 1); |
||
73 | $request->getBody(); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Tests the input stream functionality where the stream source does not exist |
||
78 | * @expectedException Vectorface\SnappyRouter\Exception\InternalErrorException |
||
79 | */ |
||
80 | public function testInputStreamIncorrectFileFailure() |
||
81 | { |
||
82 | $request = new HttpRequest('TestService', 'TestMethod', 'GET', 'file'); |
||
83 | $request->getBody(); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * Tests the various filters. |
||
88 | * @dataProvider filtersProvider |
||
89 | */ |
||
90 | public function testInputFilters($expected, $value, $filters) |
||
96 | |||
97 | /** |
||
98 | * The data provider for testInputFilters. |
||
99 | */ |
||
100 | public function filtersProvider() |
||
135 | } |
||
136 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: