From 8166b6ce3bd85fa09fc2869b313e1e7ca74fc16a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Jun 2025 03:07:07 +0000 Subject: [PATCH 1/3] Initial plan for issue From 1d6aafe48d7b0e2b9bc692443728d28c4d856dc3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Jun 2025 03:15:18 +0000 Subject: [PATCH 2/3] Replace static return types with self in SheetsClient and related classes Co-authored-by: kawax <1502086+kawax@users.noreply.github.com> --- src/Concerns/SheetsDrive.php | 2 +- src/Concerns/SheetsValues.php | 8 ++++---- src/Contracts/Factory.php | 20 ++++++++++---------- src/Facades/Sheets.php | 22 +++++++++++----------- src/SheetsClient.php | 12 ++++++------ 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/Concerns/SheetsDrive.php b/src/Concerns/SheetsDrive.php index 6d4098c..26a5ae8 100644 --- a/src/Concerns/SheetsDrive.php +++ b/src/Concerns/SheetsDrive.php @@ -29,7 +29,7 @@ public function spreadsheetList(): array return $list; } - public function setDriveService(mixed $drive): static + public function setDriveService(mixed $drive): self { $this->drive = $drive; diff --git a/src/Concerns/SheetsValues.php b/src/Concerns/SheetsValues.php index 3c5ffe4..ddea444 100644 --- a/src/Concerns/SheetsValues.php +++ b/src/Concerns/SheetsValues.php @@ -133,28 +133,28 @@ public function ranges(): ?string return $this->range; } - public function range(string $range): static + public function range(string $range): self { $this->range = $range; return $this; } - public function majorDimension(string $majorDimension): static + public function majorDimension(string $majorDimension): self { $this->majorDimension = $majorDimension; return $this; } - public function valueRenderOption(string $valueRenderOption): static + public function valueRenderOption(string $valueRenderOption): self { $this->valueRenderOption = $valueRenderOption; return $this; } - public function dateTimeRenderOption(string $dateTimeRenderOption): static + public function dateTimeRenderOption(string $dateTimeRenderOption): self { $this->dateTimeRenderOption = $dateTimeRenderOption; diff --git a/src/Contracts/Factory.php b/src/Contracts/Factory.php index e8671f0..6ea6f5c 100644 --- a/src/Contracts/Factory.php +++ b/src/Contracts/Factory.php @@ -11,22 +11,22 @@ interface Factory { - public function setService(mixed $service): static; + public function setService(mixed $service): self; public function getService(): Sheets; /** * set access_token and set new service. */ - public function setAccessToken(array|string $token): static; + public function setAccessToken(array|string $token): self; - public function spreadsheet(string $spreadsheetId): static; + public function spreadsheet(string $spreadsheetId): self; - public function spreadsheetByTitle(string $title): static; + public function spreadsheetByTitle(string $title): self; - public function sheet(string $sheet): static; + public function sheet(string $sheet): self; - public function sheetById(string $sheetId): static; + public function sheetById(string $sheetId): self; public function sheetList(): array; @@ -36,7 +36,7 @@ public function collection(array $header, array|Collection $rows): Collection; public function spreadsheetList(): array; - public function setDriveService(mixed $drive): static; + public function setDriveService(mixed $drive): self; public function getDriveService(): mixed; @@ -60,11 +60,11 @@ public function append( public function ranges(): ?string; - public function range(string $range): static; + public function range(string $range): self; - public function majorDimension(string $majorDimension): static; + public function majorDimension(string $majorDimension): self; - public function dateTimeRenderOption(string $dateTimeRenderOption): static; + public function dateTimeRenderOption(string $dateTimeRenderOption): self; public function getSpreadsheetId(): string; diff --git a/src/Facades/Sheets.php b/src/Facades/Sheets.php index b761657..e47d647 100644 --- a/src/Facades/Sheets.php +++ b/src/Facades/Sheets.php @@ -13,11 +13,11 @@ use Revolution\Google\Sheets\Contracts\Factory; /** - * @method static static setAccessToken(array|string $token) - * @method static static spreadsheet(string $spreadsheetId) - * @method static static spreadsheetByTitle(string $title) - * @method static static sheet(string $sheet) - * @method static static sheetById(string $sheetId) + * @method static self setAccessToken(array|string $token) + * @method static self spreadsheet(string $spreadsheetId) + * @method static self spreadsheetByTitle(string $title) + * @method static self sheet(string $sheet) + * @method static self sheetById(string $sheetId) * @method static array sheetList() * @method static BatchUpdateSpreadsheetResponse addSheet(string $sheetTitle) * @method static BatchUpdateSpreadsheetResponse deleteSheet(string $sheetTitle) @@ -28,14 +28,14 @@ * @method static BatchUpdateValuesResponse update(array $value, string $valueInputOption = 'RAW') * @method static ClearValuesResponse|null clear() * @method static AppendValuesResponse append(array $values, string $valueInputOption = 'RAW', string $insertDataOption = 'OVERWRITE') - * @method static static range(string $range) - * @method static static majorDimension(string $majorDimension) - * @method static static valueRenderOption(string $valueRenderOption) - * @method static static dateTimeRenderOption(string $dateTimeRenderOption) + * @method static self range(string $range) + * @method static self majorDimension(string $majorDimension) + * @method static self valueRenderOption(string $valueRenderOption) + * @method static self dateTimeRenderOption(string $dateTimeRenderOption) * @method static GoogleSheets getService() - * @method static static setService(mixed $service) + * @method static self setService(mixed $service) * @method static Drive getDriveService() - * @method static static setDriveService(mixed $drive) + * @method static self setDriveService(mixed $drive) * @method static array spreadsheetList() * @method static object spreadsheetProperties() * @method static object sheetProperties() diff --git a/src/SheetsClient.php b/src/SheetsClient.php index 2d194bf..da99513 100644 --- a/src/SheetsClient.php +++ b/src/SheetsClient.php @@ -30,7 +30,7 @@ class SheetsClient implements Factory protected ?string $sheet = null; - public function setService(mixed $service): static + public function setService(mixed $service): self { $this->service = $service; @@ -45,7 +45,7 @@ public function getService(): GoogleSheets /** * set access_token and set new service. */ - public function setAccessToken(#[\SensitiveParameter] array|string $token): static + public function setAccessToken(#[\SensitiveParameter] array|string $token): self { Google::getCache()->clear(); @@ -64,14 +64,14 @@ public function getAccessToken(): ?array return $this->getService()->getClient()->getAccessToken(); } - public function spreadsheet(string $spreadsheetId): static + public function spreadsheet(string $spreadsheetId): self { $this->spreadsheetId = $spreadsheetId; return $this; } - public function spreadsheetByTitle(string $title): static + public function spreadsheetByTitle(string $title): self { $list = $this->spreadsheetList(); @@ -80,14 +80,14 @@ public function spreadsheetByTitle(string $title): static return $this; } - public function sheet(string $sheet): static + public function sheet(string $sheet): self { $this->sheet = $sheet; return $this; } - public function sheetById(string $sheetId): static + public function sheetById(string $sheetId): self { $list = $this->sheetList(); From 0111f08a1539ae9c15ea5a037c8e12b71ea2b110 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Jun 2025 03:39:38 +0000 Subject: [PATCH 3/3] Modernize test code with expects() syntax and fix chained method calls Co-authored-by: kawax <1502086+kawax@users.noreply.github.com> --- tests/SheetsDriveTest.php | 4 ++-- tests/SheetsMockTest.php | 39 +++++++++++++++++++-------------------- tests/SheetsTest.php | 15 +++++++-------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/tests/SheetsDriveTest.php b/tests/SheetsDriveTest.php index fdcdfe0..c1e61c6 100644 --- a/tests/SheetsDriveTest.php +++ b/tests/SheetsDriveTest.php @@ -43,7 +43,7 @@ public function test_list() $file, ]; - $this->files->shouldReceive('listFiles->getFiles')->once()->andReturn($files); + $this->files->expects('listFiles->getFiles')->once()->andReturn($files); $list = Sheets::spreadsheetList(); @@ -52,7 +52,7 @@ public function test_list() public function test_null() { - Google::shouldReceive('make')->andReturn($this->service); + Google::expects('make')->andReturn($this->service); $drive = Sheets::setDriveService(null)->getDriveService(); diff --git a/tests/SheetsMockTest.php b/tests/SheetsMockTest.php index 842c93f..9efa8fc 100644 --- a/tests/SheetsMockTest.php +++ b/tests/SheetsMockTest.php @@ -55,7 +55,7 @@ public function test_sheets_all() $valueRange->setValues([['test1' => '1'], ['test2' => '2']]); $response->setValueRanges([$valueRange]); - $this->values->shouldReceive('batchGet')->with(m::any(), m::any())->once()->andReturn($response); + $this->values->expects('batchGet')->with(m::any(), m::any())->once()->andReturn($response); $values = $this->sheet->spreadsheet('test') ->sheet('test') @@ -75,7 +75,7 @@ public function test_sheets_empty() $valueRange->setValues(null); $response->setValueRanges([$valueRange]); - $this->values->shouldReceive('batchGet')->with(m::any(), m::any())->once()->andReturn($response); + $this->values->expects('batchGet')->with(m::any(), m::any())->once()->andReturn($response); $values = $this->sheet->all(); @@ -89,7 +89,7 @@ public function test_sheets_get() $valueRange->setValues([['test1' => '1'], ['test2' => '2']]); $response->setValueRanges([$valueRange]); - $this->values->shouldReceive('batchGet')->with(m::any(), m::any())->once()->andReturn($response); + $this->values->expects('batchGet')->with(m::any(), m::any())->once()->andReturn($response); $values = $this->sheet->get(); @@ -101,7 +101,7 @@ public function test_sheets_update() { $response = new BatchUpdateValuesResponse; - $this->values->shouldReceive('batchUpdate')->once()->andReturn($response); + $this->values->expects('batchUpdate')->once()->andReturn($response); $values = $this->sheet->sheet('test')->range('A1')->update([['test']]); @@ -116,7 +116,7 @@ public function test_sheets_first() $valueRange->setValues([['test1' => '1'], ['test2' => '2']]); $response->setValueRanges([$valueRange]); - $this->values->shouldReceive('batchGet')->with(m::any(), m::any())->once()->andReturn($response); + $this->values->expects('batchGet')->with(m::any(), m::any())->once()->andReturn($response); $value = $this->sheet->first(); @@ -130,7 +130,7 @@ public function test_sheets_first_empty() $valueRange->setValues(null); $response->setValueRanges([$valueRange]); - $this->values->shouldReceive('batchGet')->with(m::any(), m::any())->once()->andReturn($response); + $this->values->expects('batchGet')->with(m::any(), m::any())->once()->andReturn($response); $value = $this->sheet->first(); @@ -139,7 +139,7 @@ public function test_sheets_first_empty() public function test_sheets_clear() { - $this->values->shouldReceive('clear')->once(); + $this->values->expects('clear')->once(); $value = $this->sheet->clear(); @@ -154,7 +154,7 @@ public function test_sheets_append() $valueRange->setValues([['test1' => '1'], ['test2' => '2']]); $response->setUpdates($updates); - $this->values->shouldReceive('append')->once()->andReturn($response); + $this->values->expects('append')->once()->andReturn($response); $value = $this->sheet->append([[]]); @@ -168,7 +168,7 @@ public function test_sheets_append_with_keys() $valueRange->setValues([['header1', 'header2'], ['value1', 'value2']]); $response->setValueRanges([$valueRange]); - $this->values->shouldReceive('batchGet') + $this->values->expects('batchGet') ->with(m::any(), m::any()) ->andReturn($response); @@ -178,7 +178,7 @@ public function test_sheets_append_with_keys() public function test_spreadsheet_properties() { - $this->spreadsheets->shouldReceive('get->getProperties->toSimpleObject')->once()->andReturn(new \stdClass); + $this->spreadsheets->expects('get->getProperties->toSimpleObject')->once()->andReturn(new \stdClass); $properties = $this->sheet->spreadsheetProperties(); @@ -188,9 +188,9 @@ public function test_spreadsheet_properties() public function test_sheet_properties() { $sheet = m::mock(Spreadsheet::class); - $sheet->shouldReceive('getProperties->toSimpleObject')->once()->andReturn(new \stdClass); + $sheet->expects('getProperties->toSimpleObject')->once()->andReturn(new \stdClass); - $this->spreadsheets->shouldReceive('get->getSheets')->once()->andReturn([$sheet]); + $this->spreadsheets->expects('get->getSheets')->once()->andReturn([$sheet]); $properties = $this->sheet->sheetProperties(); @@ -213,7 +213,7 @@ public function test_sheets_list() ], ]); - $this->spreadsheets->shouldReceive('get->getSheets')->andReturn([$sheets]); + $this->spreadsheets->expects('get->getSheets')->andReturn([$sheets]); $values = $this->sheet->sheetList(); $this->assertSame(['sheetId' => 'title'], $values); @@ -230,7 +230,7 @@ public function test_sheet_by_id() $sheet = m::mock(SheetsClient::class)->makePartial(); - $sheet->shouldReceive('sheetList')->andReturn([$sheets]); + $sheet->expects('sheetList')->andReturn([$sheets]); $sheet->sheetById('sheetId'); @@ -245,7 +245,7 @@ public function test_spreadsheet_by_title() $sheet = m::mock(SheetsClient::class)->makePartial(); - $sheet->shouldReceive('spreadsheetList')->andReturn($list); + $sheet->expects('spreadsheetList')->andReturn($list); $sheet->spreadsheetByTitle('title'); @@ -278,7 +278,7 @@ public function test_get_client() public function test_add_sheet() { $this->spreadsheets - ->shouldReceive('batchUpdate') + ->expects('batchUpdate') ->andReturn(new BatchUpdateSpreadsheetResponse); $response = $this->sheet->addSheet('new sheet'); @@ -294,12 +294,11 @@ public function test_delete_sheet() ], ]); - $this->spreadsheets->shouldReceive('get->getSheets')->andReturn([$sheets]); + $this->spreadsheets->expects('get->getSheets')->andReturn([$sheets]); $this->spreadsheets - ->shouldReceive('batchUpdate') + ->expects('batchUpdate') ->andReturn(new BatchUpdateSpreadsheetResponse); - $this->sheet->shouldReceive('sheetList')->andReturn([$sheets]); $response = $this->sheet->deleteSheet('title'); $this->assertNotNull($response); } @@ -307,7 +306,7 @@ public function test_delete_sheet() public function test_get_proper_ranges() { $this->values - ->shouldReceive('batchUpdate') + ->expects('batchUpdate') ->times(3) ->andReturn(new BatchUpdateValuesResponse); diff --git a/tests/SheetsTest.php b/tests/SheetsTest.php index 65d4668..eb68123 100644 --- a/tests/SheetsTest.php +++ b/tests/SheetsTest.php @@ -31,7 +31,7 @@ protected function tearDown(): void public function test_service() { - $this->google->shouldReceive('make')->once()->andReturns(m::mock(\Google\Service\Sheets::class)); + $this->google->expects('make')->once()->andReturns(m::mock(\Google\Service\Sheets::class)); // Sheets::setService($this->google->make('Sheets')); @@ -40,12 +40,11 @@ public function test_service() public function test_set_access_token() { - $this->google->shouldReceive('getCache')->once()->andReturn(m::self()); - $this->google->shouldReceive('clear')->once(); - $this->google->shouldReceive('setAccessToken')->once(); - $this->google->shouldReceive('isAccessTokenExpired')->once()->andReturns(true); - $this->google->shouldReceive('fetchAccessTokenWithRefreshToken')->once(); - $this->google->shouldReceive('make')->times(2)->andReturns( + $this->google->expects('getCache->clear')->once(); + $this->google->expects('setAccessToken')->once(); + $this->google->expects('isAccessTokenExpired')->once()->andReturns(true); + $this->google->expects('fetchAccessTokenWithRefreshToken')->once(); + $this->google->expects('make')->times(2)->andReturns( m::mock(\Google\Service\Sheets::class), m::mock(\Google\Service\Drive::class) ); @@ -61,7 +60,7 @@ public function test_set_access_token() public function test_trait() { - Sheets::shouldReceive('setAccessToken')->with('test')->once()->andReturn(m::self()); + Sheets::expects('setAccessToken')->with('test')->once()->andReturn(m::self()); $sheets = (new User)->sheets();