Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renames psrBatchLogger to psrLogger #690

Merged
merged 1 commit into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/ErrorReporting/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ class Bootstrap
const DEFAULT_LOGNAME = 'app-error';

/** @var PsrLogger */
public static $psrBatchLogger;
public static $psrLogger;

/**
* Register hooks for error reporting.
*
* @param PsrLogger $psrBatchLogger
* @param PsrLogger $psrLogger
* @return void
* @codeCoverageIgnore
*/
public static function init(PsrLogger $psrBatchLogger = null)
public static function init(PsrLogger $psrLogger = null)
{
self::$psrBatchLogger = $psrBatchLogger ?: (new LoggingClient())
self::$psrLogger = $psrLogger ?: (new LoggingClient())
->psrLogger(self::DEFAULT_LOGNAME, [
'batchEnabled' => true,
'debugOutput' => true,
Expand Down Expand Up @@ -116,8 +116,8 @@ public static function getErrorLevelString($level)
public static function exceptionHandler($ex)
{
$message = sprintf('PHP Notice: %s', (string)$ex);
if (self::$psrBatchLogger) {
self::$psrBatchLogger->error($message);
if (self::$psrLogger) {
self::$psrLogger->error($message);
} else {
fwrite(STDERR, $message . PHP_EOL);
}
Expand All @@ -141,11 +141,11 @@ public static function errorHandler($level, $message, $file, $line)
$file,
$line
);
if (!self::$psrBatchLogger) {
if (!self::$psrLogger) {
return false;
}
$service = self::$psrBatchLogger->getMetadataProvider()->serviceId();
$version = self::$psrBatchLogger->getMetadataProvider()->versionId();
$service = self::$psrLogger->getMetadataProvider()->serviceId();
$version = self::$psrLogger->getMetadataProvider()->versionId();
$context = [
'context' => [
'reportLocation' => [
Expand All @@ -159,7 +159,7 @@ public static function errorHandler($level, $message, $file, $line)
'version' => $version
]
];
self::$psrBatchLogger->log(
self::$psrLogger->log(
self::getErrorLevelString($level),
$message,
$context
Expand All @@ -178,10 +178,10 @@ public static function shutdownHandler()
case E_PARSE:
case E_COMPILE_ERROR:
case E_CORE_ERROR:
$service = self::$psrBatchLogger
$service = self::$psrLogger
->getMetadataProvider()
->serviceId();
$version = self::$psrBatchLogger
$version = self::$psrLogger
->getMetadataProvider()
->versionId();
$message = sprintf(
Expand All @@ -204,8 +204,8 @@ public static function shutdownHandler()
'version' => $version
]
];
if (self::$psrBatchLogger) {
self::$psrBatchLogger->log(
if (self::$psrLogger) {
self::$psrLogger->log(
self::getErrorLevelString($err['type']),
$message,
$context
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/ErrorReporting/BootstrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testExceptionHandler(
$expectedMessage = sprintf('PHP Notice: %s', (string)$exception);
$this->psrBatchLogger->error($expectedMessage)
->shouldBeCalledTimes(1);
Bootstrap::$psrBatchLogger = $this->psrBatchLogger->reveal();
Bootstrap::$psrLogger = $this->psrBatchLogger->reveal();
Bootstrap::exceptionHandler($exception);
}

Expand All @@ -117,7 +117,7 @@ public function testExceptionHandlerWithoutLogger(
$exception
) {
$expectedMessage = sprintf('PHP Notice: %s', (string)$exception);
Bootstrap::$psrBatchLogger = null;
Bootstrap::$psrLogger = null;
Bootstrap::exceptionHandler($exception);
$this->assertEquals($expectedMessage . PHP_EOL, MockValues::$stderr);
}
Expand Down Expand Up @@ -173,7 +173,7 @@ public function testErrorHandler(
$expectedMessage,
$expectedContext
)->shouldBeCalledTimes(1);
Bootstrap::$psrBatchLogger = $this->psrBatchLogger->reveal();
Bootstrap::$psrLogger = $this->psrBatchLogger->reveal();
MockValues::$errorReporting = $error['type']; // always match
BootStrap::errorHandler(
$error['type'],
Expand All @@ -185,7 +185,7 @@ public function testErrorHandler(

public function testErrorHandlerWithMinorError()
{
Bootstrap::$psrBatchLogger = null;
Bootstrap::$psrLogger = null;
MockValues::$errorReporting = 0;
$result = BootStrap::errorHandler(
E_ERROR,
Expand All @@ -197,7 +197,7 @@ public function testErrorHandlerWithMinorError()
}

public function testErrorHandlerWithoutLogger() {
Bootstrap::$psrBatchLogger = null;
Bootstrap::$psrLogger = null;
MockValues::$errorReporting = E_ERROR;
$result = BootStrap::errorHandler(
E_ERROR,
Expand Down Expand Up @@ -234,7 +234,7 @@ public function testShutdownHandler(
if (!in_array($error['type'], $fatalErrors, true)) {
// The shutdownHandler should not do anything, so it should pass
// with the empty psrBatchLogger mock.
Bootstrap::$psrBatchLogger = $this->psrBatchLogger->reveal();
Bootstrap::$psrLogger = $this->psrBatchLogger->reveal();
$this->assertNull(BootStrap::shutdownHandler());
return;
}
Expand Down Expand Up @@ -266,7 +266,7 @@ public function testShutdownHandler(
$expectedMessage,
$expectedContext
)->shouldBeCalledTimes(1);
Bootstrap::$psrBatchLogger = $this->psrBatchLogger->reveal();
Bootstrap::$psrLogger = $this->psrBatchLogger->reveal();
BootStrap::shutdownHandler();
}

Expand Down