Skip to content

Commit ff70d7a

Browse files
Merge 539463e into 428b63d
2 parents 428b63d + 539463e commit ff70d7a

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

tests/ArrayHelper/GetValueTest.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use InvalidArgumentException;
99
use PHPUnit\Framework\TestCase;
1010
use stdClass;
11+
use Throwable;
1112
use Yiisoft\Arrays\ArrayHelper;
1213
use Yiisoft\Arrays\Tests\Objects\Magic;
1314
use Yiisoft\Arrays\Tests\Objects\Post1;
@@ -221,19 +222,25 @@ public function testGetNestedValueFromObjectFromArray(): void
221222
*/
222223
public function testGetValueNonexistingProperties1(): void
223224
{
224-
$this->expectError();
225-
$object = new Post1();
226-
$this->assertNull(ArrayHelper::getValue($object, 'nonExisting'));
225+
try {
226+
$object = new Post1();
227+
ArrayHelper::getValue($object, 'nonExisting');
228+
} catch (Throwable $e) {
229+
$this->assertSame('Undefined property: Yiisoft\Arrays\Tests\Objects\Post1::$nonExisting', $e->getMessage());
230+
}
227231
}
228232

229233
/**
230234
* This is expected to result in a PHP error.
231235
*/
232236
public function testGetValueNonexistingProperties2(): void
233237
{
234-
$this->expectError();
235-
$arrayObject = new ArrayObject(['id' => 23], ArrayObject::ARRAY_AS_PROPS);
236-
$this->assertEquals(23, ArrayHelper::getValue($arrayObject, 'nonExisting'));
238+
try {
239+
$arrayObject = new ArrayObject(['id' => 23], ArrayObject::ARRAY_AS_PROPS);
240+
ArrayHelper::getValue($arrayObject, 'nonExisting');
241+
} catch (Throwable $e) {
242+
$this->assertSame('Undefined array key "nonExisting"', $e->getMessage());
243+
}
237244
}
238245

239246
public function testGetValueFromStaticProperty(): void
@@ -246,12 +253,12 @@ public function testGetValueFromStaticProperty(): void
246253
public function testGetUndefinedPropertyFromObject(): void
247254
{
248255
$object = new stdClass();
249-
if (PHP_VERSION_ID >= 80000) {
250-
$this->expectWarning();
251-
} else {
252-
$this->expectNotice();
256+
257+
try {
258+
ArrayHelper::getValue($object, 'var');
259+
} catch (Throwable $e) {
260+
$this->assertSame('Undefined property: stdClass::$var', $e->getMessage());
253261
}
254-
ArrayHelper::getValue($object, 'var');
255262
}
256263

257264
public function testExistingMagicObjectProperty(): void

0 commit comments

Comments
 (0)