-
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.
- Loading branch information
Showing
5 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
src/core/etl/src/Flow/ETL/Row/Reference/Expression/All.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Row\Reference\Expression; | ||
|
||
use Flow\ETL\Row; | ||
use Flow\ETL\Row\Reference\Expression; | ||
|
||
final class All implements Expression | ||
{ | ||
/** | ||
* @var array<Expression> | ||
*/ | ||
private readonly array $refs; | ||
|
||
public function __construct( | ||
Expression ...$refs, | ||
) { | ||
$this->refs = $refs; | ||
} | ||
|
||
public function eval(Row $row) : mixed | ||
{ | ||
foreach ($this->refs as $ref) { | ||
if (!$ref->eval($row)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/core/etl/src/Flow/ETL/Row/Reference/Expression/Any.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Row\Reference\Expression; | ||
|
||
use Flow\ETL\Row; | ||
use Flow\ETL\Row\Reference\Expression; | ||
|
||
final class Any implements Expression | ||
{ | ||
/** | ||
* @var array<Expression> | ||
*/ | ||
private readonly array $refs; | ||
|
||
public function __construct( | ||
Expression ...$refs, | ||
) { | ||
$this->refs = $refs; | ||
} | ||
|
||
public function eval(Row $row) : mixed | ||
{ | ||
foreach ($this->refs as $ref) { | ||
if ($ref->eval($row)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/core/etl/tests/Flow/ETL/Tests/Unit/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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Unit\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\all; | ||
use function Flow\ETL\DSL\lit; | ||
use function Flow\ETL\DSL\ref; | ||
use Flow\ETL\DSL\Entry; | ||
use Flow\ETL\Row; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class AllTest extends TestCase | ||
{ | ||
public function test_all_expression_on_boolean_false_value() : void | ||
{ | ||
$this->assertFalse( | ||
all(lit(false))->eval(Row::create()) | ||
); | ||
} | ||
|
||
public function test_all_expression_on_boolean_true_value() : void | ||
{ | ||
$this->assertTrue( | ||
all(lit(true))->eval(Row::create()) | ||
); | ||
} | ||
|
||
public function test_all_expression_on_is_null_expression() : void | ||
{ | ||
$this->assertTrue( | ||
all(ref('value')->isNull())->eval(Row::create(Entry::null('value'))) | ||
); | ||
} | ||
|
||
public function test_all_expression_on_multiple_boolean_values() : void | ||
{ | ||
$this->assertTrue( | ||
all(lit(true), lit(true), lit(true))->eval(Row::create()) | ||
); | ||
} | ||
|
||
public function test_all_expression_on_multiple_random_boolean_values() : void | ||
{ | ||
$this->assertFalse( | ||
all(lit(true), lit(false), lit(true))->eval(Row::create()) | ||
); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/core/etl/tests/Flow/ETL/Tests/Unit/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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Unit\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\any; | ||
use function Flow\ETL\DSL\lit; | ||
use function Flow\ETL\DSL\ref; | ||
use Flow\ETL\DSL\Entry; | ||
use Flow\ETL\Row; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class AnyTest extends TestCase | ||
{ | ||
public function test_any_expression_on_boolean_false_value() : void | ||
{ | ||
$this->assertFalse( | ||
any(lit(false))->eval(Row::create()) | ||
); | ||
} | ||
|
||
public function test_any_expression_on_boolean_true_value() : void | ||
{ | ||
$this->assertTrue( | ||
any(lit(true))->eval(Row::create()) | ||
); | ||
} | ||
|
||
public function test_any_expression_on_is_null_expression() : void | ||
{ | ||
$this->assertTrue( | ||
any(ref('value')->isNull())->eval(Row::create(Entry::null('value'))) | ||
); | ||
} | ||
|
||
public function test_any_expression_on_multiple_boolean_values() : void | ||
{ | ||
$this->assertTrue( | ||
any(lit(false), lit(true), lit(false))->eval(Row::create()) | ||
); | ||
} | ||
} |