88use InvalidArgumentException ;
99use PHPUnit \Framework \TestCase ;
1010use stdClass ;
11+ use Throwable ;
1112use Yiisoft \Arrays \ArrayHelper ;
1213use Yiisoft \Arrays \Tests \Objects \Magic ;
1314use 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