From 40232ff58fa40439800ffc0a0a2c6d433aa59d7c Mon Sep 17 00:00:00 2001 From: Roy Ronalds Date: Sun, 1 Oct 2023 23:42:37 -0400 Subject: [PATCH] Fix checking for object props deprecation. --- .../controller/ApiControllerTest.php | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/deploy/tests/integration/controller/ApiControllerTest.php b/deploy/tests/integration/controller/ApiControllerTest.php index 52e768236..d57088fb4 100644 --- a/deploy/tests/integration/controller/ApiControllerTest.php +++ b/deploy/tests/integration/controller/ApiControllerTest.php @@ -13,6 +13,14 @@ class ApiControllerTest extends NWTest private $controller; public $char; + public function helperPropertyExists( + $property, + $object, + $message = 'Property does not exist' + ) { + return $this->assertTrue(property_exists($object, $property), $message); + } + public function setUp(): void { parent::setUp(); @@ -89,10 +97,10 @@ public function testSearch() $result = $this->controller->nw_json(); $payload = $this->extractPayload($result); - $this->assertObjectHasAttribute('char_matches', $payload); + $this->helperPropertyExists('char_matches', $payload); $this->assertCount(1, $payload->char_matches); - $this->assertObjectHasAttribute('uname', $payload->char_matches[0]); - $this->assertObjectHasAttribute('player_id', $payload->char_matches[0]); + $this->helperPropertyExists('uname', $payload->char_matches[0]); + $this->helperPropertyExists('player_id', $payload->char_matches[0]); } public function testChats() @@ -106,7 +114,7 @@ public function testChats() $result = $this->controller->nw_json(); $payload = $this->extractPayload($result); - $this->assertObjectHasAttribute('chats', $payload); + $this->helperPropertyExists('chats', $payload); } public function testLatestChat() @@ -120,7 +128,7 @@ public function testLatestChat() $result = $this->controller->nw_json(); $payload = $this->extractPayload($result); $this->assertInstanceOf('stdClass', $payload); - $this->assertObjectHasAttribute('latest_chat_id', $payload); + $this->helperPropertyExists('latest_chat_id', $payload); } public function testIndex() @@ -134,13 +142,13 @@ public function testIndex() $result = $this->controller->nw_json(); $payload = $this->extractPayload($result); - $this->assertObjectHasAttribute('player', $payload); - $this->assertObjectHasAttribute('inventory', $payload); - $this->assertObjectHasAttribute('event', $payload); - $this->assertObjectHasAttribute('message', $payload); - $this->assertObjectHasAttribute('member_counts', $payload); - $this->assertObjectHasAttribute('unread_messages_count', $payload); - $this->assertObjectHasAttribute('unread_events_count', $payload); + $this->helperPropertyExists('player', $payload); + $this->helperPropertyExists('inventory', $payload); + $this->helperPropertyExists('event', $payload); + $this->helperPropertyExists('message', $payload); + $this->helperPropertyExists('member_counts', $payload); + $this->helperPropertyExists('unread_messages_count', $payload); + $this->helperPropertyExists('unread_events_count', $payload); } public function testPlayer() @@ -168,7 +176,7 @@ public function testLatestEvent() $result = $this->controller->nw_json(); $payload = $this->extractPayload($result); $this->assertInstanceOf('stdClass', $payload); - $this->assertObjectHasAttribute('event', $payload); + $this->helperPropertyExists('event', $payload); } public function testLatestMessage() @@ -182,7 +190,7 @@ public function testLatestMessage() $result = $this->controller->nw_json(); $payload = $this->extractPayload($result); $this->assertInstanceOf('stdClass', $payload); - $this->assertObjectHasAttribute('message', $payload); + $this->helperPropertyExists('message', $payload); } public function testDeactivateCharError() @@ -198,7 +206,7 @@ public function testDeactivateCharError() $payload = $this->extractPayload($result); // There should be no such character to deactivate - $this->assertObjectHasAttribute('error', $payload); + $this->helperPropertyExists('error', $payload); } public function testReactivateCharError() @@ -214,7 +222,7 @@ public function testReactivateCharError() $payload = $this->extractPayload($result); // There should be no such character to reactivate - $this->assertObjectHasAttribute('error', $payload); + $this->helperPropertyExists('error', $payload); } public function testNextTarget() @@ -230,7 +238,7 @@ public function testNextTarget() $result = $this->controller->nw_json(); $payload = $this->extractPayload($result); $this->assertNotEmpty($payload, 'No payload returned'); - $this->assertObjectHasAttribute('uname', $payload); + $this->helperPropertyExists('uname', $payload); } public function testNextTargetShifted() @@ -245,7 +253,7 @@ public function testNextTargetShifted() RequestWrapper::inject($request); $payload = $this->extractPayload($this->controller->nw_json()); $this->assertNotEmpty($payload, 'No payload returned'); - $this->assertObjectHasAttribute('uname', $payload, 'No uname returned'); + $this->helperPropertyExists('uname', $payload, 'No uname returned'); $first_target = $payload->uname; $request2 = new Request([ 'type' => 'nextTarget',