-
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 string related expressions (#552)
- Loading branch information
Showing
7 changed files
with
577 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/SizeTest.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,85 @@ | ||
<?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\Exception\RuntimeException; | ||
use Flow\ETL\Flow; | ||
use Flow\ETL\Memory\ArrayMemory; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class SizeTest extends TestCase | ||
{ | ||
public function test_size_on_array() : void | ||
{ | ||
(new Flow()) | ||
->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 | ||
); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/SprintfTest.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,91 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Integration\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\lit; | ||
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 SprintfTest extends TestCase | ||
{ | ||
public function test_sprintf() : void | ||
{ | ||
(new Flow()) | ||
->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 | ||
); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/StrPadTest.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,65 @@ | ||
<?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 StrPadTest extends TestCase | ||
{ | ||
public function test_strpad() : void | ||
{ | ||
(new Flow()) | ||
->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 | ||
); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/StrReplaceTest.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,65 @@ | ||
<?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 StrReplaceTest extends TestCase | ||
{ | ||
public function test_str_replace() : void | ||
{ | ||
(new Flow()) | ||
->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 | ||
); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/core/etl/tests/Flow/ETL/Tests/Integration/Row/Reference/Expression/ToLowerTest.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,65 @@ | ||
<?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 ToLowerTest extends TestCase | ||
{ | ||
public function test_to_lower() : void | ||
{ | ||
(new Flow()) | ||
->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 | ||
); | ||
} | ||
} |
Oops, something went wrong.