Esempio n. 1
0
 public function __construct()
 {
     try {
         if (!self::$_staticPropsReady) {
             self::_initStaticProperties();
         }
         $this->_logger = new \Logger(GOOGLE_MYBUSINESS_API_LOG_FILE, GOOGLE_MYBUSINESS_API_LOG_EMAIL, self::$_apiMutex);
         if (!\LoggingExceptions\Exception::hasLogger()) {
             \LoggingExceptions\Exception::registerLogger($this->_logger);
         }
         $this->_EXCEPTION_TYPE = __NAMESPACE__ . '\\RuntimeException';
     } catch (\Exception $e) {
         if ($e instanceof Exception) {
             throw $e;
         }
         throw new RuntimeException('Encountered error during initialization.', null, $e);
     }
 }
 /**
  * Helper method that calls the getSegments() method on the given instance,
  * asserts that it throws the specified exception and that it contains the
  * given message, asserts that the exception message is present in the last
  * line of the log file, and asserts that an email regarding the exception
  * is sent.
  *
  * @param Google\Analytics\TestAPI $instance
  * @param string $expectedException
  * @param string $expectedMessage
  * @param boolean $assertMatchingClass = false
  */
 protected function _testException(TestAPI $instance, $expectedException, $expectedMessage, $assertMatchingClass = false)
 {
     $this->assertThrows($expectedException, array($instance, 'getSegments'));
     if ($assertMatchingClass) {
         $this->assertEquals($expectedException, get_class($this->_lastException));
     }
     $this->assertEquals($expectedMessage, $this->_lastException->getMessage());
     \LoggingExceptions\Exception::getLogger()->flush();
     // Fortunately this works because we're not zipping it
     $fileContents = explode(PHP_EOL, trim(file_get_contents(GOOGLE_ANALYTICS_API_LOG_FILE)));
     $this->assertContains($expectedMessage, array_pop($fileContents));
     $this->assertContains($expectedMessage, $GLOBALS['__lastEmailSent']['message']);
     $this->assertEquals(GOOGLE_ANALYTICS_API_LOG_EMAIL, $GLOBALS['__lastEmailSent']['to']);
 }