-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent double etl evaluation in buffered response (#1499)
- Loading branch information
1 parent
be1a274
commit 50f21d1
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...tests/Flow/Bridge/Symfony/HttpFoundation/Tests/Unit/Response/FlowBufferedResponseTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\Bridge\Symfony\HttpFoundation\Tests\Unit\Response; | ||
|
||
use function Flow\Bridge\Symfony\HttpFoundation\{http_json_output, http_stream_open}; | ||
use function Flow\ETL\DSL\{from_array, int_entry, row, rows}; | ||
use Flow\ETL\Extractor; | ||
use Flow\ETL\Tests\FlowTestCase; | ||
|
||
final class FlowBufferedResponseTest extends FlowTestCase | ||
{ | ||
public function test_response_from_empty_dataset() : void | ||
{ | ||
$response = http_stream_open(from_array([]))->response(http_json_output()); | ||
|
||
self::assertEquals('', $response->getContent()); | ||
self::assertEquals(204, $response->getStatusCode()); | ||
} | ||
|
||
public function test_response_is_buffered_only_once() : void | ||
{ | ||
$extractor = $this->createMock(Extractor::class); | ||
|
||
$extractor->expects(self::once())->method('extract')->willReturn((function () : \Generator { | ||
yield rows(row(int_entry('id', 1))); | ||
})()); | ||
|
||
$response = http_stream_open($extractor)->response(http_json_output()); | ||
|
||
$response->getContent(); | ||
$response->getContent(); | ||
|
||
self::assertEquals('[{"id":1}]', $response->getContent()); | ||
self::assertEquals(200, $response->getStatusCode()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...tests/Flow/Bridge/Symfony/HttpFoundation/Tests/Unit/Response/FlowStreamedResponseTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\Bridge\Symfony\HttpFoundation\Tests\Unit\Response; | ||
|
||
use function Flow\Bridge\Symfony\HttpFoundation\{http_json_output, http_stream_open}; | ||
use function Flow\ETL\DSL\from_array; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class FlowStreamedResponseTest extends TestCase | ||
{ | ||
public function test_response_from_empty_dataset() : void | ||
{ | ||
$response = http_stream_open(from_array([]))->streamedResponse(http_json_output()); | ||
|
||
self::assertEquals('', $response->getContent()); | ||
self::assertEquals(200, $response->getStatusCode()); | ||
} | ||
} |