From 384122dea09de86be26c720e1a3514635262bd42 Mon Sep 17 00:00:00 2001 From: LamLam1 Date: Sat, 12 Sep 2026 15:24:58 +0800 Subject: [PATCH] feat!: move to workflow-engine-core 2.0 Core 2.0 is a `fix!` release that corrects silent-success defects, and two of those corrections are visible here: - `WorkflowBuilder::email()` is now `fakeEmail()`, and the step it adds is `FakeEmailAction`. The rename is the point: the old method never sent anything, so a workflow that "emailed" a user silently did nothing. Tests updated to the honest name. - A failed workflow may now transition back to running, so it can be retried. Completed and cancelled remain terminal. The assertion that this was forbidden is inverted, with a note saying why. 74 tests pass against core 2.0.0; Pint clean. Co-Authored-By: Claude Opus 5 --- composer.json | 2 +- tests/Unit/AdvancedFeaturesTest.php | 8 ++++---- tests/Unit/DocumentationExamplesTest.php | 12 ++++++------ tests/Unit/PHP83FeaturesTest.php | 12 +++++++----- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 2c0378c..a545b9c 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "illuminate/database": "^10.0||^11.0||^12.0||^13.0", "illuminate/events": "^10.0||^11.0||^12.0||^13.0", "illuminate/support": "^10.0||^11.0||^12.0||^13.0", - "solution-forest/workflow-engine-core": "^1.0" + "solution-forest/workflow-engine-core": "^2.0" }, "conflict": { "laravel/framework": "<11.0.0" diff --git a/tests/Unit/AdvancedFeaturesTest.php b/tests/Unit/AdvancedFeaturesTest.php index b522602..ae7529a 100644 --- a/tests/Unit/AdvancedFeaturesTest.php +++ b/tests/Unit/AdvancedFeaturesTest.php @@ -16,7 +16,7 @@ test('email action configuration matches documentation examples', function () { $workflow = WorkflowBuilder::create('email-test') - ->email( + ->fakeEmail( 'welcome-email', '{{ user.email }}', 'Welcome to {{ app.name }}!', @@ -101,7 +101,7 @@ ->version('1.5') ->startWith(CreateUserProfileAction::class, ['profile_type' => 'basic']) ->then(SendWelcomeEmailAction::class) - ->email('tips-email', '{{ user.email }}', 'Getting Started Tips') + ->fakeEmail('tips-email', '{{ user.email }}', 'Getting Started Tips') ->delay(minutes: 5) ->when('user.premium = true', function ($builder) { $builder->then(VerifyIdentityAction::class); @@ -116,7 +116,7 @@ $stepClasses = array_map(fn ($step) => $step->getActionClass(), $workflow->getSteps()); expect($stepClasses)->toContain(CreateUserProfileAction::class); expect($stepClasses)->toContain(SendWelcomeEmailAction::class); - expect($stepClasses)->toContain('SolutionForest\\WorkflowEngine\\Actions\\EmailAction'); + expect($stepClasses)->toContain('SolutionForest\\WorkflowEngine\\Actions\\FakeEmailAction'); expect($stepClasses)->toContain('SolutionForest\\WorkflowEngine\\Actions\\DelayAction'); expect($stepClasses)->toContain(VerifyIdentityAction::class); expect($stepClasses)->toContain('SolutionForest\\WorkflowEngine\\Actions\\HttpAction'); @@ -149,7 +149,7 @@ test('complex workflow execution with all features', function () { $workflow = WorkflowBuilder::create('integration-test') ->startWith(CreateUserProfileAction::class, ['profile_type' => 'premium']) - ->email('welcome-email', '{{ user.email }}', 'Welcome Premium User!') + ->fakeEmail('welcome-email', '{{ user.email }}', 'Welcome Premium User!') ->delay(seconds: 1) // Short delay for testing ->when('user.age >= 21', function ($builder) { $builder->addStep('age_verification', VerifyIdentityAction::class, [], '30s', 2); diff --git a/tests/Unit/DocumentationExamplesTest.php b/tests/Unit/DocumentationExamplesTest.php index 03c800b..c40f6a7 100644 --- a/tests/Unit/DocumentationExamplesTest.php +++ b/tests/Unit/DocumentationExamplesTest.php @@ -19,9 +19,9 @@ test('getting started - basic workflow creation works', function () { $registrationWorkflow = WorkflowBuilder::create('user-registration') ->addStep('create-profile', CreateUserProfileAction::class) - ->email('welcome-email', '{{ user.email }}', 'Welcome!') + ->fakeEmail('welcome-email', '{{ user.email }}', 'Welcome!') ->delay(hours: 24) - ->email('tips-email', '{{ user.email }}', 'Getting Started Tips') + ->fakeEmail('tips-email', '{{ user.email }}', 'Getting Started Tips') ->build(); expect($registrationWorkflow)->not->toBeNull(); @@ -129,14 +129,14 @@ test('api reference - email method works', function () { $workflow = WorkflowBuilder::create('email-workflow') - ->email('welcome-email', '{{ user.email }}', 'Welcome {{ user.name }}!', ['welcome_bonus' => 100]) + ->fakeEmail('welcome-email', '{{ user.email }}', 'Welcome {{ user.name }}!', ['welcome_bonus' => 100]) ->build(); expect($workflow->getSteps())->toHaveCount(1); $steps = $workflow->getSteps(); $step = $steps['email_1']; - expect($step->getActionClass())->toBe('SolutionForest\\WorkflowEngine\\Actions\\EmailAction'); + expect($step->getActionClass())->toBe('SolutionForest\\WorkflowEngine\\Actions\\FakeEmailAction'); expect($step->getConfig()['template'])->toBe('welcome-email'); expect($step->getConfig()['to'])->toBe('{{ user.email }}'); expect($step->getConfig()['subject'])->toBe('Welcome {{ user.name }}!'); @@ -235,7 +235,7 @@ ->description('A complex workflow showcasing all features') ->version('2.0') ->startWith(CreateUserProfileAction::class, ['profile_type' => 'premium']) - ->email('welcome-email', '{{ user.email }}', 'Welcome to Premium!') + ->fakeEmail('welcome-email', '{{ user.email }}', 'Welcome to Premium!') ->when('user.age >= 21', function ($builder) { $builder->addStep('age-verification', VerifyIdentityAction::class, [], '60s', 2); }) @@ -258,7 +258,7 @@ ->description('A complex workflow showcasing all features') ->version('2.0') ->startWith(CreateUserProfileAction::class, ['profile_type' => 'premium']) - ->email('welcome-email', '{{ user.email }}', 'Welcome to Premium!') + ->fakeEmail('welcome-email', '{{ user.email }}', 'Welcome to Premium!') ->when('user.age >= 21', function ($builder) { $builder->addStep('age-verification', VerifyIdentityAction::class, [], '60s', 2); }) diff --git a/tests/Unit/PHP83FeaturesTest.php b/tests/Unit/PHP83FeaturesTest.php index 34b80f8..f3d21a8 100644 --- a/tests/Unit/PHP83FeaturesTest.php +++ b/tests/Unit/PHP83FeaturesTest.php @@ -23,7 +23,7 @@ ->version('2.0') ->startWith(LogAction::class, ['message' => 'Starting workflow']) ->then(DelayAction::class, ['seconds' => 1]) - ->email( + ->fakeEmail( template: 'test', to: '{{ user.email }}', subject: 'Test Email' @@ -66,7 +66,9 @@ // Test invalid transitions expect(WorkflowState::COMPLETED->canTransitionTo(WorkflowState::RUNNING))->toBeFalse(); - expect(WorkflowState::FAILED->canTransitionTo(WorkflowState::RUNNING))->toBeFalse(); + // Core 2.0 allows a failed workflow to be retried, so this is a valid + // transition now; completed and cancelled remain terminal. + expect(WorkflowState::FAILED->canTransitionTo(WorkflowState::RUNNING))->toBeTrue(); expect(WorkflowState::CANCELLED->canTransitionTo(WorkflowState::RUNNING))->toBeFalse(); }); @@ -91,7 +93,7 @@ it('can create workflow with common patterns using helper methods', function () { $workflow = WorkflowBuilder::create('helper-test') - ->email( + ->fakeEmail( template: 'welcome', to: 'user@example.com', subject: 'Welcome!' @@ -109,7 +111,7 @@ expect($steps)->toHaveCount(4); // Check email step - expect($steps[0]->getActionClass())->toBe('SolutionForest\\WorkflowEngine\\Actions\\EmailAction'); + expect($steps[0]->getActionClass())->toBe('SolutionForest\\WorkflowEngine\\Actions\\FakeEmailAction'); expect($steps[0]->getConfig()['template'])->toBe('welcome'); // Check delay step @@ -140,7 +142,7 @@ $workflow = WorkflowBuilder::create(name: 'named-args-test') ->description(description: 'Testing named arguments') ->version(version: '1.0') - ->email( + ->fakeEmail( template: 'test', to: 'test@example.com', subject: 'Test Subject',