Skip to content
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

fix(etl-adapter-google-sheet): Fix scenario for empty google sheet. #641

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,27 @@
private readonly int $rowsInBatch,
private readonly array $options = [],
) {
if ($this->rowsInBatch < 1) {

Check warning on line 28 in src/adapter/etl-adapter-google-sheet/src/Flow/ETL/Adapter/GoogleSheet/GoogleSheetExtractor.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (locked, 8.1, ubuntu-latest)

Escaped Mutant for Mutator "LessThan": --- Original +++ New @@ @@ */ public function __construct(private readonly Sheets $service, private readonly string $spreadsheetId, private readonly Columns $columnRange, private readonly bool $withHeader, private readonly int $rowsInBatch, private readonly array $options = []) { - if ($this->rowsInBatch < 1) { + if ($this->rowsInBatch <= 1) { throw new InvalidArgumentException('Rows in batch must be greater than 0'); } }
throw new InvalidArgumentException('Rows in batch must be greater than 0');
}
}

public function extract(FlowContext $context) : \Generator
{
$cellsRange = new SheetRange($this->columnRange, 1, $this->rowsInBatch);

Check warning on line 35 in src/adapter/etl-adapter-google-sheet/src/Flow/ETL/Adapter/GoogleSheet/GoogleSheetExtractor.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (locked, 8.1, ubuntu-latest)

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ } public function extract(FlowContext $context) : \Generator { - $cellsRange = new SheetRange($this->columnRange, 1, $this->rowsInBatch); + $cellsRange = new SheetRange($this->columnRange, 2, $this->rowsInBatch); $headers = []; $totalRows = 0; /** @var Sheets\ValueRange $response */
$headers = [];

$totalRows = 0;

Check warning on line 38 in src/adapter/etl-adapter-google-sheet/src/Flow/ETL/Adapter/GoogleSheet/GoogleSheetExtractor.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (locked, 8.1, ubuntu-latest)

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ { $cellsRange = new SheetRange($this->columnRange, 1, $this->rowsInBatch); $headers = []; - $totalRows = 0; + $totalRows = -1; /** @var Sheets\ValueRange $response */ $response = $this->service->spreadsheets_values->get($this->spreadsheetId, $cellsRange->toString(), $this->options); /**
/** @var Sheets\ValueRange $response */
$response = $this->service->spreadsheets_values->get($this->spreadsheetId, $cellsRange->toString(), $this->options);
/** @var array[] $values */
$values = $response->getValues();
/**
* @var array[] $values
*
* @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction
*
* @phpstan-ignore-next-line
*/
$values = $response->getValues() ?? [];

if ($this->withHeader && [] !== $values) {
/** @var string[] $headers */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function test_works_for_no_data() : void
20
);
$ValueRangeMock = $this->createMock(Sheets\ValueRange::class);
$ValueRangeMock->method('getValues')->willReturn([]);
$ValueRangeMock->method('getValues')->willReturn(null);

$service->spreadsheets_values = ($spreadsheetsValues = $this->createMock(SpreadsheetsValues::class));
$spreadsheetsValues->method('get')->willReturn($ValueRangeMock);
Expand Down
Loading