|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace BenTools\ETL\Tests\Unit; |
| 6 | + |
| 7 | +use BenTools\ETL\EtlExecutor; |
| 8 | + |
| 9 | +use function expect; |
| 10 | +use function it; |
| 11 | + |
| 12 | +it('provides a default context', function () { |
| 13 | + // Given |
| 14 | + $executor = (new EtlExecutor(context: ['color' => 'green', 'shape' => 'square', 'lights' => 'on'])); |
| 15 | + |
| 16 | + // When |
| 17 | + $report = $executor->process([], context: ['shape' => 'round', 'size' => 'small']); |
| 18 | + |
| 19 | + // Then |
| 20 | + expect($report->context)->toBe(['color' => 'green', 'shape' => 'round', 'lights' => 'on', 'size' => 'small']); |
| 21 | +}); |
| 22 | + |
| 23 | +it('adds some more context', function () { |
| 24 | + // Given |
| 25 | + $executor = (new EtlExecutor(context: ['color' => 'green', 'shape' => 'square', 'lights' => 'on'])) |
| 26 | + ->withContext(['color' => 'blue', 'flavor' => 'vanilla']); |
| 27 | + |
| 28 | + // When |
| 29 | + $report = $executor->process([], context: ['shape' => 'round', 'size' => 'small']); |
| 30 | + |
| 31 | + // Then |
| 32 | + expect($report->context)->toBe(['color' => 'blue', 'shape' => 'round', 'lights' => 'on', 'flavor' => 'vanilla', 'size' => 'small']); |
| 33 | +}); |
| 34 | + |
| 35 | +it('replaces the whole context', function () { |
| 36 | + // Given |
| 37 | + $executor = (new EtlExecutor(context: ['color' => 'green', 'shape' => 'square', 'lights' => 'on'])) |
| 38 | + ->withContext(['color' => 'blue', 'flavor' => 'vanilla'], clear: true); |
| 39 | + |
| 40 | + // When |
| 41 | + $report = $executor->process([], context: ['shape' => 'round', 'size' => 'small']); |
| 42 | + |
| 43 | + // Then |
| 44 | + expect($report->context)->toBe(['color' => 'blue', 'flavor' => 'vanilla', 'shape' => 'round', 'size' => 'small']); |
| 45 | +}); |
| 46 | + |
| 47 | +it('does not override existing values', function () { |
| 48 | + // Given |
| 49 | + $executor = (new EtlExecutor(context: ['color' => 'green', 'shape' => 'square', 'lights' => 'on'])) |
| 50 | + ->withContext(['color' => 'blue', 'flavor' => 'vanilla'], overwrite: false); |
| 51 | + |
| 52 | + // When |
| 53 | + $report = $executor->process([], context: ['shape' => 'round', 'size' => 'small']); |
| 54 | + |
| 55 | + // Then |
| 56 | + expect($report->context)->toBe(['color' => 'green', 'shape' => 'round', 'lights' => 'on', 'flavor' => 'vanilla', 'size' => 'small']); |
| 57 | +}); |
0 commit comments