|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Tests\Feature\V2; |
| 6 | + |
| 7 | +use Tests\Fixtures\V2\TestUuidWorkflow; |
| 8 | +use Tests\TestCase; |
| 9 | +use Workflow\V2\Enums\HistoryEventType; |
| 10 | +use Workflow\V2\Models\WorkflowHistoryEvent; |
| 11 | +use Workflow\V2\WorkflowStub; |
| 12 | + |
| 13 | +final class V2UuidWorkflowTest extends TestCase |
| 14 | +{ |
| 15 | + protected function setUp(): void |
| 16 | + { |
| 17 | + parent::setUp(); |
| 18 | + |
| 19 | + config() |
| 20 | + ->set('queue.default', 'sync'); |
| 21 | + config() |
| 22 | + ->set('queue.connections.sync.driver', 'sync'); |
| 23 | + } |
| 24 | + |
| 25 | + public function testUuidHelpersRecordReplayStableUuid4AndUuid7Values(): void |
| 26 | + { |
| 27 | + WorkflowStub::fake(); |
| 28 | + |
| 29 | + $workflow = WorkflowStub::make(TestUuidWorkflow::class, 'uuid-helper-workflow'); |
| 30 | + $workflow->start(); |
| 31 | + |
| 32 | + $this->assertSame('waiting', $workflow->refresh()->status()); |
| 33 | + |
| 34 | + $queriedIds = $workflow->query('ids'); |
| 35 | + |
| 36 | + $this->assertMatchesRegularExpression( |
| 37 | + '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/', |
| 38 | + $queriedIds['uuid4'][0], |
| 39 | + ); |
| 40 | + $this->assertMatchesRegularExpression( |
| 41 | + '/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/', |
| 42 | + $queriedIds['uuid7'][0], |
| 43 | + ); |
| 44 | + $this->assertNotSame($queriedIds['uuid4'][0], $queriedIds['uuid4'][1]); |
| 45 | + $this->assertNotSame($queriedIds['uuid7'][0], $queriedIds['uuid7'][1]); |
| 46 | + $this->assertLessThan($queriedIds['uuid7'][1], $queriedIds['uuid7'][0]); |
| 47 | + |
| 48 | + $sideEffectEventsBeforeSignal = WorkflowHistoryEvent::query() |
| 49 | + ->where('workflow_run_id', $workflow->runId()) |
| 50 | + ->where('event_type', HistoryEventType::SideEffectRecorded) |
| 51 | + ->count(); |
| 52 | + |
| 53 | + $this->assertSame(4, $sideEffectEventsBeforeSignal); |
| 54 | + |
| 55 | + $workflow->signal('finish'); |
| 56 | + $this->assertTrue($workflow->refresh()->completed()); |
| 57 | + |
| 58 | + $this->assertSame($queriedIds, $workflow->output()); |
| 59 | + $this->assertSame( |
| 60 | + $sideEffectEventsBeforeSignal, |
| 61 | + WorkflowHistoryEvent::query() |
| 62 | + ->where('workflow_run_id', $workflow->runId()) |
| 63 | + ->where('event_type', HistoryEventType::SideEffectRecorded) |
| 64 | + ->count(), |
| 65 | + ); |
| 66 | + } |
| 67 | +} |
0 commit comments