diff --git a/src/core/etl/README.md b/src/core/etl/README.md index 30cbd5750..dcf171946 100644 --- a/src/core/etl/README.md +++ b/src/core/etl/README.md @@ -215,7 +215,6 @@ Adapters might also define some custom transformers. * [clone entry](src/Flow/ETL/Transformer/CloneEntryTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/CloneEntryTransformerTest.php) * [dynamic entry](src/Flow/ETL/Transformer/DynamicEntryTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/DynamicEntryTransformerTest.php) * [entry name style converter](src/Flow/ETL/Transformer/EntryNameStyleConverterTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/DynamicEntryTransformerTest.php) - * [filter rows](src/Flow/ETL/Transformer/FilterRowsTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/FilterRowsTransformerTest.php) * [group to array](src/Flow/ETL/Transformer/GroupToArrayTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/GroupToArrayTransformerTest.php) * [keep entries](src/Flow/ETL/Transformer/KeepEntriesTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/KeepEntriesTransformerTest.php) * [remove entries](src/Flow/ETL/Transformer/RemoveEntriesTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/RemoveEntriesTransformerTest.php) diff --git a/src/core/etl/docs/complex_transformers.md b/src/core/etl/docs/complex_transformers.md index c0481a6eb..ae1f2e808 100644 --- a/src/core/etl/docs/complex_transformers.md +++ b/src/core/etl/docs/complex_transformers.md @@ -15,12 +15,6 @@ Available Filters - [all](../src/Flow/ETL/Transformer/Filter/Filter/All.php) - [any](../src/Flow/ETL/Transformer/Filter/Filter/Any.php) - [callback](../src/Flow/ETL/Transformer/Filter/Filter/Callback.php) -- [entry equals to](../src/Flow/ETL/Transformer/Filter/Filter/EntryEqualsTo.php) -- [entry not equals to](../src/Flow/ETL/Transformer/Filter/Filter/EntryNotEqualsTo.php) -- [entry not null](../src/Flow/ETL/Transformer/Filter/Filter/EntryNotNull.php) -- [entry not number](../src/Flow/ETL/Transformer/Filter/Filter/EntryNotNumber.php) -- [entry number](../src/Flow/ETL/Transformer/Filter/Filter/EntryNumber.php) -- [entry exists](../src/Flow/ETL/Transformer/Filter/Filter/EntryExists.php) - [opposite](../src/Flow/ETL/Transformer/Filter/Filter/Opposite.php) #### Transformer - Conditional diff --git a/src/core/etl/src/Flow/ETL/DSL/Transform.php b/src/core/etl/src/Flow/ETL/DSL/Transform.php index 68ae23ea9..3a7953a58 100644 --- a/src/core/etl/src/Flow/ETL/DSL/Transform.php +++ b/src/core/etl/src/Flow/ETL/DSL/Transform.php @@ -25,12 +25,6 @@ use Flow\ETL\Transformer\Cast\EntryCaster\DateTimeToStringEntryCaster; use Flow\ETL\Transformer\Cast\EntryCaster\StringToDateTimeEntryCaster; use Flow\ETL\Transformer\CastTransformer; -use Flow\ETL\Transformer\Filter\Filter\EntryEqualsTo; -use Flow\ETL\Transformer\Filter\Filter\EntryExists; -use Flow\ETL\Transformer\Filter\Filter\EntryNotNull; -use Flow\ETL\Transformer\Filter\Filter\EntryNumber; -use Flow\ETL\Transformer\Filter\Filter\Opposite; -use Flow\ETL\Transformer\FilterRowsTransformer; use Flow\ETL\Transformer\KeepEntriesTransformer; use Flow\ETL\Transformer\Rename\EntryRename; use Flow\ETL\Transformer\RenameEntriesTransformer; @@ -154,46 +148,6 @@ final public static function dynamic(callable $generator) : Transformer return new Transformer\DynamicEntryTransformer($generator); } - final public static function filter_equals(string $entry, mixed $value) : Transformer - { - return new FilterRowsTransformer(new EntryEqualsTo($entry, $value)); - } - - final public static function filter_exists(string $entry) : Transformer - { - return new FilterRowsTransformer(new EntryExists($entry)); - } - - final public static function filter_not_equals(string $entry, mixed $value) : Transformer - { - return new FilterRowsTransformer(new Opposite(new EntryEqualsTo($entry, $value))); - } - - final public static function filter_not_exists(string $entry) : Transformer - { - return new FilterRowsTransformer(new Opposite(new EntryExists($entry))); - } - - final public static function filter_not_null(string $entry) : Transformer - { - return new FilterRowsTransformer(new EntryNotNull($entry)); - } - - final public static function filter_not_number(string $entry) : Transformer - { - return new FilterRowsTransformer(new Opposite(new EntryNumber($entry))); - } - - final public static function filter_null(string $entry) : Transformer - { - return new FilterRowsTransformer(new Opposite(new EntryNotNull($entry))); - } - - final public static function filter_number(string $entry) : Transformer - { - return new FilterRowsTransformer(new EntryNumber($entry)); - } - final public static function group_to_array(string $group_by_entry, string $new_entry_name) : Transformer { return new Transformer\GroupToArrayTransformer($group_by_entry, $new_entry_name); diff --git a/src/core/etl/src/Flow/ETL/Row/Reference/EntryExpression.php b/src/core/etl/src/Flow/ETL/Row/Reference/EntryExpression.php index e061b4475..4ac14f437 100644 --- a/src/core/etl/src/Flow/ETL/Row/Reference/EntryExpression.php +++ b/src/core/etl/src/Flow/ETL/Row/Reference/EntryExpression.php @@ -18,7 +18,9 @@ use Flow\ETL\Row\Reference\Expression\GreaterThanEqual; use Flow\ETL\Row\Reference\Expression\IsIn; use Flow\ETL\Row\Reference\Expression\IsNotNull; +use Flow\ETL\Row\Reference\Expression\IsNotNumeric; use Flow\ETL\Row\Reference\Expression\IsNull; +use Flow\ETL\Row\Reference\Expression\IsNumeric; use Flow\ETL\Row\Reference\Expression\IsType; use Flow\ETL\Row\Reference\Expression\LessThan; use Flow\ETL\Row\Reference\Expression\LessThanEqual; @@ -176,11 +178,21 @@ public function isNotNull() : Expression|EntryReference return new Expressions(new IsNotNull($this)); } + public function isNotNumeric() : Expression|EntryReference + { + return new Expressions(new IsNotNumeric($this)); + } + public function isNull() : Expression|EntryReference { return new Expressions(new IsNull($this)); } + public function isNumeric() : Expression|EntryReference + { + return new Expressions(new IsNumeric($this)); + } + public function isOdd() : Expression|EntryReference { return new NotEquals(new Mod($this, lit(2)), lit(0)); diff --git a/src/core/etl/src/Flow/ETL/Row/Reference/Expression/IsNotNumeric.php b/src/core/etl/src/Flow/ETL/Row/Reference/Expression/IsNotNumeric.php new file mode 100644 index 000000000..b775bb105 --- /dev/null +++ b/src/core/etl/src/Flow/ETL/Row/Reference/Expression/IsNotNumeric.php @@ -0,0 +1,21 @@ +ref->eval($row)); + } +} diff --git a/src/core/etl/src/Flow/ETL/Row/Reference/Expression/IsNumeric.php b/src/core/etl/src/Flow/ETL/Row/Reference/Expression/IsNumeric.php new file mode 100644 index 000000000..dceb11526 --- /dev/null +++ b/src/core/etl/src/Flow/ETL/Row/Reference/Expression/IsNumeric.php @@ -0,0 +1,21 @@ +ref->eval($row)); + } +} diff --git a/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryEqualsTo.php b/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryEqualsTo.php deleted file mode 100644 index 3ac2b5b89..000000000 --- a/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryEqualsTo.php +++ /dev/null @@ -1,58 +0,0 @@ - - */ -final class EntryEqualsTo implements Filter -{ - public function __construct( - private string $entryName, - private mixed $entryValue - ) { - } - - public function __serialize() : array - { - return [ - 'entry_name' => $this->entryName, - 'entry_value' => $this->entryValue, - ]; - } - - public function __unserialize(array $data) : void - { - $this->entryName = $data['entry_name']; - $this->entryValue = $data['entry_value']; - } - - public function keep(Row $row) : bool - { - $entry = $row->get($this->entryName); - - if ($entry instanceof Row\Entry\FloatEntry) { - if (!\is_numeric($this->entryValue)) { - return false; - } - - return \bccomp((string) $entry->value(), (string) $this->entryValue, 8) === 0; - } - - if (\is_float($this->entryValue)) { - if (!\is_numeric($entry->value())) { - return false; - } - - /** @psalm-suppress ArgumentTypeCoercion */ - return \bccomp((string) $entry->value(), (string) $this->entryValue, 8) === 0; - } - - return $entry->value() === $this->entryValue; - } -} diff --git a/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryExists.php b/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryExists.php deleted file mode 100644 index cdea71946..000000000 --- a/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryExists.php +++ /dev/null @@ -1,35 +0,0 @@ - - */ -final class EntryExists implements Filter -{ - public function __construct(private string $entryName) - { - } - - public function __serialize() : array - { - return [ - 'entry_name' => $this->entryName, - ]; - } - - public function __unserialize(array $data) : void - { - $this->entryName = $data['entry_name']; - } - - public function keep(Row $row) : bool - { - return $row->entries()->has($this->entryName); - } -} diff --git a/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryNotEqualsTo.php b/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryNotEqualsTo.php deleted file mode 100644 index 99ba68826..000000000 --- a/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryNotEqualsTo.php +++ /dev/null @@ -1,50 +0,0 @@ - - */ -final class EntryNotEqualsTo implements Filter -{ - /** - * @param mixed $entryValue - */ - public function __construct(private string $entryName, private $entryValue) - { - } - - public function __serialize() : array - { - return [ - 'entry_name' => $this->entryName, - 'entry_value' => $this->entryValue, - ]; - } - - public function __unserialize(array $data) : void - { - $this->entryName = $data['entry_name']; - $this->entryValue = $data['entry_value']; - } - - public function keep(Row $row) : bool - { - $entry = $row->get($this->entryName); - - if ($entry instanceof Row\Entry\FloatEntry) { - if (!\is_numeric($this->entryValue)) { - return false; - } - - return \bccomp((string) $entry->value(), (string) $this->entryValue, 8) !== 0; - } - - return $entry->value() !== $this->entryValue; - } -} diff --git a/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryNotNull.php b/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryNotNull.php deleted file mode 100644 index f4520c4dd..000000000 --- a/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryNotNull.php +++ /dev/null @@ -1,35 +0,0 @@ - - */ -final class EntryNotNull implements Filter -{ - public function __construct(private string $entryName) - { - } - - public function __serialize() : array - { - return [ - 'entry_name' => $this->entryName, - ]; - } - - public function __unserialize(array $data) : void - { - $this->entryName = $data['entry_name']; - } - - public function keep(Row $row) : bool - { - return !$row->get($this->entryName) instanceof Row\Entry\NullEntry; - } -} diff --git a/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryNotNumber.php b/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryNotNumber.php deleted file mode 100644 index cd1e7e07c..000000000 --- a/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryNotNumber.php +++ /dev/null @@ -1,35 +0,0 @@ - - */ -final class EntryNotNumber implements Filter -{ - public function __construct(private string $entryName) - { - } - - public function __serialize() : array - { - return [ - 'entry_name' => $this->entryName, - ]; - } - - public function __unserialize(array $data) : void - { - $this->entryName = $data['entry_name']; - } - - public function keep(Row $row) : bool - { - return !\is_numeric($row->get($this->entryName)->value()); - } -} diff --git a/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryNumber.php b/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryNumber.php deleted file mode 100644 index 963fa3555..000000000 --- a/src/core/etl/src/Flow/ETL/Transformer/Filter/Filter/EntryNumber.php +++ /dev/null @@ -1,35 +0,0 @@ - - */ -final class EntryNumber implements Filter -{ - public function __construct(private string $entryName) - { - } - - public function __serialize() : array - { - return [ - 'entry_name' => $this->entryName, - ]; - } - - public function __unserialize(array $data) : void - { - $this->entryName = $data['entry_name']; - } - - public function keep(Row $row) : bool - { - return \is_numeric($row->get($this->entryName)->value()); - } -} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/AllTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/AllTest.php index e2b91820d..fa5d96f53 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/AllTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/AllTest.php @@ -8,29 +8,27 @@ use Flow\ETL\Row; use Flow\ETL\Transformer\Filter\Filter\All; use Flow\ETL\Transformer\Filter\Filter\Callback; -use Flow\ETL\Transformer\Filter\Filter\EntryNotNumber; -use Flow\ETL\Transformer\Filter\Filter\EntryNumber; use PHPUnit\Framework\TestCase; final class AllTest extends TestCase { public function test_that_all_filters_are_satisfied() : void { - $filter = new All(new EntryNotNumber('test-entry'), new Callback(fn (Row $row) : bool => true)); + $filter = new All(new Callback(fn (Row $row) : bool => true), new Callback(fn (Row $row) : bool => true)); $this->assertTrue($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value')))); } public function test_that_none_filter_is_satisfied() : void { - $filter = new All(new EntryNumber('test-entry'), new Callback(fn (Row $row) : bool => false)); + $filter = new All(new Callback(fn (Row $row) : bool => false), new Callback(fn (Row $row) : bool => false)); $this->assertFalse($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value')))); } public function test_that_not_all_filters_are_satisfied() : void { - $filter = new All(new EntryNotNumber('test-entry'), new Callback(fn (Row $row) : bool => false)); + $filter = new All(new Callback(fn (Row $row) : bool => false)); $this->assertFalse($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value')))); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/AnyTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/AnyTest.php index b67a95265..98d2b9699 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/AnyTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/AnyTest.php @@ -8,29 +8,27 @@ use Flow\ETL\Row; use Flow\ETL\Transformer\Filter\Filter\Any; use Flow\ETL\Transformer\Filter\Filter\Callback; -use Flow\ETL\Transformer\Filter\Filter\EntryNotNumber; -use Flow\ETL\Transformer\Filter\Filter\EntryNumber; use PHPUnit\Framework\TestCase; final class AnyTest extends TestCase { public function test_that_all_filters_are_satisfied() : void { - $filter = new Any(new EntryNotNumber('test-entry'), new Callback(fn (Row $row) : bool => true)); + $filter = new Any(new Callback(fn (Row $row) : bool => true), new Callback(fn (Row $row) : bool => true)); $this->assertTrue($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value')))); } public function test_that_none_filter_is_satisfied() : void { - $filter = new Any(new EntryNumber('test-entry'), new Callback(fn (Row $row) : bool => false)); + $filter = new Any(new Callback(fn (Row $row) : bool => false), new Callback(fn (Row $row) : bool => false)); $this->assertFalse($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value')))); } public function test_that_not_all_filters_are_satisfied() : void { - $filter = new Any(new EntryNotNumber('test-entry'), new Callback(fn (Row $row) : bool => false)); + $filter = new Any(new Callback(fn (Row $row) : bool => false), new Callback(fn (Row $row) : bool => true)); $this->assertTrue($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value')))); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryEqualsToTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryEqualsToTest.php deleted file mode 100644 index f1718029e..000000000 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryEqualsToTest.php +++ /dev/null @@ -1,78 +0,0 @@ -assertFalse($filter->keep(Row::create(Entry::string('float-entry', 'test')))); - } - - public function test_float_entry_equals_to_integer() : void - { - $filter = new EntryEqualsTo('float-entry', 10.00); - - $this->assertTrue($filter->keep(Row::create(Entry::integer('float-entry', 10)))); - } - - public function test_float_entry_equals_to_not_numeric() : void - { - $filter = new EntryEqualsTo('float-entry', 'something'); - - $this->assertFalse($filter->keep(Row::create(Entry::float('float-entry', 1.0001003)))); - } - - public function test_float_entry_equals_to_numeric() : void - { - $filter = new EntryEqualsTo('float-entry', 10.01); - - $this->assertTrue($filter->keep(Row::create(Entry::string('float-entry', '10.01')))); - } - - public function test_float_entry_not_equals() : void - { - $filter = new EntryEqualsTo('float-entry', 1.0001003); - - $this->assertTrue($filter->keep(Row::create(Entry::float('float-entry', 1.0001003)))); - $this->assertFalse($filter->keep(Row::create(Entry::float('float-entry', 1.0002003)))); - } - - public function test_that_entry_is_not_a_string() : void - { - $filter = new EntryEqualsTo('test-entry', 'test-value'); - - $this->assertFalse($filter->keep(Row::create(Entry::json('test-entry', [])))); - } - - public function test_that_integer_entry_is_equals_to_other_integer() : void - { - $filter = new EntryEqualsTo('integer-entry', 200); - - $this->assertFalse($filter->keep(Row::create(Entry::integer('integer-entry', 404)))); - $this->assertTrue($filter->keep(Row::create(Entry::integer('integer-entry', 200)))); - } - - public function test_that_string_entry_is_equals_to() : void - { - $filter = new EntryEqualsTo('test-entry', 'test-value'); - - $this->assertTrue($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value')))); - } - - public function test_that_string_entry_is_not_equals_to() : void - { - $filter = new EntryEqualsTo('test-entry', 'test-value'); - - $this->assertFalse($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value-random')))); - } -} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryExistsTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryExistsTest.php deleted file mode 100644 index 5a3072382..000000000 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryExistsTest.php +++ /dev/null @@ -1,27 +0,0 @@ -assertTrue($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value')))); - } - - public function test_entry_not_exists() : void - { - $filter = new EntryExists('test-entry'); - - $this->assertFalse($filter->keep(Row::create(Entry::string_upper('production-entry', 'test-value')))); - } -} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryNotEqualsToTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryNotEqualsToTest.php deleted file mode 100644 index 81fd19669..000000000 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryNotEqualsToTest.php +++ /dev/null @@ -1,44 +0,0 @@ -assertFalse($filter->keep(Row::create(Entry::float('float-entry', 1.0001003)))); - $this->assertTrue($filter->keep(Row::create(Entry::float('float-entry', 1.0002003)))); - } - - public function test_float_entry_not_equals_to_not_numeric() : void - { - $filter = new EntryNotEqualsTo('float-entry', 'not_numeric'); - - $this->assertFalse($filter->keep(Row::create(Entry::float('float-entry', 1.0001003)))); - } - - public function test_that_integer_entry_is_not_equals_to_other_integer() : void - { - $filter = new EntryNotEqualsTo('integer-entry', 200); - - $this->assertTrue($filter->keep(Row::create(Entry::integer('integer-entry', 404)))); - $this->assertFalse($filter->keep(Row::create(Entry::integer('integer-entry', 200)))); - } - - public function test_that_string_entry_is_not_equals_to_other_string() : void - { - $filter = new EntryNotEqualsTo('test-entry', 'test-value'); - - $this->assertTrue($filter->keep(Row::create(Entry::string_lower('test-entry', 'not-same-value')))); - $this->assertFalse($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value')))); - } -} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryNotNullTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryNotNullTest.php deleted file mode 100644 index df52b7cc7..000000000 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryNotNullTest.php +++ /dev/null @@ -1,27 +0,0 @@ -assertFalse($filter->keep(Row::create(Entry::null('test-entry')))); - } - - public function test_that_string_entry_is_not_null() : void - { - $filter = new EntryNotNull('test-entry'); - - $this->assertTrue($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value')))); - } -} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryNotNumberTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryNotNumberTest.php deleted file mode 100644 index d878d00ab..000000000 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryNotNumberTest.php +++ /dev/null @@ -1,41 +0,0 @@ -assertFalse($filter->keep(Row::create(Entry::float('test-entry', 1.02)))); - } - - public function test_that_integer_entry_is_number() : void - { - $filter = new EntryNotNumber('test-entry'); - - $this->assertFalse($filter->keep(Row::create(Entry::integer('test-entry', 1)))); - } - - public function test_that_string_entry_is_not_number() : void - { - $filter = new EntryNotNumber('test-entry'); - - $this->assertTrue($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value')))); - } - - public function test_that_string_number_entry_is_number() : void - { - $filter = new EntryNotNumber('test-entry'); - - $this->assertFalse($filter->keep(Row::create(Entry::string('test-entry', '1.02')))); - } -} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryNumberTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryNumberTest.php deleted file mode 100644 index 779851af3..000000000 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/EntryNumberTest.php +++ /dev/null @@ -1,41 +0,0 @@ -assertTrue($filter->keep(Row::create(Entry::float('test-entry', 1.02)))); - } - - public function test_that_integer_entry_is_number() : void - { - $filter = new EntryNumber('test-entry'); - - $this->assertTrue($filter->keep(Row::create(Entry::integer('test-entry', 1)))); - } - - public function test_that_string_entry_is_not_number() : void - { - $filter = new EntryNumber('test-entry'); - - $this->assertFalse($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value')))); - } - - public function test_that_string_number_entry_is_number() : void - { - $filter = new EntryNumber('test-entry'); - - $this->assertTrue($filter->keep(Row::create(Entry::string('test-entry', '1.02')))); - } -} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/OppositeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/OppositeTest.php index 1cf05f2d8..28a7cebb6 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/OppositeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Filter/OppositeTest.php @@ -6,30 +6,23 @@ use Flow\ETL\DSL\Entry; use Flow\ETL\Row; -use Flow\ETL\Transformer\Filter\Filter\EntryNumber; +use Flow\ETL\Transformer\Filter\Filter\Callback; use Flow\ETL\Transformer\Filter\Filter\Opposite; use PHPUnit\Framework\TestCase; final class OppositeTest extends TestCase { - public function test_that_float_entry_is_number() : void + public function test_that_filter_is_matched() : void { - $filter = new Opposite(new EntryNumber('test-entry')); + $filter = new Opposite(new Callback(fn (Row $row) : bool => true)); $this->assertFalse($filter->keep(Row::create(Entry::float('test-entry', 1.02)))); } - public function test_that_integer_entry_is_number() : void + public function test_that_filter_is_not_matched() : void { - $filter = new Opposite(new EntryNumber('test-entry')); + $filter = new Opposite(new Callback(fn (Row $row) : bool => false)); - $this->assertFalse($filter->keep(Row::create(Entry::integer('test-entry', 1)))); - } - - public function test_that_string_entry_is_not_number() : void - { - $filter = new Opposite(new EntryNumber('test-entry')); - - $this->assertTrue($filter->keep(Row::create(Entry::string_lower('test-entry', 'test-value')))); + $this->assertTrue($filter->keep(Row::create(Entry::integer('test-entry', 1)))); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Reference/Expression/BinaryComparisionsTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Reference/Expression/BinaryComparisionsTest.php index 5f9494ed4..884f21bc8 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Reference/Expression/BinaryComparisionsTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Reference/Expression/BinaryComparisionsTest.php @@ -17,7 +17,9 @@ use Flow\ETL\Row\Reference\Expression\GreaterThanEqual; use Flow\ETL\Row\Reference\Expression\IsIn; use Flow\ETL\Row\Reference\Expression\IsNotNull; +use Flow\ETL\Row\Reference\Expression\IsNotNumeric; use Flow\ETL\Row\Reference\Expression\IsNull; +use Flow\ETL\Row\Reference\Expression\IsNumeric; use Flow\ETL\Row\Reference\Expression\IsType; use Flow\ETL\Row\Reference\Expression\LessThan; use Flow\ETL\Row\Reference\Expression\LessThanEqual; @@ -79,6 +81,20 @@ public function test_is_in() : void $this->assertTrue((new IsIn(ref('b'), ref('e')))->eval($row)); } + public function test_is_numeric() : void + { + $row = Row::create( + Entry::integer('a', 100), + Entry::null('b'), + ); + $this->assertTrue((new IsNumeric(ref('a')))->eval($row)); + $this->assertFalse((new IsNumeric(ref('b')))->eval($row)); + $this->assertFalse((new IsNotNumeric(ref('a')))->eval($row)); + $this->assertTrue((new IsNotNumeric(ref('b')))->eval($row)); + $this->assertTrue((new IsNotNumeric(lit(null)))->eval($row)); + $this->assertTrue((new IsNumeric(lit(1000)))->eval($row)); + } + public function test_is_type() : void { $row = Row::create( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/FilterRowsTransformerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/FilterRowsTransformerTest.php deleted file mode 100644 index 997e98ab3..000000000 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/FilterRowsTransformerTest.php +++ /dev/null @@ -1,119 +0,0 @@ -transform( - new Rows( - Row::create(new Row\Entry\IntegerEntry('number', 2), new Row\Entry\StringEntry('text', 'test')), - Row::create(new Row\Entry\StringEntry('text', 'test')), - ), - new FlowContext(Config::default()) - ); - - $this->assertEquals( - [ - ['number' => 2, 'text' => 'test'], - ], - $rows->toArray() - ); - } - - public function test_entry_not_exists_in_rows() : void - { - $filterRows = Transform::filter_not_exists('number'); - - $rows = $filterRows->transform( - new Rows( - Row::create(new Row\Entry\IntegerEntry('number', 2), new Row\Entry\StringEntry('text', 'test')), - Row::create(new Row\Entry\StringEntry('text', 'test')), - ), - new FlowContext(Config::default()) - ); - - $this->assertEquals( - [ - ['text' => 'test'], - ], - $rows->toArray() - ); - } - - public function test_filter_null_rows() : void - { - $filterRows = Transform::filter_not_null('number'); - - $rows = $filterRows->transform( - new Rows( - Row::create(new Row\Entry\IntegerEntry('number', 2), new Row\Entry\StringEntry('text', 'test')), - Row::create(new Row\Entry\NullEntry('number'), new Row\Entry\StringEntry('text', 'test')), - Row::create(new Row\Entry\IntegerEntry('number', 5), new Row\Entry\StringEntry('text', 'test')), - ), - new FlowContext(Config::default()) - ); - - $this->assertEquals( - [ - ['number' => 2, 'text' => 'test'], - ['number' => 5, 'text' => 'test'], - ], - $rows->toArray() - ); - } - - public function test_filter_numeric_rows() : void - { - $filterRows = Transform::filter_equals('number', 5); - - $rows = $filterRows->transform( - new Rows( - Row::create(new Row\Entry\IntegerEntry('number', 2)), - Row::create(new Row\Entry\IntegerEntry('number', 10)), - Row::create(new Row\Entry\IntegerEntry('number', 5)), - ), - new FlowContext(Config::default()) - ); - - $this->assertEquals( - [ - ['number' => 5], - ], - $rows->toArray() - ); - } - - public function test_filter_string_rows() : void - { - $filterRows = Transform::filter_equals('status', 'NEW'); - - $rows = $filterRows->transform( - new Rows( - Row::create(new Row\Entry\StringEntry('status', 'PENDING')), - Row::create(new Row\Entry\StringEntry('status', 'SHIPPED')), - Row::create(new Row\Entry\StringEntry('status', 'NEW')), - ), - new FlowContext(Config::default()) - ); - - $this->assertEquals( - [ - ['status' => 'NEW'], - ], - $rows->toArray() - ); - } -}