diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/SizeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/SizeTest.php new file mode 100644 index 000000000..6a3c50649 --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/SizeTest.php @@ -0,0 +1,85 @@ +read( + From::array( + [ + ['array' => [1, 2, 3]], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('size', ref('array')->size()) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['array' => [1, 2, 3], 'size' => 3], + ], + $memory->data + ); + } + + public function test_size_on_non_string_key() : void + { + $this->expectException(RuntimeException::class); + + (new Flow()) + ->read( + From::array( + [ + ['id' => 1], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('size', ref('id')->size()) + ->run(); + } + + public function test_size_on_string() : void + { + (new Flow()) + ->read( + From::array( + [ + ['key' => 'value'], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('size', ref('key')->size()) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['key' => 'value', 'size' => 5], + ], + $memory->data + ); + } +} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/SprintfTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/SprintfTest.php new file mode 100644 index 000000000..94c953d0b --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/SprintfTest.php @@ -0,0 +1,91 @@ +read( + From::array( + [ + ['key' => 'test %s'], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('sprintf', ref('key')->sprintf(lit('value'))) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['key' => 'test %s', 'sprintf' => 'test value'], + ], + $memory->data + ); + } + + public function test_sprintf_on_non_string_key() : void + { + (new Flow()) + ->read( + From::array( + [ + ['id' => 1], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('sprintf', ref('id')->sprintf(lit('1'))) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['id' => 1, 'sprintf' => null], + ], + $memory->data + ); + } + + public function test_sprintf_on_null_value() : void + { + (new Flow()) + ->read( + From::array( + [ + ['id' => '1'], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('sprintf', ref('id')->sprintf(lit(null))) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['id' => '1', 'sprintf' => null], + ], + $memory->data + ); + } +} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/StrPadTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/StrPadTest.php new file mode 100644 index 000000000..201fec189 --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/StrPadTest.php @@ -0,0 +1,65 @@ +read( + From::array( + [ + ['key' => 'value'], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('strpad', ref('key')->strPad(10, '*')) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['key' => 'value', 'strpad' => 'value*****'], + ], + $memory->data + ); + } + + public function test_strpad_on_non_string_key() : void + { + (new Flow()) + ->read( + From::array( + [ + ['id' => 1], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('strpad', ref('id')->strPad(10)) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['id' => 1, 'strpad' => null], + ], + $memory->data + ); + } +} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/StrReplaceTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/StrReplaceTest.php new file mode 100644 index 000000000..9ff71f03d --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/StrReplaceTest.php @@ -0,0 +1,65 @@ +read( + From::array( + [ + ['key' => 'value'], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('str_replace', ref('key')->strReplace('e', 'es')) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['key' => 'value', 'str_replace' => 'values'], + ], + $memory->data + ); + } + + public function test_str_replace_on_non_string_key() : void + { + (new Flow()) + ->read( + From::array( + [ + ['id' => 1], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('str_replace', ref('id')->strReplace('', '')) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['id' => 1, 'str_replace' => null], + ], + $memory->data + ); + } +} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ToLowerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ToLowerTest.php new file mode 100644 index 000000000..86df3f468 --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ToLowerTest.php @@ -0,0 +1,65 @@ +read( + From::array( + [ + ['key' => 'VALUE'], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('to_lower', ref('key')->lower()) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['key' => 'VALUE', 'to_lower' => 'value'], + ], + $memory->data + ); + } + + public function test_to_lower_on_non_string_key() : void + { + (new Flow()) + ->read( + From::array( + [ + ['id' => 1], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('to_lower', ref('id')->lower()) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['id' => 1, 'to_lower' => 1], + ], + $memory->data + ); + } +} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ToUpperTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ToUpperTest.php new file mode 100644 index 000000000..8a94f5964 --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ToUpperTest.php @@ -0,0 +1,65 @@ +read( + From::array( + [ + ['key' => 'value'], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('to_upper', ref('key')->upper()) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['key' => 'value', 'to_upper' => 'VALUE'], + ], + $memory->data + ); + } + + public function test_to_upper_on_non_string_key() : void + { + (new Flow()) + ->read( + From::array( + [ + ['id' => 1], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('to_upper', ref('id')->upper()) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['id' => 1, 'to_upper' => 1], + ], + $memory->data + ); + } +} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/TrimTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/TrimTest.php new file mode 100644 index 000000000..54d3089e6 --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/TrimTest.php @@ -0,0 +1,141 @@ +read( + From::array( + [ + ['key' => ' value '], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('trim', ref('key')->trim()) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['key' => ' value ', 'trim' => 'value'], + ], + $memory->data + ); + } + + public function test_trim_custom_characters() : void + { + (new Flow()) + ->read( + From::array( + [ + ['key' => '-value '], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('trim', ref('key')->trim(characters: '-')) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['key' => '-value ', 'trim' => 'value '], + ], + $memory->data + ); + } + + public function test_trim_left() : void + { + (new Flow()) + ->read( + From::array( + [ + ['key' => ' value '], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('trim', ref('key')->trim(Type::LEFT)) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['key' => ' value ', 'trim' => 'value '], + ], + $memory->data + ); + } + + public function test_trim_on_non_string_key() : void + { + (new Flow()) + ->read( + From::array( + [ + ['id' => 1], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('trim', ref('id')->trim()) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['id' => 1, 'trim' => null], + ], + $memory->data + ); + } + + public function test_trim_right() : void + { + (new Flow()) + ->read( + From::array( + [ + ['key' => ' value '], + ] + ) + ) + ->withEntry('row', ref('row')->unpack()) + ->renameAll('row.', '') + ->drop('row') + ->withEntry('trim', ref('key')->trim(Type::RIGHT)) + ->write(To::memory($memory = new ArrayMemory())) + ->run(); + + $this->assertSame( + [ + ['key' => ' value ', 'trim' => ' value'], + ], + $memory->data + ); + } +}