Skip to content

Commit

Permalink
Merge pull request #546 from rollbar/revert-666a1a2
Browse files Browse the repository at this point in the history
Re-fix isset check and revert PR #539
  • Loading branch information
Bishop Bettini committed Nov 10, 2021
2 parents 1a4744c + 8bc8cc7 commit ad22e35
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,12 @@ private function setMinimumLevel(array $config): void

private function setReportSuppressed(array $config): void
{
if (isset($config['reportSuppressed'])) {
$this->reportSuppressed = $config['reportSuppressed'];
} elseif (isset($config['report_suppressed'])) {
$this->reportSuppressed = $config['report_suppressed'];
$this->reportSuppressed = isset($config['reportSuppressed']) && $config['reportSuppressed'];
if (!$this->reportSuppressed) {
$this->reportSuppressed = isset($config['report_suppressed']) && $config['report_suppressed'];
}

if (!isset($this->reportSuppressed)) {
if (!$this->reportSuppressed) {
$this->reportSuppressed = \Rollbar\Defaults::get()->reportSuppressed();
}
}
Expand Down Expand Up @@ -1002,7 +1001,12 @@ private function levelTooLow(Level $level): bool
return $level->toInt() < $this->minimumLevel;
}

private function shouldSuppress(): bool
/**
* Decides if a given log message should be suppressed by policy.
* If so, then a debug message is emitted: "Ignoring (error reporting has been disabled in PHP config"
* @since 3.0.1
*/
public function shouldSuppress(): bool
{
return error_reporting() === 0 && !$this->reportSuppressed;
}
Expand Down
34 changes: 31 additions & 3 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,37 @@ private function prepareMockPayload($level)
return new Payload($data, $this->getTestAccessToken());
}

public function testReportSuppressed()
{
$this->assertTrue(true, "Don't know how to unit test this. PRs welcome");
/**
* Test the shouldSuppress method, which is driven by the configuration
* given and the value of the PHP engine's error_reporting() setting.
*
* - error reporting value
* | - configuration key
* | | - configuration value
* | | | - shouldSuppress() result
* v v v v
* @testWith [0, "reportSuppressed", false, true]
* [0, "reportSuppressed", true, false]
* [1, "reportSuppressed", false, false]
* [0, "report_suppressed", false, true]
* [0, "report_suppressed", true, false]
* [1, "report_suppressed", false, false]
*/
public function testReportSuppressed($errorReporting, $configKey, $configValue, $shouldSuppressExpect)
{
$oldErrorReporting = error_reporting($errorReporting);
try {
$config = new Config(array(
$configKey => $configValue
));
$this->assertSame(
$shouldSuppressExpect,
$config->shouldSuppress(),
'shouldSuppress() did not return the expected value for the error_reporting and configuration given'
);
} finally {
error_reporting($oldErrorReporting);
}
}

public function testFilter()
Expand Down

0 comments on commit ad22e35

Please sign in to comment.