-
-
Notifications
You must be signed in to change notification settings - Fork 52
[GoogleSheet] Prevent fatal error when extracted columns don't match headers amount #1606
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
17 changes: 17 additions & 0 deletions
17
...adapter-google-sheet/tests/Flow/ETL/Adapter/GoogleSheet/Tests/Fixtures/extra-columns.json
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,17 @@ | ||
| { | ||
| "range": "Sheet!A1:D11", | ||
| "majorDimension": "ROWS", | ||
| "values": [ | ||
| ["Header 1", "Header 2", "Header 3"], | ||
| ["A2", "B2", "C2"], | ||
| ["A3", "B3", "C3"], | ||
| ["A4", "B4", "C4"], | ||
| ["A5", "B5", "C5"], | ||
| ["A6", "B6", "C6"], | ||
| ["A7", "B7", "C7"], | ||
| ["A8", "B8", "C8"], | ||
| ["A9", "B9", "C9"], | ||
| ["A10", "B10", "C10"], | ||
| ["A11", "B11", "C11", "D11"] | ||
| ] | ||
| } |
47 changes: 47 additions & 0 deletions
47
...etl-adapter-google-sheet/tests/Flow/ETL/Adapter/GoogleSheet/Tests/GoogleSheetsContext.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,47 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Flow\ETL\Adapter\GoogleSheet\Tests; | ||
|
|
||
| use Google\Client as GoogleClient; | ||
| use Google\Service\Sheets; | ||
| use GuzzleHttp\{Client as HttpClient, HandlerStack}; | ||
| use GuzzleHttp\Handler\MockHandler; | ||
| use GuzzleHttp\Psr7\Response; | ||
|
|
||
| final readonly class GoogleSheetsContext | ||
| { | ||
| private GoogleClient $client; | ||
|
|
||
| public function __construct() | ||
| { | ||
| $this->client = new GoogleClient(); | ||
| } | ||
|
|
||
| public function sheets(string $fixtureFile) : Sheets | ||
| { | ||
| $this->client->setHttpClient($this->createHttpClient($fixtureFile)); | ||
|
|
||
| return new Sheets($this->client); | ||
| } | ||
|
|
||
| private function createHttpClient(string $fixtureFile) : HttpClient | ||
| { | ||
| return new HttpClient( | ||
| [ | ||
| 'handler' => HandlerStack::create( | ||
| new MockHandler( | ||
| [ | ||
| new Response( | ||
| 200, | ||
| ['Content-Type' => 'application/json'], | ||
| file_get_contents($fixtureFile) ?: throw new \RuntimeException('Failed to read file: ' . $fixtureFile) | ||
| ), | ||
| ] | ||
| ) | ||
| ), | ||
| ] | ||
| ); | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
...e-sheet/tests/Flow/ETL/Adapter/GoogleSheet/Tests/Integration/GoogleSheetExtractorTest.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,54 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Flow\ETL\Adapter\GoogleSheet\Tests\Integration; | ||
|
|
||
| use function Flow\ETL\DSL\{config, flow_context}; | ||
| use Flow\ETL\Adapter\GoogleSheet\{Columns, GoogleSheetExtractor, Tests\GoogleSheetsContext}; | ||
| use Flow\ETL\Exception\InvalidArgumentException; | ||
| use Flow\ETL\Tests\FlowTestCase; | ||
|
|
||
| final class GoogleSheetExtractorTest extends FlowTestCase | ||
| { | ||
| private GoogleSheetsContext $context; | ||
|
|
||
| protected function setUp() : void | ||
| { | ||
| $this->context = new GoogleSheetsContext(); | ||
| } | ||
|
|
||
| public function test_extract_with_cut_extra_columns() : void | ||
| { | ||
| $extractor = new GoogleSheetExtractor( | ||
| $this->context->sheets(__DIR__ . '/../Fixtures/extra-columns.json'), | ||
| '1234567890', | ||
| new Columns('Sheet', 'A', 'Z'), | ||
| ); | ||
|
|
||
| $rows = $extractor->extract(flow_context(config())); | ||
|
|
||
| foreach ($rows as $row) { | ||
| self::assertNotNull($row); | ||
| } | ||
| } | ||
|
|
||
| public function test_extract_without_cut_extra_columns() : void | ||
| { | ||
| $extractor = new GoogleSheetExtractor( | ||
| $this->context->sheets(__DIR__ . '/../Fixtures/extra-columns.json'), | ||
| '1234567890', | ||
| new Columns('Sheet', 'A', 'Z'), | ||
| ); | ||
| $extractor->withDropExtraColumns(false); | ||
|
|
||
| $rows = $extractor->extract(flow_context(config())); | ||
|
|
||
| $this->expectException(InvalidArgumentException::class); | ||
| $this->expectExceptionMessage('Row has more columns (4) than headers (3)'); | ||
|
|
||
| foreach ($rows as $row) { | ||
| self::assertNotNull($row); | ||
| } | ||
| } | ||
| } |
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
Large diffs are not rendered by default.
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.