diff --git a/.gitignore b/.gitignore index 4fa82b9..c08d53b 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Makefile b/Makefile index 1e35e14..a45646a 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 9a5275b..c81f038 100644 --- a/README.md +++ b/README.md @@ -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 ---------------- diff --git a/SilMock/Google/Service/Gmail/Resource/UsersSettingsDelegates.php b/SilMock/Google/Service/Gmail/Resource/UsersSettingsDelegates.php index f17d94f..27c4663 100644 --- a/SilMock/Google/Service/Gmail/Resource/UsersSettingsDelegates.php +++ b/SilMock/Google/Service/Gmail/Resource/UsersSettingsDelegates.php @@ -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; } } diff --git a/SilMock/tests/Google/Service/Gmail/Resource/UsersSettingsDelegatesTest.php b/SilMock/tests/Google/Service/Gmail/Resource/UsersSettingsDelegatesTest.php new file mode 100644 index 0000000..649a79e --- /dev/null +++ b/SilMock/tests/Google/Service/Gmail/Resource/UsersSettingsDelegatesTest.php @@ -0,0 +1,77 @@ +emptyFixturesDataFile(); + } + + private function emptyFixturesDataFile() + { + $fixturesClass = new GoogleFixtures($this->dataFile); + $fixturesClass->removeAllFixtures(); + } + + protected function tearDown(): void + { + $this->emptyFixturesDataFile(); + } + + public function testListUsersSettingsDelegates() + { + // Arrange: + $accountEmail = 'john_smith@example.org'; + $delegateEmail = 'mike_manager@example.org'; + + // 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); + } +} diff --git a/SilMock/tests/bootstrap.php b/SilMock/tests/bootstrap.php index 4254c69..22364cc 100644 --- a/SilMock/tests/bootstrap.php +++ b/SilMock/tests/bootstrap.php @@ -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); @@ -17,4 +18,8 @@ if(!file_exists(DATAFILE3)){ touch(DATAFILE3); -} \ No newline at end of file +} + +if(!file_exists(DATAFILE4)){ + touch(DATAFILE4); +}