Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checking for object props deprecation. #1547

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions deploy/tests/integration/controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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',
Expand Down
Loading