Skip to content

Commit

Permalink
Strict parameter added to assertJsonPath (#30142)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttrig authored and taylorotwell committed Oct 1, 2019
1 parent 370ee34 commit abd94c9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Illuminate/Foundation/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,16 @@ protected function assertJsonMessage(array $data)
*
* @param string $path
* @param mixed $expect
* @param bool $strict
* @return $this
*/
public function assertJsonPath($path, $expect)
public function assertJsonPath($path, $expect, $strict = false)
{
PHPUnit::assertEquals($expect, $this->json($path));
if ($strict) {
PHPUnit::assertSame($expect, $this->json($path));
} else {
PHPUnit::assertEquals($expect, $this->json($path));
}

return $this;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/Foundation/FoundationTestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,25 @@ public function testAssertJsonPath()
$response->assertJsonPath('2.id', 30);
}

public function testAssertJsonPathStrict()
{
$response = TestResponse::fromBaseResponse(new Response(new JsonSerializableSingleResourceWithIntegersStub));

$response->assertJsonPath('0.id', 10, true);
$response->assertJsonPath('1.id', 20, true);
$response->assertJsonPath('2.id', 30, true);
}

public function testAssertJsonPathStrictCanFail()
{
$this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage('Failed asserting that 10 is identical to \'10\'.');

$response = TestResponse::fromBaseResponse(new Response(new JsonSerializableSingleResourceWithIntegersStub));

$response->assertJsonPath('0.id', '10', true);
}

public function testAssertJsonFragment()
{
$response = TestResponse::fromBaseResponse(new Response(new JsonSerializableSingleResourceStub));
Expand Down

0 comments on commit abd94c9

Please sign in to comment.