Skip to content

Commit d32f25a

Browse files
committed
fix test for callable-iterable
1 parent 365f16c commit d32f25a

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

‎tests/system/HTTP/StreamResponseTest.php‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
namespace CodeIgniter\HTTP;
1515

1616
use CodeIgniter\Test\CIUnitTestCase;
17+
use Generator;
18+
use IteratorAggregate;
1719
use PHPUnit\Framework\Attributes\Group;
1820

1921
/**
@@ -80,8 +82,22 @@ public function testStatusCodeIsSettable(): void
8082

8183
public function testConstructorTreatsCallableIterableAsCallable(): void
8284
{
83-
// An array callable is both callable and iterable; callable must win.
84-
$response = new StreamResponse($this->writeHello(...));
85+
$callbackOrChunks = new class () implements IteratorAggregate {
86+
public function __invoke(StreamResponse $stream): void
87+
{
88+
$stream->write('Hello');
89+
}
90+
91+
/**
92+
* @return Generator<int, string>
93+
*/
94+
public function getIterator(): Generator
95+
{
96+
yield 'iterable chunk';
97+
}
98+
};
99+
100+
$response = new StreamResponse($callbackOrChunks);
85101
$response->pretend();
86102

87103
ob_start();
@@ -91,11 +107,6 @@ public function testConstructorTreatsCallableIterableAsCallable(): void
91107
$this->assertSame('Hello', $output);
92108
}
93109

94-
public function writeHello(StreamResponse $stream): void
95-
{
96-
$stream->write('Hello');
97-
}
98-
99110
public function testStreamFactoryReturnsStreamResponse(): void
100111
{
101112
$response = (new Response())->stream(static function (): void {

0 commit comments

Comments
 (0)