Skip to content

Commit d4b6286

Browse files
committed
test: fix error handling
The zero-equality tests were depending on error_reporting(E_NOTICE) which may not be set in all environments.
1 parent 9e0d29e commit d4b6286

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

test/10-ValueTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use mle86\Value\Tests\Helpers\TestWrapper4;
88
use mle86\Value\Tests\Helpers\TestWrapper9;
99
use mle86\Value\Value;
10-
use PHPUnit\Framework\Error\Error;
1110
use PHPUnit\Framework\TestCase;
1211

1312
/**
@@ -155,12 +154,16 @@ public function testEquals()
155154
}
156155

157156
/**
157+
* This test ensures that our object instances are never considered equal to zero.
158+
*
159+
* This requires an implicit object-to-int cast which may causes a NOTICE
160+
* depending on the error_reporting setting.
161+
*
158162
* @depends testEquals
159163
*/
160164
public function testBuiltinEqualsZero()
161165
{
162-
$this->expectException(Error::class);
163-
$this->assertFalse((self::$tw1 == 0 || 0 == self::$tw1),
166+
$this->assertFalse(@(self::$tw1 == 0 || 0 == self::$tw1),
164167
"wrapper is considered equal to zero by builtin== !");
165168
}
166169

@@ -472,8 +475,7 @@ public function testExtendedBuiltinEqualsZero($additional_property, ExtTestWrapp
472475
{
473476
$ew->set_additional_property($additional_property);
474477

475-
$this->expectException(Error::class);
476-
$this->assertFalse(($ew == 0 || 0 == $ew),
478+
$this->assertFalse(@($ew == 0 || 0 == $ew),
477479
"Extended wrapper object is considered equal to zero by builtin== !");
478480
}
479481

test/15-SerializableValueTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use mle86\Value\AbstractSerializableValue;
66
use mle86\Value\Tests\Helpers\TestSWrapper6;
77
use mle86\Value\Value;
8-
use PHPUnit\Framework\Error\Error;
98
use PHPUnit\Framework\TestCase;
109

1110
/**
@@ -87,8 +86,7 @@ public function testBuiltinEquals(AbstractSerializableValue $tw)
8786
*/
8887
public function testBuiltinEqualsZero(AbstractSerializableValue $tw)
8988
{
90-
$this->expectException(Error::class);
91-
$this->assertFalse(($tw == 0),
89+
$this->assertFalse(@($tw == 0),
9290
"serializable wrapper considered zero as ==equal !");
9391
}
9492

0 commit comments

Comments
 (0)