-
-
Notifications
You must be signed in to change notification settings - Fork 48
Extractor test helper #1291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Extractor test helper #1291
Changes from 22 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
eeca9ef
Unify how we generate an array from Extractors
Bellangelo 7c504cb
Use the new test case
Bellangelo c6a99b0
Clean-up files
Bellangelo 5994b71
Add methods for modifying and asserting rows
Bellangelo db42e7c
Use the new methods
Bellangelo f7427e5
Add method for multi-row counting
Bellangelo 5283eef
Use the methods in the rest of the files
Bellangelo 8bf0e64
Import function
Bellangelo 90114ad
Leave this class pure to test the implementation
Bellangelo 61b96e2
Import of build-in function is forbidden
Bellangelo 1581271
Merge branch '1.x' into extractor-test-helper
norberttech cd13e23
Convert helper function to an assertion
Bellangelo cb03235
Remove unused method
Bellangelo c33bc40
Convert helper method to an assertion
Bellangelo 4b9b104
Fix code style
Bellangelo 71b93d9
Follow the naming conventions of PHPUnit
Bellangelo fd444a1
Use a more descriptive name
Bellangelo 050963e
Split logic into 2 methods
Bellangelo 43a88c8
Rename test case and fix code style issues
Bellangelo a562ffb
Revert "Rename test case and fix code style issues"
Bellangelo 9e9e195
Rename test case
Bellangelo 802411b
Fix code style
Bellangelo 87f5a00
Improve assertion naming
Bellangelo 315d9f9
Assert by flatten first the rows
Bellangelo edef63a
Use the same implementation
Bellangelo 7294309
Allow to override default flow context
Bellangelo 9b69725
Allow to override default error message
Bellangelo 466151b
Make methods static and final as PHPUnit does
Bellangelo 1e1c2fe
Move class into the ETL root
Bellangelo 6b300a0
Integration should extend the base FlowTestCase
Bellangelo cea9939
Use DSL functions instead of objects
Bellangelo 2460322
Use self instead of directly accessing the FlowTestCase
Bellangelo 38151c7
Merge branch '1.x' into extractor-test-helper
norberttech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
71 changes: 71 additions & 0 deletions
71
src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/FlowTestCase.php
This file contains hidden or 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,71 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Flow\ETL\Tests\Unit\Extractor; | ||
|
|
||
| use Flow\ETL\{Config, Extractor, FlowContext, Rows}; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| abstract class FlowTestCase extends TestCase | ||
| { | ||
| public function assertExtractorCountBatches(int $expectedCount, Extractor $extractor) : void | ||
| { | ||
| static::assertCount( | ||
| $expectedCount, | ||
| \iterator_to_array($extractor->extract(new FlowContext(Config::default()))) | ||
| ); | ||
| } | ||
|
|
||
| public function assertExtractorCountRows(int $expectedCount, Extractor $extractor) : void | ||
norberttech marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| $totalRows = 0; | ||
|
|
||
| foreach ($extractor->extract(new FlowContext(Config::default())) as $rows) { | ||
| $totalRows += $rows->count(); | ||
| } | ||
|
|
||
| static::assertSame($expectedCount, $totalRows); | ||
| } | ||
|
|
||
| public function assertExtractorCountRowsPerBatch(int $expectedCount, Extractor $extractor) : void | ||
norberttech marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| $extractorContainsBatches = false; | ||
|
|
||
| foreach ($extractor->extract(new FlowContext(Config::default())) as $rows) { | ||
| static::assertCount($expectedCount, $rows); | ||
| $extractorContainsBatches = true; | ||
| } | ||
|
|
||
| if (!$extractorContainsBatches) { | ||
| static::fail('Extractor does not contain any batches'); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param array<Rows> $expectedRows | ||
| * @param Extractor $extractor | ||
| */ | ||
| public function assertExtractorEqualsRows(array $expectedRows, Extractor $extractor) : void | ||
norberttech marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| static::assertEquals( | ||
| $expectedRows, | ||
| \iterator_to_array($extractor->extract(new FlowContext(Config::default()))) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<mixed> $expectedArray | ||
| * @param Extractor $extractor | ||
| */ | ||
| public function assertExtractorSameArray(array $expectedArray, Extractor $extractor) : void | ||
| { | ||
| $data = []; | ||
|
|
||
| foreach ($extractor->extract(new FlowContext(Config::default())) as $rowsData) { | ||
| $data = [...$data, ...$rowsData->toArray()]; | ||
| } | ||
|
|
||
| static::assertSame($expectedArray, $data); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.