From bde405ecc59682f81fdc23b7a56fe15a7965f163 Mon Sep 17 00:00:00 2001 From: Sascha Schimke Date: Thu, 8 Sep 2016 11:33:33 +0200 Subject: [PATCH] Recursive comparison for "response should contain json" --- src/Context/WebApiContext.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Context/WebApiContext.php b/src/Context/WebApiContext.php index fa008df..198bde5 100644 --- a/src/Context/WebApiContext.php +++ b/src/Context/WebApiContext.php @@ -278,11 +278,7 @@ public function theResponseShouldContainJson(PyStringNode $jsonString) ); } - Assertions::assertGreaterThanOrEqual(count($etalon), count($actual)); - foreach ($etalon as $key => $needle) { - Assertions::assertArrayHasKey($key, $actual); - Assertions::assertEquals($etalon[$key], $actual[$key]); - } + $this->compareArrays($etalon, $actual); } /** @@ -408,4 +404,22 @@ private function getClient() return $this->client; } + + /** + * @param array $etalon + * @param array $actual + */ + private function compareArrays(array $etalon, array $actual) + { + Assertions::assertGreaterThanOrEqual(count($etalon), count($actual)); + foreach ($etalon as $key => $needle) { + Assertions::assertArrayHasKey($key, $actual); + + if (is_array($needle)) { + $this->compareArrays($etalon[$key], $actual[$key]); + } else { + Assertions::assertEquals($etalon[$key], $actual[$key]); + } + } + } }