CaiWuXiTong/tests/Unit/Console/BusinessDataArchiveStreamTest.php

31 lines
991 B
PHP

<?php
namespace Tests\Unit\Console;
use App\Console\Commands\BackfillBusinessDataColumnar;
use GuzzleHttp\Psr7\PumpStream;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;
class BusinessDataArchiveStreamTest extends TestCase
{
public function test_non_seekable_parquet_stream_is_spooled_to_a_seekable_resource(): void
{
$chunks = ['PAR1-', 'fixture'];
$stream = new PumpStream(static function () use (&$chunks): string|false {
return array_shift($chunks) ?? false;
});
$this->assertFalse($stream->isSeekable());
$method = new ReflectionMethod(BackfillBusinessDataColumnar::class, 'seekableResource');
$resource = $method->invoke(new BackfillBusinessDataColumnar(), $stream);
try {
$this->assertTrue(stream_get_meta_data($resource)['seekable']);
$this->assertSame('PAR1-fixture', stream_get_contents($resource));
} finally {
fclose($resource);
}
}
}