-
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 array related expression
- Loading branch information
Showing
11 changed files
with
440 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
43 changes: 43 additions & 0 deletions
43
src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ArrayExistsTest.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\Integration\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\array_exists; | ||
use function Flow\ETL\DSL\ref; | ||
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 ArrayExistsTest extends TestCase | ||
{ | ||
public function test_array_exists() : void | ||
{ | ||
(new Flow()) | ||
->read( | ||
From::array( | ||
[ | ||
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], | ||
['id' => 2], | ||
] | ||
) | ||
) | ||
->withEntry('row', ref('row')->unpack()) | ||
->renameAll('row.', '') | ||
->withEntry('has_array', array_exists(ref('array'), 'a')) | ||
->drop('row', 'array') | ||
->write(To::memory($memory = new ArrayMemory())) | ||
->run(); | ||
|
||
$this->assertSame( | ||
[ | ||
['id' => 1, 'has_array' => true], | ||
['id' => 2, 'has_array' => false], | ||
], | ||
$memory->data | ||
); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ArrayGetCollectionTest.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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Integration\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\array_get_collection; | ||
use function Flow\ETL\DSL\ref; | ||
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 ArrayGetCollectionTest extends TestCase | ||
{ | ||
public function test_array_get_collection() : void | ||
{ | ||
(new Flow()) | ||
->read( | ||
From::array( | ||
[ | ||
['id' => 1, 'array' => [ | ||
['a' => 1, 'b' => 2, 'c' => 3], | ||
['a' => 1, 'b' => 2, 'c' => 3], | ||
['a' => 1, 'b' => 2, 'c' => 3], | ||
]], | ||
['id' => 2], | ||
] | ||
) | ||
) | ||
->withEntry('row', ref('row')->unpack()) | ||
->renameAll('row.', '') | ||
->withEntry('result', array_get_collection(ref('array'), 'a', 'c')) | ||
->drop('row', 'array') | ||
->write(To::memory($memory = new ArrayMemory())) | ||
->run(); | ||
|
||
$this->assertSame( | ||
[ | ||
['id' => 1, 'result' => [['a' => 1, 'c' => 3], ['a' => 1, 'c' => 3], ['a' => 1, 'c' => 3]]], | ||
['id' => 2, 'result' => null], | ||
], | ||
$memory->data | ||
); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ArrayGetTest.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\Integration\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\array_get; | ||
use function Flow\ETL\DSL\ref; | ||
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 ArrayGetTest extends TestCase | ||
{ | ||
public function test_array_get() : void | ||
{ | ||
(new Flow()) | ||
->read( | ||
From::array( | ||
[ | ||
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], | ||
['id' => 2], | ||
] | ||
) | ||
) | ||
->withEntry('row', ref('row')->unpack()) | ||
->renameAll('row.', '') | ||
->withEntry('result', array_get(ref('array'), 'b')) | ||
->drop('row', 'array') | ||
->write(To::memory($memory = new ArrayMemory())) | ||
->run(); | ||
|
||
$this->assertSame( | ||
[ | ||
['id' => 1, 'result' => 2], | ||
['id' => 2, 'result' => null], | ||
], | ||
$memory->data | ||
); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ArrayKeyRenameTest.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\Integration\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\array_key_rename; | ||
use function Flow\ETL\DSL\ref; | ||
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 ArrayKeyRenameTest extends TestCase | ||
{ | ||
public function test_array_key_rename() : void | ||
{ | ||
(new Flow()) | ||
->read( | ||
From::array( | ||
[ | ||
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], | ||
['id' => 2], | ||
] | ||
) | ||
) | ||
->withEntry('row', ref('row')->unpack()) | ||
->renameAll('row.', '') | ||
->withEntry('array', array_key_rename(ref('array'), 'a', 'd')) | ||
->drop('row') | ||
->write(To::memory($memory = new ArrayMemory())) | ||
->run(); | ||
|
||
$this->assertSame( | ||
[ | ||
['id' => 1, 'array' => ['b' => 2, 'c' => 3, 'd' => 1]], | ||
['id' => 2, 'array' => null], | ||
], | ||
$memory->data | ||
); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...l/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ArrayKeysStyleConvertTest.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,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Integration\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\array_keys_style_convert; | ||
use function Flow\ETL\DSL\ref; | ||
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 ArrayKeysStyleConvertTest extends TestCase | ||
{ | ||
public function test_array_keys_style_convert() : void | ||
{ | ||
(new Flow()) | ||
->read( | ||
From::array( | ||
[ | ||
['id' => 1, 'array' => ['camelCased' => 1, 'snake_cased' => 2, 'space word' => 3]], | ||
] | ||
) | ||
) | ||
->withEntry('row', ref('row')->unpack()) | ||
->renameAll('row.', '') | ||
->withEntry('array', array_keys_style_convert(ref('array'), 'kebab')) | ||
->drop('row') | ||
->write(To::memory($memory = new ArrayMemory())) | ||
->run(); | ||
|
||
$this->assertSame( | ||
[ | ||
['id' => 1, 'array' => ['camel-cased' => 1, 'snake-cased' => 2, 'space-word' => 3]], | ||
], | ||
$memory->data | ||
); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...tl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ArrayMergeCollectionTest.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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Integration\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\array_merge_collection; | ||
use function Flow\ETL\DSL\ref; | ||
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 ArrayMergeCollectionTest extends TestCase | ||
{ | ||
public function test_array_merge_collection() : void | ||
{ | ||
(new Flow()) | ||
->read( | ||
From::array( | ||
[ | ||
['id' => 1, 'array' => [ | ||
['a' => 1], | ||
['b' => 2], | ||
['c' => 3], | ||
]], | ||
['id' => 2], | ||
] | ||
) | ||
) | ||
->withEntry('row', ref('row')->unpack()) | ||
->renameAll('row.', '') | ||
->withEntry('result', array_merge_collection(ref('array'))) | ||
->drop('row', 'array') | ||
->write(To::memory($memory = new ArrayMemory())) | ||
->run(); | ||
|
||
$this->assertSame( | ||
[ | ||
['id' => 1, 'result' => ['a' => 1, 'b' => 2, 'c' => 3]], | ||
['id' => 2, 'result' => null], | ||
], | ||
$memory->data | ||
); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ArrayMergeTest.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\Integration\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\array_merge; | ||
use function Flow\ETL\DSL\ref; | ||
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 ArrayMergeTest extends TestCase | ||
{ | ||
public function test_array_merge() : void | ||
{ | ||
(new Flow()) | ||
->read( | ||
From::array( | ||
[ | ||
['id' => 1, 'first' => ['a' => 1, 'b' => 2], 'second' => ['c' => 3]], | ||
['id' => 2], | ||
] | ||
) | ||
) | ||
->withEntry('row', ref('row')->unpack()) | ||
->renameAll('row.', '') | ||
->withEntry('array', array_merge(ref('first'), ref('second'))) | ||
->drop('row', 'first', 'second') | ||
->write(To::memory($memory = new ArrayMemory())) | ||
->run(); | ||
|
||
$this->assertSame( | ||
[ | ||
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], | ||
['id' => 2, 'array' => null], | ||
], | ||
$memory->data | ||
); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ArrayReverseTest.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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Integration\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\ref; | ||
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 ArrayReverseTest extends TestCase | ||
{ | ||
public function test_array_reverse() : void | ||
{ | ||
(new Flow()) | ||
->read( | ||
From::array( | ||
[ | ||
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], | ||
['id' => 2], | ||
] | ||
) | ||
) | ||
->withEntry('row', ref('row')->unpack()) | ||
->renameAll('row.', '') | ||
->drop('row') | ||
->withEntry('array', ref('array')->arrayReverse()) | ||
->write(To::memory($memory = new ArrayMemory())) | ||
->run(); | ||
|
||
$this->assertSame( | ||
[ | ||
['id' => 1, 'array' => ['c' => 3, 'b' => 2, 'a' => 1]], | ||
['id' => 2, 'array' => null], | ||
], | ||
$memory->data | ||
); | ||
} | ||
} |
Oops, something went wrong.