コード例 #1
0
 /**
  * Tests that we get the proper result when setting a profile summary,
  * whether it's by ID, by name, or the object itself.
  *
  * @runInSeparateProcess
  * @preserveGlobalState disabled
  */
 public function testProfileSetting()
 {
     // For this test we will need a mock API object
     define('GOOGLE_ANALYTICS_API_AUTH_EMAIL', '*****@*****.**');
     define('GOOGLE_ANALYTICS_API_AUTH_KEYFILE', __FILE__);
     define('GOOGLE_ANALYTICS_API_DATA_DIR', sys_get_temp_dir());
     define('GOOGLE_ANALYTICS_API_LOG_FILE', GOOGLE_ANALYTICS_API_DATA_DIR . DIRECTORY_SEPARATOR . 'log.txt');
     $profile1 = new ProfileSummary();
     $profile1->setID('1');
     $profile1->setName('Foo');
     $profile2 = new ProfileSummary();
     $profile2->setID('2');
     $profile2->setName('Bar');
     $profile3 = new ProfileSummary();
     $profile3->setID('3');
     $profile3->setName('Baz');
     $api = $this->getMockBuilder(__NAMESPACE__ . '\\API')->setMethods(array('getProfileSummaryByID', 'getProfileSummaryByName'))->getMock();
     $api->method('getProfileSummaryByID')->will($this->returnValue($profile1));
     $api->method('getProfileSummaryByName')->will($this->returnValue($profile2));
     $q = new GaDataQuery();
     // First of all, make sure this exception is thrown when necessary
     $q->setProfile('1');
     $this->assertThrows(__NAMESPACE__ . '\\LogicException', array($q, 'getProfile'));
     $q->setAPIInstance($api);
     /* Now we should get profile #1 (which has nothing to do with the
        parameter we passed when we set the profile; it's because of the mocked
        method). */
     $this->assertSame($profile1, $q->getProfile());
     /* If we set a profile by its name, the existing one should be cleared
        out. */
     $q->setProfileName('Bar');
     $this->assertSame($profile2, $q->getProfile());
     // And if we set a profile object explicitly, we should always get that
     foreach (array($profile1, $profile2, $profile3) as $profile) {
         $q->setProfile($profile);
         $this->assertSame($profile, $q->getProfile());
     }
 }