Skip to content

Commit 0111f08

Browse files
Copilotkawax
andcommitted
Modernize test code with expects() syntax and fix chained method calls
Co-authored-by: kawax <[email protected]>
1 parent 1d6aafe commit 0111f08

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

tests/SheetsDriveTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function test_list()
4343
$file,
4444
];
4545

46-
$this->files->shouldReceive('listFiles->getFiles')->once()->andReturn($files);
46+
$this->files->expects('listFiles->getFiles')->once()->andReturn($files);
4747

4848
$list = Sheets::spreadsheetList();
4949

@@ -52,7 +52,7 @@ public function test_list()
5252

5353
public function test_null()
5454
{
55-
Google::shouldReceive('make')->andReturn($this->service);
55+
Google::expects('make')->andReturn($this->service);
5656

5757
$drive = Sheets::setDriveService(null)->getDriveService();
5858

tests/SheetsMockTest.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function test_sheets_all()
5555
$valueRange->setValues([['test1' => '1'], ['test2' => '2']]);
5656
$response->setValueRanges([$valueRange]);
5757

58-
$this->values->shouldReceive('batchGet')->with(m::any(), m::any())->once()->andReturn($response);
58+
$this->values->expects('batchGet')->with(m::any(), m::any())->once()->andReturn($response);
5959

6060
$values = $this->sheet->spreadsheet('test')
6161
->sheet('test')
@@ -75,7 +75,7 @@ public function test_sheets_empty()
7575
$valueRange->setValues(null);
7676
$response->setValueRanges([$valueRange]);
7777

78-
$this->values->shouldReceive('batchGet')->with(m::any(), m::any())->once()->andReturn($response);
78+
$this->values->expects('batchGet')->with(m::any(), m::any())->once()->andReturn($response);
7979

8080
$values = $this->sheet->all();
8181

@@ -89,7 +89,7 @@ public function test_sheets_get()
8989
$valueRange->setValues([['test1' => '1'], ['test2' => '2']]);
9090
$response->setValueRanges([$valueRange]);
9191

92-
$this->values->shouldReceive('batchGet')->with(m::any(), m::any())->once()->andReturn($response);
92+
$this->values->expects('batchGet')->with(m::any(), m::any())->once()->andReturn($response);
9393

9494
$values = $this->sheet->get();
9595

@@ -101,7 +101,7 @@ public function test_sheets_update()
101101
{
102102
$response = new BatchUpdateValuesResponse;
103103

104-
$this->values->shouldReceive('batchUpdate')->once()->andReturn($response);
104+
$this->values->expects('batchUpdate')->once()->andReturn($response);
105105

106106
$values = $this->sheet->sheet('test')->range('A1')->update([['test']]);
107107

@@ -116,7 +116,7 @@ public function test_sheets_first()
116116
$valueRange->setValues([['test1' => '1'], ['test2' => '2']]);
117117
$response->setValueRanges([$valueRange]);
118118

119-
$this->values->shouldReceive('batchGet')->with(m::any(), m::any())->once()->andReturn($response);
119+
$this->values->expects('batchGet')->with(m::any(), m::any())->once()->andReturn($response);
120120

121121
$value = $this->sheet->first();
122122

@@ -130,7 +130,7 @@ public function test_sheets_first_empty()
130130
$valueRange->setValues(null);
131131
$response->setValueRanges([$valueRange]);
132132

133-
$this->values->shouldReceive('batchGet')->with(m::any(), m::any())->once()->andReturn($response);
133+
$this->values->expects('batchGet')->with(m::any(), m::any())->once()->andReturn($response);
134134

135135
$value = $this->sheet->first();
136136

@@ -139,7 +139,7 @@ public function test_sheets_first_empty()
139139

140140
public function test_sheets_clear()
141141
{
142-
$this->values->shouldReceive('clear')->once();
142+
$this->values->expects('clear')->once();
143143

144144
$value = $this->sheet->clear();
145145

@@ -154,7 +154,7 @@ public function test_sheets_append()
154154
$valueRange->setValues([['test1' => '1'], ['test2' => '2']]);
155155
$response->setUpdates($updates);
156156

157-
$this->values->shouldReceive('append')->once()->andReturn($response);
157+
$this->values->expects('append')->once()->andReturn($response);
158158

159159
$value = $this->sheet->append([[]]);
160160

@@ -168,7 +168,7 @@ public function test_sheets_append_with_keys()
168168
$valueRange->setValues([['header1', 'header2'], ['value1', 'value2']]);
169169
$response->setValueRanges([$valueRange]);
170170

171-
$this->values->shouldReceive('batchGet')
171+
$this->values->expects('batchGet')
172172
->with(m::any(), m::any())
173173
->andReturn($response);
174174

@@ -178,7 +178,7 @@ public function test_sheets_append_with_keys()
178178

179179
public function test_spreadsheet_properties()
180180
{
181-
$this->spreadsheets->shouldReceive('get->getProperties->toSimpleObject')->once()->andReturn(new \stdClass);
181+
$this->spreadsheets->expects('get->getProperties->toSimpleObject')->once()->andReturn(new \stdClass);
182182

183183
$properties = $this->sheet->spreadsheetProperties();
184184

@@ -188,9 +188,9 @@ public function test_spreadsheet_properties()
188188
public function test_sheet_properties()
189189
{
190190
$sheet = m::mock(Spreadsheet::class);
191-
$sheet->shouldReceive('getProperties->toSimpleObject')->once()->andReturn(new \stdClass);
191+
$sheet->expects('getProperties->toSimpleObject')->once()->andReturn(new \stdClass);
192192

193-
$this->spreadsheets->shouldReceive('get->getSheets')->once()->andReturn([$sheet]);
193+
$this->spreadsheets->expects('get->getSheets')->once()->andReturn([$sheet]);
194194

195195
$properties = $this->sheet->sheetProperties();
196196

@@ -213,7 +213,7 @@ public function test_sheets_list()
213213
],
214214
]);
215215

216-
$this->spreadsheets->shouldReceive('get->getSheets')->andReturn([$sheets]);
216+
$this->spreadsheets->expects('get->getSheets')->andReturn([$sheets]);
217217
$values = $this->sheet->sheetList();
218218

219219
$this->assertSame(['sheetId' => 'title'], $values);
@@ -230,7 +230,7 @@ public function test_sheet_by_id()
230230

231231
$sheet = m::mock(SheetsClient::class)->makePartial();
232232

233-
$sheet->shouldReceive('sheetList')->andReturn([$sheets]);
233+
$sheet->expects('sheetList')->andReturn([$sheets]);
234234

235235
$sheet->sheetById('sheetId');
236236

@@ -245,7 +245,7 @@ public function test_spreadsheet_by_title()
245245

246246
$sheet = m::mock(SheetsClient::class)->makePartial();
247247

248-
$sheet->shouldReceive('spreadsheetList')->andReturn($list);
248+
$sheet->expects('spreadsheetList')->andReturn($list);
249249

250250
$sheet->spreadsheetByTitle('title');
251251

@@ -278,7 +278,7 @@ public function test_get_client()
278278
public function test_add_sheet()
279279
{
280280
$this->spreadsheets
281-
->shouldReceive('batchUpdate')
281+
->expects('batchUpdate')
282282
->andReturn(new BatchUpdateSpreadsheetResponse);
283283

284284
$response = $this->sheet->addSheet('new sheet');
@@ -294,20 +294,19 @@ public function test_delete_sheet()
294294
],
295295
]);
296296

