-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for
when
, any
& all
expressions
- Loading branch information
Showing
3 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/AllTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Integration\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\all; | ||
use function Flow\ETL\DSL\lit; | ||
use function Flow\ETL\DSL\ref; | ||
use function Flow\ETL\DSL\when; | ||
use Flow\ETL\DSL\From; | ||
use Flow\ETL\DSL\To; | ||
use Flow\ETL\Flow; | ||
use Flow\ETL\Memory\ArrayMemory; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class AllTest extends TestCase | ||
{ | ||
public function test_all_cases_found() : void | ||
{ | ||
(new Flow()) | ||
->read( | ||
From::array( | ||
[ | ||
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], | ||
['id' => 2], | ||
['id' => 3], | ||
['id' => 4, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], | ||
] | ||
) | ||
) | ||
->withEntry('row', ref('row')->unpack()) | ||
->renameAll('row.', '') | ||
->withEntry( | ||
'result', | ||
when( | ||
all(ref('id')->isEven(), ref('array')->exists('b')), | ||
lit('found'), | ||
lit('not found') | ||
) | ||
) | ||
->drop('row', 'array') | ||
->write(To::memory($memory = new ArrayMemory())) | ||
->run(); | ||
|
||
$this->assertSame( | ||
[ | ||
['id' => 1, 'result' => 'not found'], | ||
['id' => 2, 'result' => 'not found'], | ||
['id' => 3, 'result' => 'not found'], | ||
['id' => 4, 'result' => 'found'], | ||
], | ||
$memory->data | ||
); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/AnyTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Integration\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\any; | ||
use function Flow\ETL\DSL\lit; | ||
use function Flow\ETL\DSL\ref; | ||
use function Flow\ETL\DSL\when; | ||
use Flow\ETL\DSL\From; | ||
use Flow\ETL\DSL\To; | ||
use Flow\ETL\Flow; | ||
use Flow\ETL\Memory\ArrayMemory; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class AnyTest extends TestCase | ||
{ | ||
public function test_any_case_found() : void | ||
{ | ||
(new Flow()) | ||
->read( | ||
From::array( | ||
[ | ||
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], | ||
['id' => 2], | ||
['id' => 3], | ||
['id' => 4, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], | ||
] | ||
) | ||
) | ||
->withEntry('row', ref('row')->unpack()) | ||
->renameAll('row.', '') | ||
->withEntry( | ||
'result', | ||
when( | ||
any(ref('id')->isEven(), ref('array')->exists('b')), | ||
lit('found'), | ||
lit('not found') | ||
) | ||
) | ||
->drop('row', 'array') | ||
->write(To::memory($memory = new ArrayMemory())) | ||
->run(); | ||
|
||
$this->assertSame( | ||
[ | ||
['id' => 1, 'result' => 'found'], | ||
['id' => 2, 'result' => 'found'], | ||
['id' => 3, 'result' => 'not found'], | ||
['id' => 4, 'result' => 'found'], | ||
], | ||
$memory->data | ||
); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/WhenTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Integration\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\lit; | ||
use function Flow\ETL\DSL\ref; | ||
use function Flow\ETL\DSL\when; | ||
use Flow\ETL\DSL\From; | ||
use Flow\ETL\DSL\To; | ||
use Flow\ETL\Flow; | ||
use Flow\ETL\Memory\ArrayMemory; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class WhenTest extends TestCase | ||
{ | ||
public function test_when_odd_even() : void | ||
{ | ||
(new Flow()) | ||
->read(From::sequence_number('id', 1, 10)) | ||
->collect() | ||
->withEntry( | ||
'type', | ||
when( | ||
ref('id')->isOdd(), | ||
lit('odd'), | ||
lit('even') | ||
) | ||
) | ||
->write(To::memory($memory = new ArrayMemory())) | ||
->run(); | ||
|
||
$this->assertSame( | ||
[ | ||
['id' => 1, 'type' => 'odd'], | ||
['id' => 2, 'type' => 'even'], | ||
['id' => 3, 'type' => 'odd'], | ||
['id' => 4, 'type' => 'even'], | ||
['id' => 5, 'type' => 'odd'], | ||
['id' => 6, 'type' => 'even'], | ||
['id' => 7, 'type' => 'odd'], | ||
['id' => 8, 'type' => 'even'], | ||
['id' => 9, 'type' => 'odd'], | ||
['id' => 10, 'type' => 'even'], | ||
], | ||
$memory->data | ||
); | ||
} | ||
} |