Some checks failed
Deploy Application / deploy (push) Has been cancelled
102 lines
3.2 KiB
PHP
102 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Framework\LiveComponents\E2E;
|
|
|
|
use App\Framework\LiveComponents\Batch\BatchProcessor;
|
|
use App\Framework\LiveComponents\Batch\BatchRequest;
|
|
use App\Framework\LiveComponents\ValueObjects\BatchOperation;
|
|
use Tests\Feature\Framework\LiveComponents\TestHarness\LiveComponentTestCase;
|
|
|
|
/**
|
|
* E2E Tests for Batch Operations
|
|
*
|
|
* Tests batch request processing end-to-end.
|
|
*/
|
|
class BatchOperationsE2ETest extends LiveComponentTestCase
|
|
{
|
|
private BatchProcessor $batchProcessor;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->batchProcessor = $this->getContainer()->get(BatchProcessor::class);
|
|
}
|
|
|
|
public function test_processes_multiple_operations_in_batch(): void
|
|
{
|
|
// Create batch request with multiple operations
|
|
$operations = [
|
|
BatchOperation::fromArray([
|
|
'componentId' => 'counter:test1',
|
|
'method' => 'increment',
|
|
'params' => ['amount' => 1],
|
|
]),
|
|
BatchOperation::fromArray([
|
|
'componentId' => 'counter:test2',
|
|
'method' => 'increment',
|
|
'params' => ['amount' => 2],
|
|
]),
|
|
];
|
|
|
|
$batchRequest = new BatchRequest(...$operations);
|
|
$response = $this->batchProcessor->process($batchRequest);
|
|
|
|
$this->assertEquals(2, $response->totalOperations);
|
|
$this->assertEquals(2, $response->successCount);
|
|
$this->assertEquals(0, $response->failureCount);
|
|
$this->assertTrue($response->isFullSuccess());
|
|
}
|
|
|
|
public function test_handles_partial_failures_gracefully(): void
|
|
{
|
|
// Create batch with one valid and one invalid operation
|
|
$operations = [
|
|
BatchOperation::fromArray([
|
|
'componentId' => 'counter:test1',
|
|
'method' => 'increment',
|
|
'params' => ['amount' => 1],
|
|
]),
|
|
BatchOperation::fromArray([
|
|
'componentId' => 'nonexistent:test',
|
|
'method' => 'increment',
|
|
'params' => [],
|
|
]),
|
|
];
|
|
|
|
$batchRequest = new BatchRequest(...$operations);
|
|
$response = $this->batchProcessor->process($batchRequest);
|
|
|
|
$this->assertEquals(2, $response->totalOperations);
|
|
$this->assertEquals(1, $response->successCount);
|
|
$this->assertEquals(1, $response->failureCount);
|
|
$this->assertTrue($response->hasPartialFailure());
|
|
}
|
|
|
|
public function test_supports_fragments_in_batch_operations(): void
|
|
{
|
|
$operations = [
|
|
BatchOperation::fromArray([
|
|
'componentId' => 'counter:test1',
|
|
'method' => 'increment',
|
|
'params' => ['amount' => 5],
|
|
'fragments' => ['counter-display'],
|
|
]),
|
|
];
|
|
|
|
$batchRequest = new BatchRequest(...$operations);
|
|
$response = $this->batchProcessor->process($batchRequest);
|
|
|
|
$this->assertEquals(1, $response->successCount);
|
|
$result = $response->getSuccessfulResults()[0];
|
|
$this->assertTrue($result->hasFragments());
|
|
$this->assertArrayHasKey('counter-display', $result->fragments);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|