-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Unify how we generate an array from Extractors * Use the new test case * Clean-up files * Add methods for modifying and asserting rows * Use the new methods * Add method for multi-row counting * Use the methods in the rest of the files * Import function * Leave this class pure to test the implementation * Import of build-in function is forbidden * Convert helper function to an assertion * Remove unused method * Convert helper method to an assertion * Fix code style * Follow the naming conventions of PHPUnit * Use a more descriptive name * Split logic into 2 methods * Rename test case and fix code style issues * Revert "Rename test case and fix code style issues" This reverts commit 43a88c8. * Rename test case * Fix code style * Improve assertion naming * Assert by flatten first the rows * Use the same implementation * Allow to override default flow context * Allow to override default error message * Make methods static and final as PHPUnit does * Move class into the ETL root * Integration should extend the base FlowTestCase * Use DSL functions instead of objects * Use self instead of directly accessing the FlowTestCase --------- Co-authored-by: Norbert Orzechowicz <[email protected]>
- Loading branch information
1 parent
4c533ea
commit 12357ba
Showing
37 changed files
with
240 additions
and
191 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
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
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
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
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
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,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests; | ||
|
||
use function Flow\ETL\DSL\{flow_context, rows}; | ||
use Flow\ETL\{Extractor, FlowContext, Rows}; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
abstract class FlowTestCase extends TestCase | ||
{ | ||
final public static function assertExtractedBatchesCount( | ||
int $expectedCount, | ||
Extractor $extractor, | ||
?FlowContext $flowContext = null, | ||
string $message = '', | ||
) : void { | ||
$flowContext = $flowContext ?? flow_context(); | ||
|
||
static::assertCount( | ||
$expectedCount, | ||
\iterator_to_array($extractor->extract($flowContext)), | ||
$message | ||
); | ||
} | ||
|
||
final public static function assertExtractedBatchesSize( | ||
int $expectedCount, | ||
Extractor $extractor, | ||
?FlowContext $flowContext = null, | ||
string $message = '', | ||
) : void { | ||
$flowContext = $flowContext ?? flow_context(); | ||
$extractorContainsBatches = false; | ||
|
||
foreach ($extractor->extract($flowContext) as $rows) { | ||
static::assertCount($expectedCount, $rows, $message); | ||
$extractorContainsBatches = true; | ||
} | ||
|
||
if (!$extractorContainsBatches) { | ||
static::fail('Extractor does not contain any batches'); | ||
} | ||
} | ||
|
||
final public static function assertExtractedRowsAsArrayEquals( | ||
array $expectedArray, | ||
Extractor $extractor, | ||
?FlowContext $flowContext = null, | ||
string $message = '', | ||
) : void { | ||
$flowContext = $flowContext ?? flow_context(); | ||
$extractedRows = rows(); | ||
|
||
foreach ($extractor->extract($flowContext) as $nextRows) { | ||
$extractedRows = $extractedRows->merge($nextRows); | ||
} | ||
|
||
static::assertEquals($expectedArray, $extractedRows->toArray(), $message); | ||
} | ||
|
||
final public static function assertExtractedRowsCount( | ||
int $expectedCount, | ||
Extractor $extractor, | ||
?FlowContext $flowContext = null, | ||
string $message = '', | ||
) : void { | ||
$flowContext = $flowContext ?? flow_context(); | ||
$totalRows = 0; | ||
|
||
foreach ($extractor->extract($flowContext) as $rows) { | ||
$totalRows += $rows->count(); | ||
} | ||
|
||
static::assertSame($expectedCount, $totalRows, $message); | ||
} | ||
|
||
final public static function assertExtractedRowsEquals( | ||
Rows $expectedRows, | ||
Extractor $extractor, | ||
?FlowContext $flowContext = null, | ||
string $message = '', | ||
) : void { | ||
$flowContext = $flowContext ?? flow_context(); | ||
$extractedRows = rows(); | ||
|
||
foreach ($extractor->extract($flowContext) as $nextRows) { | ||
$extractedRows = $extractedRows->merge($nextRows); | ||
} | ||
|
||
static::assertEquals($expectedRows, $extractedRows, $message); | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.