diff --git a/src/Internal/EtlBuilderTrait.php b/src/Internal/EtlBuilderTrait.php index 079964a..dc28406 100644 --- a/src/Internal/EtlBuilderTrait.php +++ b/src/Internal/EtlBuilderTrait.php @@ -95,11 +95,12 @@ public function withOptions(EtlConfiguration $configuration): self public function withRecipe(Recipe|callable $recipe, Recipe|callable ...$recipes): self { + $executor = $this; foreach ([$recipe, ...$recipes] as $_recipe) { if (!$_recipe instanceof Recipe) { $_recipe = Recipe::fromCallable($_recipe); } - $executor = $_recipe->decorate($this); + $executor = $_recipe->decorate($executor); } return $executor; diff --git a/tests/Unit/Recipe/RecipeTest.php b/tests/Unit/Recipe/RecipeTest.php index f740f9b..a9b0005 100644 --- a/tests/Unit/Recipe/RecipeTest.php +++ b/tests/Unit/Recipe/RecipeTest.php @@ -23,12 +23,15 @@ function (EtlExecutor $executor) use (&$hasReceivedInitEvent, &$hasReceivedEndEv $hasReceivedEndEvent = true; }); }, + fn (EtlExecutor $executor) => $executor->withContext(['foo' => 'bar']) ); // When - $executor->process([]); + $report = $executor->process([]); // Then expect($hasReceivedInitEvent)->toBeTrue() - ->and($hasReceivedEndEvent)->toBeTrue(); + ->and($hasReceivedEndEvent)->toBeTrue() + ->and($report->context)->toBe(['foo' => 'bar']) + ; });