Commit 70880e91 authored by catch's avatar catch

Issue #2561207 by stefan.r, Aki Tendo: assert() without a message breaks in PHP 5

parent e12fd0d0
...@@ -57,7 +57,7 @@ public static function register() { ...@@ -57,7 +57,7 @@ public static function register() {
if (version_compare(PHP_VERSION, '7.0.0-dev') < 0) { if (version_compare(PHP_VERSION, '7.0.0-dev') < 0) {
// PHP 5 - create a handler to throw the exception directly. // PHP 5 - create a handler to throw the exception directly.
assert_options(ASSERT_CALLBACK, function($file, $line, $code, $message) { assert_options(ASSERT_CALLBACK, function($file = '', $line = 0, $code = '', $message = '') {
if (empty($message)) { if (empty($message)) {
$message = $code; $message = $code;
} }
......
...@@ -167,12 +167,21 @@ function stubTest() { ...@@ -167,12 +167,21 @@ function stubTest() {
// Check to see if runtime assertions are indeed on, if successful this // Check to see if runtime assertions are indeed on, if successful this
// will be the first of sixteen passes asserted in confirmStubResults() // will be the first of sixteen passes asserted in confirmStubResults()
try { try {
assert(FALSE, 'Lorem Ipsum'); // Test with minimum possible arguments to make sure no notice for
// missing argument is thrown.
assert(FALSE);
$this->fail('Runtime assertions are not working.'); $this->fail('Runtime assertions are not working.');
} }
catch (\AssertionError $e) { catch (\AssertionError $e) {
try {
// Now test with an error message to insure it is correctly passed
// along by the rethrow.
assert(FALSE, 'Lorem Ipsum');
}
catch ( \AssertionError $e ) {
$this->assertEqual($e->getMessage(), 'Lorem Ipsum', 'Runtime assertions Enabled and running.'); $this->assertEqual($e->getMessage(), 'Lorem Ipsum', 'Runtime assertions Enabled and running.');
} }
}
// This causes the second of the sixteen passes asserted in // This causes the second of the sixteen passes asserted in
// confirmStubResults(). // confirmStubResults().
$this->pass($this->passMessage); $this->pass($this->passMessage);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment