Skip to content

Commit

Permalink
tests: Use assertObjectHasProperty() (#263)
Browse files Browse the repository at this point in the history
Updates tests to use phpunit method `assertObjectHasProperty()`.

sebastianbergmann/phpunit#5478
  • Loading branch information
VerifiedJoseph authored Aug 21, 2023
1 parent 533ab79 commit 9e165d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
22 changes: 11 additions & 11 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public function testSend(): void
$client = new Client($server);
$response = $client->send($message);

$this->assertTrue(property_exists($response, 'topic'));
$this->assertTrue(property_exists($response, 'title'));
$this->assertTrue(property_exists($response, 'message'));
$this->assertTrue(property_exists($response, 'priority'));
$this->assertTrue(property_exists($response, 'tags'));
$this->assertObjectHasProperty('topic', $response);
$this->assertObjectHasProperty('title', $response);
$this->assertObjectHasProperty('message', $response);
$this->assertObjectHasProperty('priority', $response);
$this->assertObjectHasProperty('tags', $response);

$this->assertEquals(self::$messageParams->topic, $response->topic);
$this->assertEquals(self::$messageParams->title, $response->title);
Expand Down Expand Up @@ -84,9 +84,9 @@ public function testSendWithUserAuth(): void
$client = new Client($server, $auth);
$response = $client->send($message);

$this->assertTrue(property_exists($response, 'topic'));
$this->assertTrue(property_exists($response, 'title'));
$this->assertTrue(property_exists($response, 'message'));
$this->assertObjectHasProperty('topic', $response);
$this->assertObjectHasProperty('title', $response);
$this->assertObjectHasProperty('message', $response);

$this->assertEquals($topic, $response->topic);
$this->assertEquals(self::$messageParams->title, $response->title);
Expand Down Expand Up @@ -114,9 +114,9 @@ public function testSendWithTokenAuth(): void
$client = new Client($server, $auth);
$response = $client->send($message);

$this->assertTrue(property_exists($response, 'topic'));
$this->assertTrue(property_exists($response, 'title'));
$this->assertTrue(property_exists($response, 'message'));
$this->assertObjectHasProperty('topic', $response);
$this->assertObjectHasProperty('title', $response);
$this->assertObjectHasProperty('message', $response);

$this->assertEquals($topic, $response->topic);
$this->assertEquals(self::$messageParams->title, $response->title);
Expand Down
18 changes: 9 additions & 9 deletions tests/GuzzleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function testGet(): void
$body = Json::decode($response->getBody());

$this->assertIsObject($body);
$this->assertTrue(property_exists($body, 'args'));
$this->assertTrue(property_exists($body->args, 'test'));
$this->assertObjectHasProperty('args', $body);
$this->assertObjectHasProperty('test', $body->args);
$this->assertEquals('HelloWorld', $body->args->test[0]);
}

Expand All @@ -47,9 +47,9 @@ public function testPost(): void
$body = Json::decode($response->getBody());

$this->assertIsObject($body);
$this->assertTrue(property_exists($body, 'data'));
$this->assertTrue(property_exists($body, 'headers'));
$this->assertTrue(property_exists($body->headers, 'X-Httpbin-Test'));
$this->assertObjectHasProperty('data', $body);
$this->assertObjectHasProperty('headers', $body);
$this->assertObjectHasProperty('X-Httpbin-Test', $body->headers);

$this->assertEquals($data, $body->json);
$this->assertEquals($headerValue, $body->headers->{'X-Httpbin-Test'}[0]);
Expand All @@ -67,8 +67,8 @@ public function testBasicAuth(): void
$body = Json::decode($response->getBody());

$this->assertIsObject($body);
$this->assertTrue(property_exists($body, 'authorized'));
$this->assertTrue(property_exists($body, 'user'));
$this->assertObjectHasProperty('authorized', $body);
$this->assertObjectHasProperty('user', $body);

$this->assertEquals(true, $body->authorized);
$this->assertEquals($auth->getUsername(), $body->user);
Expand All @@ -86,8 +86,8 @@ public function testBearerToken(): void
$body = Json::decode($response->getBody());

$this->assertIsObject($body);
$this->assertTrue(property_exists($body, 'authenticated'));
$this->assertTrue(property_exists($body, 'token'));
$this->assertObjectHasProperty('authenticated', $body);
$this->assertObjectHasProperty('token', $body);

$this->assertEquals(true, $body->authenticated);
$this->assertEquals($auth->getToken(), $body->token);
Expand Down

0 comments on commit 9e165d3

Please sign in to comment.