diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/AllTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/AllTest.php new file mode 100644 index 000000000..8fadcfb77 --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/AllTest.php @@ -0,0 +1,56 @@ +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 + ); + } +} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/AnyTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/AnyTest.php new file mode 100644 index 000000000..20ab92bb4 --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/AnyTest.php @@ -0,0 +1,56 @@ +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 + ); + } +} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/WhenTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/WhenTest.php new file mode 100644 index 000000000..ee4f8170b --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/WhenTest.php @@ -0,0 +1,50 @@ +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 + ); + } +}