Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kawax committed Apr 22, 2022
1 parent 42f141a commit c460a3c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
18 changes: 10 additions & 8 deletions src/Concerns/SheetsProperties.php
Expand Up @@ -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();
Expand All @@ -32,8 +34,8 @@ public function sheetProperties()
/**
* @return string
*/
public function getSpreadsheetId()
public function getSpreadsheetId(): string
{
return $this->spreadsheetId;
return $this->spreadsheetId ?? '';
}
}
8 changes: 4 additions & 4 deletions src/Concerns/SheetsValues.php
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Sheets.php
Expand Up @@ -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();
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
11 changes: 6 additions & 5 deletions tests/SheetsMockTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit c460a3c

Please sign in to comment.