Skip to content

Commit 81d91b5

Browse files
mvanhornclaude
andcommitted
test: parse NDJSON documents in getTaskDocuments test
Show how to access individual documents from the stream by splitting NDJSON lines, decoding each, and asserting structure. Fixes phpstan alreadyNarrowedType error by removing redundant assertInstanceOf check. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 902ee12 commit 81d91b5

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

tests/Endpoints/TasksTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Meilisearch\Endpoints\Indexes;
1515
use Meilisearch\Exceptions\ApiException;
1616
use Meilisearch\Http\Client;
17-
use Psr\Http\Message\StreamInterface;
1817
use Tests\TestCase;
1918

2019
final class TasksTest extends TestCase
@@ -59,9 +58,13 @@ public function testGetTaskDocumentsClient(): void
5958

6059
$stream = $this->client->getTaskDocuments($task->getTaskUid());
6160

62-
self::assertInstanceOf(StreamInterface::class, $stream);
63-
$content = (string) $stream;
64-
self::assertNotEmpty($content);
61+
// Parse NDJSON: each line is a separate JSON document
62+
$lines = array_filter(explode("\n", (string) $stream), fn (string $line) => '' !== trim($line));
63+
self::assertNotEmpty($lines, 'Stream should contain at least one NDJSON line');
64+
65+
$documents = array_map(fn (string $line) => json_decode($line, true, 512, \JSON_THROW_ON_ERROR), $lines);
66+
self::assertNotEmpty($documents);
67+
self::assertArrayHasKey('id', $documents[0], 'Each document should have an id field');
6568
}
6669

6770
public function testGetAllTasksClient(): void

0 commit comments

Comments
 (0)