From f1636d3b8ee25eacc9796933417d894a6e159967 Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Thu, 12 Oct 2017 19:04:58 +0200 Subject: [PATCH] Make it compatible with PHPUnit 6 --- composer.json | 2 +- src/Context/WebApiContext.php | 35 ++++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 49e4dc2..5bec52c 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": ">=5.6", "behat/behat": "~3.0", "guzzlehttp/guzzle": "4 - 6", - "phpunit/phpunit": "4 - 5" + "phpunit/phpunit": "4 - 6" }, "require-dev": { diff --git a/src/Context/WebApiContext.php b/src/Context/WebApiContext.php index fa008df..97b1231 100644 --- a/src/Context/WebApiContext.php +++ b/src/Context/WebApiContext.php @@ -15,6 +15,7 @@ use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Request; +use PHPUnit\Framework\Assert; use PHPUnit_Framework_Assert as Assertions; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -219,7 +220,11 @@ public function theResponseCodeShouldBe($code) { $expected = intval($code); $actual = intval($this->response->getStatusCode()); - Assertions::assertSame($expected, $actual); + if (class_exists(Assert::class)) { + Assert::assertSame($expected, $actual); + } else { + Assertions::assertSame($expected, $actual); + } } /** @@ -233,7 +238,11 @@ public function theResponseShouldContain($text) { $expectedRegexp = '/' . preg_quote($text) . '/i'; $actual = (string) $this->response->getBody(); - Assertions::assertRegExp($expectedRegexp, $actual); + if (class_exists(Assert::class)) { + Assert::assertRegExp($expectedRegexp, $actual); + } else { + Assertions::assertRegExp($expectedRegexp, $actual); + } } /** @@ -247,7 +256,11 @@ public function theResponseShouldNotContain($text) { $expectedRegexp = '/' . preg_quote($text) . '/'; $actual = (string) $this->response->getBody(); - Assertions::assertNotRegExp($expectedRegexp, $actual); + if (class_exists(Assert::class)) { + Assert::assertNotRegExp($expectedRegexp, $actual); + } else { + Assertions::assertNotRegExp($expectedRegexp, $actual); + } } /** @@ -278,10 +291,18 @@ 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]); + if (class_exists(Assert::class)) { + Assert::assertGreaterThanOrEqual(count($etalon), count($actual)); + foreach ($etalon as $key => $needle) { + Assert::assertArrayHasKey($key, $actual); + Assert::assertEquals($etalon[$key], $actual[$key]); + } + } else { + Assertions::assertGreaterThanOrEqual(count($etalon), count($actual)); + foreach ($etalon as $key => $needle) { + Assertions::assertArrayHasKey($key, $actual); + Assertions::assertEquals($etalon[$key], $actual[$key]); + } } }