From 6a546c9f67ff86fc432566a854bef3982269a3f0 Mon Sep 17 00:00:00 2001 From: Ahmed Helal Ahmed Date: Sat, 18 Sep 2021 13:41:29 +0200 Subject: [PATCH 1/4] Fix consistency of assertJsonPath to act like assertSame so that expected value be first parameter - Fix consistency to be like assertSame the expected to be first parameter - Similar to assertJsonCount with provide expected first --- src/Illuminate/Testing/AssertableJsonString.php | 4 ++-- src/Illuminate/Testing/TestResponse.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Testing/AssertableJsonString.php b/src/Illuminate/Testing/AssertableJsonString.php index 1964a7c5ce7c..584360b2c3c4 100644 --- a/src/Illuminate/Testing/AssertableJsonString.php +++ b/src/Illuminate/Testing/AssertableJsonString.php @@ -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)); diff --git a/src/Illuminate/Testing/TestResponse.php b/src/Illuminate/Testing/TestResponse.php index 2770f1b60794..35895082b7ea 100644 --- a/src/Illuminate/Testing/TestResponse.php +++ b/src/Illuminate/Testing/TestResponse.php @@ -687,13 +687,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; } From f2ec3ac12706361753254765349383a60fd03802 Mon Sep 17 00:00:00 2001 From: Ahmed Helal Ahmed Date: Sat, 18 Sep 2021 14:05:29 +0200 Subject: [PATCH 2/4] Fix test for testAssertJsonPathCanFail and testAssertJsonPath --- tests/Testing/TestResponseTest.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index 6d14cd4b660a..9cca4682f213 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -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() @@ -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() From 4f9c5ad1ae0f79e1499cececca5774e6db655a46 Mon Sep 17 00:00:00 2001 From: Ahmed Helal Ahmed Date: Sat, 18 Sep 2021 14:15:33 +0200 Subject: [PATCH 3/4] Fix style --- tests/Testing/TestResponseTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index 9cca4682f213..796f47bbea5e 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -778,14 +778,14 @@ public function testAssertJsonPath() $response->assertJsonPath('foo', 'foobar.foobar_foo'); $response->assertJsonPath('bar', 'foobar.foobar_bar'); - $response->assertJsonPath( 'foo', 'foobar.foobar_foo')->assertJsonPath( 'bar','foobar.foobar_bar'); + $response->assertJsonPath('foo', 'foobar.foobar_foo')->assertJsonPath('bar','foobar.foobar_bar'); $response->assertJsonPath([ ['bar' => 'foo 0', 'foo' => 'bar 0'], ['bar' => 'foo 1', 'foo' => 'bar 1'], ['bar' => 'foo 2', 'foo' => 'bar 2'], ], 'bars'); - $response->assertJsonPath(['bar' => 'foo 0', 'foo' => 'bar 0'], 'bars.0'); + $response->assertJsonPath(['bar' => 'foo 0', 'foo' => 'bar 0'], 'bars.0'); $response = TestResponse::fromBaseResponse(new Response(new JsonSerializableSingleResourceWithIntegersStub)); From 8a45fe133820ea82833aabe61df5ad9119a41c19 Mon Sep 17 00:00:00 2001 From: Ahmed Helal Ahmed Date: Sat, 18 Sep 2021 14:17:18 +0200 Subject: [PATCH 4/4] Fix style --- tests/Testing/TestResponseTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index 796f47bbea5e..ce123c43dd2b 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -778,7 +778,7 @@ public function testAssertJsonPath() $response->assertJsonPath('foo', 'foobar.foobar_foo'); $response->assertJsonPath('bar', 'foobar.foobar_bar'); - $response->assertJsonPath('foo', 'foobar.foobar_foo')->assertJsonPath('bar','foobar.foobar_bar'); + $response->assertJsonPath('foo', 'foobar.foobar_foo')->assertJsonPath('bar', 'foobar.foobar_bar'); $response->assertJsonPath([ ['bar' => 'foo 0', 'foo' => 'bar 0'],