Skip to content

Commit

Permalink
Merge pull request #27 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 0.7.0
  • Loading branch information
forevermatt authored Apr 6, 2020
2 parents 7ec9b55 + 736bff2 commit e158a35
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 23 deletions.
19 changes: 10 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
nbproject/
.DS_Store
vendor/
*.local.php
build/
.vagrant/
.idea/
composer.phar
*.db
nbproject/
.DS_Store
vendor/
*.local.php
build/
.vagrant/
.idea/
composer.phar
*.db
.phpunit.result.cache
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
it-now: clean install phpunit
it-now: clean install test

clean:
sudo rm -rf ./vendor
rm -f composer.lock
docker-compose kill
docker system prune -f

install:
docker-compose run --rm cli bash -c "cd /data;composer install"
docker-compose run --rm cli bash -c "composer install"

update:
docker-compose run --rm cli bash -c "cd /data;composer update"
docker-compose run --rm cli bash -c "composer update"

phpunit:
docker-compose run --rm cli bash -c "cd /data/SilMock/tests;./phpunit"

# For use in virtualbox.
test:
docker-compose run --rm cli bash -c "cd /data/SilMock/tests; ./phpunit"

# For use in a Vagrant VM:
vagrantTest:
cd /var/lib/GA_mock/SilMock/tests; /var/lib/GA_mock/SilMock/tests/phpunit
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ If not, then use vagrant up:
- vagrant up
- vagrant ssh
- cd /var/lib/GA_mock
- make test
- make vagrantTest

Data Persistence
----------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ protected function removeDelegate(int $recordId)

public function listUsersSettingsDelegates($userId, $optParams = array())
{
return new Google_Service_Gmail_ListDelegatesResponse(array(
'delegates' => array(),
));
$response = new Google_Service_Gmail_ListDelegatesResponse();
$response->setDelegates($this->listDelegatesFor($userId));
return $response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

use PHPUnit\Framework\Assert;
use SilMock\Google\Service\Gmail\Resource\UsersSettingsDelegates;
use SilMock\Google\Service\GoogleFixtures;

class UsersSettingsDelegatesTest extends PHPUnit\Framework\TestCase
{
public $dataFile = DATAFILE4;

protected function setUp(): void
{
$this->emptyFixturesDataFile();
}

private function emptyFixturesDataFile()
{
$fixturesClass = new GoogleFixtures($this->dataFile);
$fixturesClass->removeAllFixtures();
}

protected function tearDown(): void
{
$this->emptyFixturesDataFile();
}

public function testListUsersSettingsDelegates()
{
// Arrange:
$accountEmail = '[email protected]';
$delegateEmail = '[email protected]';

// Act
$before = $this->getDelegatesForAccount($accountEmail);
$this->delegateAccessToAccountBy($accountEmail, $delegateEmail);
$after = $this->getDelegatesForAccount($accountEmail);

// Assert:
$delegatesBefore = $before->getDelegates();
Assert::assertEmpty($delegatesBefore);

$delegatesAfter = $after->getDelegates();
Assert::assertNotEmpty($delegatesAfter);

$foundExpectedDelegate = false;
foreach ($delegatesAfter as $delegate) {
if ($delegate->delegateEmail === $delegateEmail) {
$foundExpectedDelegate = true;
break;
}
}
Assert::assertTrue($foundExpectedDelegate, sprintf(
'Did not find %s in %s',
$delegateEmail,
json_encode($delegatesAfter)
));
}

private function delegateAccessToAccountBy(
string $accountEmail,
string $delegateEmail
) {
$gmailDelegate = new Google_Service_Gmail_Delegate();
$gmailDelegate->setDelegateEmail($delegateEmail);
$userSettingsDelegates = new UsersSettingsDelegates($this->dataFile);
$userSettingsDelegates->create(
$accountEmail,
$gmailDelegate
);
}

private function getDelegatesForAccount(string $emailAddress)
{
$userSettingsDelegates = new UsersSettingsDelegates($this->dataFile);
return $userSettingsDelegates->listUsersSettingsDelegates($emailAddress);
}
}
7 changes: 6 additions & 1 deletion SilMock/tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
define('DATAFILE1', __DIR__.'/../DataStore/Sqlite/Test1_Google_Service_Data.db');
define('DATAFILE2', __DIR__.'/../DataStore/Sqlite/Test2_Google_Service_Data.db');
define('DATAFILE3', __DIR__.'/../DataStore/Sqlite/Test3_Google_Service_Data.db');
define('DATAFILE4', __DIR__.'/../DataStore/Sqlite/Test4_Google_Service_Data.db');

if(!file_exists(DATAFILE1)){
touch(DATAFILE1);
Expand All @@ -17,4 +18,8 @@

if(!file_exists(DATAFILE3)){
touch(DATAFILE3);
}
}

if(!file_exists(DATAFILE4)){
touch(DATAFILE4);
}

0 comments on commit e158a35

Please sign in to comment.