Skip to content

Commit

Permalink
Cast "1" and "0" as booleans when they are expected as booleans.
Browse files Browse the repository at this point in the history
Rollbar/WordPress/UI creates checkboxes for booleans and stores the state as "1" and "0". The PHP8 version of https://github.com/rollbar/rollbar-php expects actual booleans. this updates the config builder to convert "1" and "0" into TRUE and FALSE.

Fixes: rollbar#119
  • Loading branch information
aaronjorbin committed Sep 13, 2023
1 parent 6492ad0 commit badf31f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@ public function buildPHPConfig()
} else if (isset($config[$setting]) && $config[$setting] === 'true') {
$config[$setting] = true;
}

// also handle 1 and 0 as booleans
else if (isset($config[$setting]) && $config[$setting] === '0') {
$config[$setting] = false;
} else if (isset($config[$setting]) && $config[$setting] === '1') {
$config[$setting] = true;
}
}

return $config;
Expand Down
16 changes: 16 additions & 0 deletions tests/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ public function testLoggingLevel(
}

}

/**
* Tests to ensure bools are properly converted from "1" and "0" strings
*
* @ticket https://github.com/rollbar/rollbar-php-wordpress/issues/119
*/
public function testSendMessageTraceBool(){
$plugin = $this->subject;

$plugin->setting( 'send_message_trace', '1' );
$plugin->setting( 'report_suppressed', '0' );
$data = $plugin->buildPHPConfig();

$this->assertTrue( $data['send_message_trace'] );
$this->assertFalse( $data['report_suppressed'] );
}

public static function loggingLevelTestDataProvider()
{
Expand Down

0 comments on commit badf31f

Please sign in to comment.