Skip to content

[9.x] Fix consistency of assertJsonPath to act like assertSame so that expected value be first parameter #38856

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/Illuminate/Testing/AssertableJsonString.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ public function assertMissingExact(array $data)
/**
* Assert that the expected value and type exists at the given path in the response.
*
* @param string $path
* @param mixed $expect
* @param string $path
* @return $this
*/
public function assertPath($path, $expect)
public function assertPath($expect, $path)
{
PHPUnit::assertSame($expect, $this->json($path));

Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,13 +704,13 @@ public function assertJson($value, $strict = false)
/**
* Assert that the expected value and type exists at the given path in the response.
*
* @param string $path
* @param mixed $expect
* @param string $path
* @return $this
*/
public function assertJsonPath($path, $expect)
public function assertJsonPath($expect, $path)
{
$this->decodeResponseJson()->assertPath($path, $expect);
$this->decodeResponseJson()->assertPath($expect, $path);

return $this;
}
Expand Down
30 changes: 15 additions & 15 deletions tests/Testing/TestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -765,33 +765,33 @@ public function testAssertJsonPath()
{
$response = TestResponse::fromBaseResponse(new Response(new JsonSerializableSingleResourceStub));

$response->assertJsonPath('0.foo', 'foo 0');
$response->assertJsonPath('foo 0', '0.foo');

$response->assertJsonPath('0.foo', 'foo 0');
$response->assertJsonPath('0.bar', 'bar 0');
$response->assertJsonPath('0.foobar', 'foobar 0');
$response->assertJsonPath('foo 0', '0.foo');
$response->assertJsonPath('bar 0', '0.bar');
$response->assertJsonPath('foobar 0', '0.foobar');

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

$response->assertJsonPath('foo', 'bar');
$response->assertJsonPath('bar', 'foo');

$response->assertJsonPath('foobar.foobar_foo', 'foo');
$response->assertJsonPath('foobar.foobar_bar', 'bar');
$response->assertJsonPath('foo', 'foobar.foobar_foo');
$response->assertJsonPath('bar', 'foobar.foobar_bar');

$response->assertJsonPath('foobar.foobar_foo', 'foo')->assertJsonPath('foobar.foobar_bar', 'bar');
$response->assertJsonPath('foo', 'foobar.foobar_foo')->assertJsonPath('bar', 'foobar.foobar_bar');

$response->assertJsonPath('bars', [
$response->assertJsonPath([
['bar' => 'foo 0', 'foo' => 'bar 0'],
['bar' => 'foo 1', 'foo' => 'bar 1'],
['bar' => 'foo 2', 'foo' => 'bar 2'],
]);
$response->assertJsonPath('bars.0', ['bar' => 'foo 0', 'foo' => 'bar 0']);
], 'bars');
$response->assertJsonPath(['bar' => 'foo 0', 'foo' => 'bar 0'], 'bars.0');

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

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

public function testAssertJsonPathCanFail()
Expand All @@ -801,7 +801,7 @@ public function testAssertJsonPathCanFail()

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

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

public function testAssertJsonFragment()
Expand Down