예제 #1
0
 /**
  * Attempts to fetch the email address associated with a developerId.
  *
  * If no such developer exists, null is returned. We turn off all logging,
  * both by the main logger and by any subscribers. (The exception is that
  * non-404 ResponseExceptions are logged.) It is therefore the
  * responsibility of any client of this method to handle appropriate
  * logging.
  *
  * @param string $id
  *   The developerId of the developer in question
  *
  * @return string|null
  *   The email address of the developer, or null if no such developer
  *   exists.
  */
 private function getDeveloperMailById($id)
 {
     static $devs = array();
     if (!isset($devs[$id])) {
         $cached_logger = self::$logger;
         $config = clone $this->config;
         // Suppress (almost) all logging.
         $config->logger = new \Psr\Log\NullLogger();
         $config->subscribers = array();
         $dev = new Developer($config);
         try {
             $dev->load($id);
             $devs[$id] = $dev->getEmail();
         } catch (ResponseException $e) {
             $devs[$id] = null;
             // Log exceptions that are NOT 404s.
             if ($e->getCode() != 404) {
                 $warning = 'Attempt to load dev “%s” resulted in response code of %d.';
                 $warningArgs = array($id, $e->getCode());
                 $cached_logger->warning(vsprintf($warning, $warningArgs));
             }
         }
         self::$logger = $cached_logger;
     }
     return $devs[$id];
 }
예제 #2
0
 public function testDeveloperCRUD()
 {
     $developer = new Developer(self::$orgConfig);
     $mail = 'phpunit-' . $this->randomString() . '@example.com';
     // Begin creation
     $developer->blankValues();
     $developer->setEmail($mail);
     $developer->setFirstName($this->randomString());
     $developer->setLastName($this->randomString());
     $developer->setUserName($this->randomString());
     $developer->setAttribute('foo', 'bar');
     try {
         $developer->save();
     } catch (\Exception $e) {
         $this->fail('Cannot save developer at create time: [' . $e->getCode() . '] ' . $e->getMessage());
     }
     $this->assertNotEmpty($developer->getDeveloperId());
     $this->assertEquals($mail, $developer->getEmail());
     $this->assertEquals('bar', $developer->getAttribute('foo'));
     // End creation
     // Begin load
     $developer->blankValues();
     try {
         $developer->load($mail);
     } catch (\Exception $e) {
         $this->fail();
         return;
     }
     $this->assertNotEmpty($developer->getDeveloperId());
     $this->assertEquals($mail, $developer->getEmail());
     $this->assertEquals('bar', $developer->getAttribute('foo'));
     // End load
     // Begin update
     $developer->setAttribute('foo', 'baz');
     try {
         $developer->save(false);
     } catch (\Exception $e) {
         $this->fail('Cannot save developer at update time');
         return;
     }
     $developer->blankValues();
     try {
         $developer->load($mail);
     } catch (\Exception $e) {
         $this->fail('Cannot reload developer after update');
         return;
     }
     $this->assertEquals('baz', $developer->getAttribute('foo'));
     // End update
     // Begin delete
     try {
         $developer->delete();
     } catch (\Exception $e) {
         $this->fail('Cannot delete developer');
     }
     $developer->blankValues();
     try {
         $developer->load($mail);
         // If we succeed in the load, the developer was not deleted.
         $this->fail('Developer deletion failed.');
     } catch (\Exception $e) {
         $this->assertEquals(404, $e->getCode());
     }
     // End delete
 }