Skip to content

Commit

Permalink
Local Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kawax committed Mar 27, 2017
1 parent 98bd1f3 commit 6fbdf19
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,5 @@
composer.lock
.DS_Store
/build
dev-*
tests/data/test*
!tests/data/test-config-sample.php
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -188,6 +188,23 @@ Remove
```
https://github.com/pulkitjalan/google-apiclient#usage

## Local Testing
- composer install
- Create new Google Spreadsheet for testing. **Don't use Important Sheets.**
- Put API Credentials(Service Account Key) to `tests/data/test-credentials.json`
- Copy `test-config-sample.php`, rename to `test-config.php`

```
<?php
$this->spreadsheetId = '{SpreadsheetID}';
$this->spreadsheetTitle = 'Test Spreadsheet';
$this->sheetTitle = 'Sheet 1';
$this->sheetId = 0;
```

- Run phpunit

## LICENSE
MIT
Copyright kawax
9 changes: 8 additions & 1 deletion src/GoogleSheets/SheetsDrive.php
@@ -1,4 +1,5 @@
<?php

namespace GoogleSheets;

use \Google_Service_Drive;
Expand All @@ -21,7 +22,13 @@ public function spreadsheetList()

$list = [];

$files = $this->drive->files->listFiles(['q' => "mimeType = 'application/vnd.google-apps.spreadsheet'"])->getFiles();
$files = $this->drive
->files
->listFiles([
'q' => "mimeType = 'application/vnd.google-apps.spreadsheet'",
])
->getFiles();

foreach ($files as $file) {
$list[$file->id] = $file->name;
}
Expand Down
18 changes: 15 additions & 3 deletions tests/SheetsTest.php
Expand Up @@ -48,8 +48,8 @@ public function setUp()
parent::setUp();

if ($this->checkDevConfig()) {
$config = __DIR__ . '/data/dev-credentials.json';
include __DIR__ . '/data/dev-config.php';
$config = __DIR__ . '/data/test-credentials.json';
include __DIR__ . '/data/test-config.php';
} else {
$config = __DIR__ . '/data/service-account.json';
}
Expand Down Expand Up @@ -79,7 +79,7 @@ public function tearDown()
*/
private function checkDevConfig()
{
return file_exists(__DIR__ . '/data/dev-config.php');
return file_exists(__DIR__ . '/data/test-config.php');
}

public function testSheetsInstance()
Expand All @@ -92,6 +92,18 @@ public function testService()
$this->assertInstanceOf('Google_Service_Sheets', $this->sheet->getService());
}

public function testSpreadsheetByTitle()
{
if (!$this->checkDevConfig()) {
return;
}

$this->sheet->setDriveService($this->client->make('drive'));
$properties = $this->sheet->spreadsheetByTitle($this->spreadsheetTitle)->spreadsheetProperties();

$this->assertEquals($this->spreadsheetTitle, $properties->title);
}

public function testSpreadsheetProperties()
{
if (!$this->checkDevConfig()) {
Expand Down
File renamed without changes.

0 comments on commit 6fbdf19

Please sign in to comment.