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/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 37dc500..db301c3 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -2,6 +2,7 @@ use Behat\Behat\Context\SnippetAcceptingContext; use Behat\Gherkin\Node\PyStringNode; +use PHPUnit\Framework\Assert; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; @@ -119,7 +120,11 @@ public function itShouldPassWith($success, PyStringNode $text) */ public function theOutputShouldContain(PyStringNode $text) { - PHPUnit_Framework_Assert::assertContains($this->getExpectedOutput($text), $this->getOutput()); + if (class_exists(Assert::class)) { + Assert::assertContains($this->getExpectedOutput($text), $this->getOutput()); + } else { + PHPUnit_Framework_Assert::assertContains($this->getExpectedOutput($text), $this->getOutput()); + } } private function getExpectedOutput(PyStringNode $expectedText) @@ -162,13 +167,21 @@ public function itShouldFail($success) echo 'Actual output:' . PHP_EOL . PHP_EOL . $this->getOutput(); } - PHPUnit_Framework_Assert::assertNotEquals(0, $this->getExitCode()); + if (class_exists(Assert::class)) { + Assert::assertNotEquals(0, $this->getExitCode()); + } else { + PHPUnit_Framework_Assert::assertNotEquals(0, $this->getExitCode()); + } } else { if (0 !== $this->getExitCode()) { echo 'Actual output:' . PHP_EOL . PHP_EOL . $this->getOutput(); } - PHPUnit_Framework_Assert::assertEquals(0, $this->getExitCode()); + if (class_exists(Assert::class)) { + Assert::assertEquals(0, $this->getExitCode()); + } else { + PHPUnit_Framework_Assert::assertEquals(0, $this->getExitCode()); + } } } 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]); + } } }