Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit fe846d3

Browse files
committed
Merge branch 'hotfix/139'
Close #139
2 parents d03fa37 + 8548073 commit fe846d3

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/CallbackStream.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ public function read($length)
154154
public function getContents()
155155
{
156156
$callback = $this->detach();
157-
158157
return $callback ? $callback() : '';
159158
}
160159

test/CallbackStreamTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@
1818
*/
1919
class CallbackStreamTest extends TestCase
2020
{
21+
/**
22+
* Sample callback to use with testing.
23+
*
24+
* @return string
25+
*/
26+
public function sampleCallback()
27+
{
28+
return __METHOD__;
29+
}
30+
31+
/**
32+
* Sample static callback to use with testing.
33+
*
34+
* @return string
35+
*/
36+
public static function sampleStaticCallback()
37+
{
38+
return __METHOD__;
39+
}
40+
2141
public function testToString()
2242
{
2343
$stream = new CallbackStream(function () {
@@ -177,4 +197,26 @@ public function testGetMetadata()
177197
$notExists = $stream->getMetadata('boo');
178198
$this->assertNull($notExists);
179199
}
200+
201+
public function phpCallbacksForStreams()
202+
{
203+
$class = 'ZendTest\Diactoros\CallbackStreamTest';
204+
205+
// @codingStandardsIgnoreStart
206+
return [
207+
'instance-method' => [[new self(), 'sampleCallback'], $class . '::sampleCallback'],
208+
'static-method' => [[$class, 'sampleStaticCallback'], $class . '::sampleStaticCallback'],
209+
];
210+
// @codingStandardsIgnoreEnd
211+
}
212+
213+
/**
214+
* @dataProvider phpCallbacksForStreams
215+
*/
216+
public function testAllowsArbitraryPhpCallbacks($callback, $expected)
217+
{
218+
$stream = new CallbackStream($callback);
219+
$contents = $stream->getContents();
220+
$this->assertEquals($expected, $contents);
221+
}
180222
}

0 commit comments

Comments
 (0)