From c460a3c50a9d7c69765e8097bcd072a88b62c46b Mon Sep 17 00:00:00 2001 From: kawax Date: Fri, 22 Apr 2022 10:20:12 +0900 Subject: [PATCH] wip --- src/Concerns/SheetsProperties.php | 18 ++++++++++-------- src/Concerns/SheetsValues.php | 8 ++++---- src/Sheets.php | 6 +++--- tests/SheetsMockTest.php | 11 ++++++----- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Concerns/SheetsProperties.php b/src/Concerns/SheetsProperties.php index 26cfc52..967f6db 100644 --- a/src/Concerns/SheetsProperties.php +++ b/src/Concerns/SheetsProperties.php @@ -2,28 +2,30 @@ namespace Revolution\Google\Sheets\Concerns; +use stdClass; + trait SheetsProperties { /** - * @return \stdClass + * @return stdClass */ - public function spreadsheetProperties() + public function spreadsheetProperties(): stdClass { return $this->getService() ->spreadsheets - ->get($this->spreadsheetId) + ->get($this->getSpreadsheetId()) ->getProperties() ->toSimpleObject(); } /** - * @return \stdClass + * @return stdClass */ - public function sheetProperties() + public function sheetProperties(): stdClass { $sheets = $this->getService() ->spreadsheets - ->get($this->spreadsheetId, ['ranges' => $this->sheet]) + ->get($this->getSpreadsheetId(), ['ranges' => $this->sheet]) ->getSheets(); return $sheets[0]->getProperties()->toSimpleObject(); @@ -32,8 +34,8 @@ public function sheetProperties() /** * @return string */ - public function getSpreadsheetId() + public function getSpreadsheetId(): string { - return $this->spreadsheetId; + return $this->spreadsheetId ?? ''; } } diff --git a/src/Concerns/SheetsValues.php b/src/Concerns/SheetsValues.php index b7e2ec8..6fbb761 100644 --- a/src/Concerns/SheetsValues.php +++ b/src/Concerns/SheetsValues.php @@ -41,7 +41,7 @@ public function all() { $query = $this->query(); - $sheets = $this->serviceValues()->batchGet($this->spreadsheetId, $query); + $sheets = $this->serviceValues()->batchGet($this->getSpreadsheetId(), $query); $values = $sheets->getValueRanges()[0]->getValues(); @@ -78,7 +78,7 @@ public function update(array $value, string $valueInputOption = 'RAW') $batch->setData($valueRange); - return $this->serviceValues()->batchUpdate($this->spreadsheetId, $batch); + return $this->serviceValues()->batchUpdate($this->getSpreadsheetId(), $batch); } /** @@ -90,7 +90,7 @@ public function clear() $clear = new ClearValuesRequest(); - return $this->serviceValues()->clear($this->spreadsheetId, $range, $clear); + return $this->serviceValues()->clear($this->getSpreadsheetId(), $range, $clear); } /** @@ -113,7 +113,7 @@ public function append(array $values, string $valueInputOption = 'RAW', string $ 'insertDataOption' => $insertDataOption, ]; - return $this->serviceValues()->append($this->spreadsheetId, $range, $valueRange, $optParams); + return $this->serviceValues()->append($this->getSpreadsheetId(), $range, $valueRange, $optParams); } /** diff --git a/src/Sheets.php b/src/Sheets.php index 0c914aa..366f518 100644 --- a/src/Sheets.php +++ b/src/Sheets.php @@ -155,7 +155,7 @@ public function sheetList(): array { $list = []; - $sheets = $this->getService()->spreadsheets->get($this->spreadsheetId)->getSheets(); + $sheets = $this->getService()->spreadsheets->get($this->getSpreadsheetId())->getSheets(); foreach ($sheets as $sheet) { $list[$sheet->getProperties()->getSheetId()] = $sheet->getProperties()->getTitle(); @@ -182,7 +182,7 @@ public function addSheet(string $sheetTitle) ] ); - return $this->getService()->spreadsheets->batchUpdate($this->spreadsheetId, $body); + return $this->getService()->spreadsheets->batchUpdate($this->getSpreadsheetId(), $body); } /** @@ -204,7 +204,7 @@ public function deleteSheet(string $sheetTitle) ] ); - return $this->getService()->spreadsheets->batchUpdate($this->spreadsheetId, $body); + return $this->getService()->spreadsheets->batchUpdate($this->getSpreadsheetId(), $body); } /** diff --git a/tests/SheetsMockTest.php b/tests/SheetsMockTest.php index 115a45e..a2f4953 100644 --- a/tests/SheetsMockTest.php +++ b/tests/SheetsMockTest.php @@ -5,6 +5,7 @@ use Google\Service\Sheets\AppendValuesResponse; use Google\Service\Sheets\BatchGetValuesResponse; use Google\Service\Sheets\BatchUpdateSpreadsheetResponse; +use Google\Service\Sheets\BatchUpdateValuesResponse; use Google\Service\Sheets\Resource\Spreadsheets; use Google\Service\Sheets\Resource\SpreadsheetsValues; use Google\Service\Sheets\Sheet; @@ -40,10 +41,10 @@ class SheetsMockTest extends TestCase public function setUp(): void { parent::setUp(); - $this->service = m::mock('Google_Service_Sheets')->makePartial(); - $this->spreadsheets = m::mock('Google_Service_Sheets_Resource_Spreadsheets'); + $this->service = m::mock(\Google\Service\Sheets::class)->makePartial(); + $this->spreadsheets = m::mock(Spreadsheets::class); $this->service->spreadsheets = $this->spreadsheets; - $this->values = m::mock('Google_Service_Sheets_Resource_SpreadsheetsValues'); + $this->values = m::mock(SpreadsheetsValues::class); $this->service->spreadsheets_values = $this->values; $this->sheet = new Sheets(); @@ -107,14 +108,14 @@ public function testSheetsGet() public function testSheetsUpdate() { - $response = new UpdateValuesResponse(); + $response = new BatchUpdateValuesResponse(); $this->values->shouldReceive('batchUpdate')->once()->andReturn($response); $values = $this->sheet->sheet('test')->range('A1')->update([['test']]); $this->assertEquals('test!A1', $this->sheet->ranges()); - $this->assertInstanceOf('Google_Service_Sheets_UpdateValuesResponse', $values); + $this->assertInstanceOf(BatchUpdateValuesResponse::class, $values); } public function testSheetsFirst()