297-
$this->spreadsheets->shouldReceive('get->getSheets')->andReturn([$sheets]);
297+
$this->spreadsheets->expects('get->getSheets')->andReturn([$sheets]);
298298
$this->spreadsheets
299-
->shouldReceive('batchUpdate')
299+
->expects('batchUpdate')
300300
->andReturn(new BatchUpdateSpreadsheetResponse);
301301

302-
$this->sheet->shouldReceive('sheetList')->andReturn([$sheets]);
303302
$response = $this->sheet->deleteSheet('title');
304303
$this->assertNotNull($response);
305304
}
306305

307306
public function test_get_proper_ranges()
308307
{
309308
$this->values
310-
->shouldReceive('batchUpdate')
309+
->expects('batchUpdate')
311310
->times(3)
312311
->andReturn(new BatchUpdateValuesResponse);
313312

tests/SheetsTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function tearDown(): void
3131

3232
public function test_service()
3333
{
34-
$this->google->shouldReceive('make')->once()->andReturns(m::mock(\Google\Service\Sheets::class));
34+
$this->google->expects('make')->once()->andReturns(m::mock(\Google\Service\Sheets::class));
3535

3636
// Sheets::setService($this->google->make('Sheets'));
3737

@@ -40,12 +40,11 @@ public function test_service()
4040

4141
public function test_set_access_token()
4242
{
43-
$this->google->shouldReceive('getCache')->once()->andReturn(m::self());
44-
$this->google->shouldReceive('clear')->once();
45-
$this->google->shouldReceive('setAccessToken')->once();
46-
$this->google->shouldReceive('isAccessTokenExpired')->once()->andReturns(true);
47-
$this->google->shouldReceive('fetchAccessTokenWithRefreshToken')->once();
48-
$this->google->shouldReceive('make')->times(2)->andReturns(
43+
$this->google->expects('getCache->clear')->once();
44+
$this->google->expects('setAccessToken')->once();
45+
$this->google->expects('isAccessTokenExpired')->once()->andReturns(true);
46+
$this->google->expects('fetchAccessTokenWithRefreshToken')->once();
47+
$this->google->expects('make')->times(2)->andReturns(
4948
m::mock(\Google\Service\Sheets::class),
5049
m::mock(\Google\Service\Drive::class)
5150
);
@@ -61,7 +60,7 @@ public function test_set_access_token()
6160

6261
public function test_trait()
6362
{
64-
Sheets::shouldReceive('setAccessToken')->with('test')->once()->andReturn(m::self());
63+
Sheets::expects('setAccessToken')->with('test')->once()->andReturn(m::self());
6564

6665
$sheets = (new User)->sheets();
6766

0 commit comments

Comments
 (0)