From bc16782c9f7553f411ed678c256a957717188022 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 8566b24c4035..c796e3e82efd 100644 --- a/src/Illuminate/Testing/TestResponse.php +++ b/src/Illuminate/Testing/TestResponse.php @@ -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; } From f3f60f0a3e72edf4d6a49ffbfe9c5444805e3f36 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 a5090dae9790..1c18b29328e2 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 c467fbc4e0f5e6123fbd8aa8a436cc189aa3c77b 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 1c18b29328e2..7603b37cd55f 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 8ca27997953a397e2c67f0c2d19981740dfdd6bb 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 7603b37cd55f..242be05006e7 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'],