From 0f170dbfe1ebdfcb9a54f74891c38bdc1d5b807d Mon Sep 17 00:00:00 2001 From: Marcel Hernandez Date: Tue, 23 Feb 2016 00:35:27 +0100 Subject: [PATCH 1/2] PHPUnit dependency removal --- composer.json | 2 +- features/bootstrap/FeatureContext.php | 6 +++--- features/context.feature | 3 ++- src/Context/WebApiContext.php | 23 ++++++++++++++++------- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 48d3658..399fda1 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": ">=5.4", "behat/behat": "~3.0", "guzzlehttp/guzzle": "4 - 5", - "phpunit/phpunit": "4 - 5" + "beberlei/assert": "^2.4" }, "require-dev": { diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 37dc500..800752d 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -119,7 +119,7 @@ public function itShouldPassWith($success, PyStringNode $text) */ public function theOutputShouldContain(PyStringNode $text) { - PHPUnit_Framework_Assert::assertContains($this->getExpectedOutput($text), $this->getOutput()); + \Assert\Assertion::contains($this->getOutput(), $this->getExpectedOutput($text)); } private function getExpectedOutput(PyStringNode $expectedText) @@ -162,13 +162,13 @@ public function itShouldFail($success) echo 'Actual output:' . PHP_EOL . PHP_EOL . $this->getOutput(); } - PHPUnit_Framework_Assert::assertNotEquals(0, $this->getExitCode()); + \Assert\Assertion::notSame($this->getExitCode(), 0); } else { if (0 !== $this->getExitCode()) { echo 'Actual output:' . PHP_EOL . PHP_EOL . $this->getOutput(); } - PHPUnit_Framework_Assert::assertEquals(0, $this->getExitCode()); + \Assert\Assertion::same($this->getExitCode(), 0); } } diff --git a/features/context.feature b/features/context.feature index 368ceca..635233d 100644 --- a/features/context.feature +++ b/features/context.feature @@ -8,6 +8,7 @@ Feature: client aware context """ client); + Assertion::isInstanceOf($this->client, ClientInterface::class); } } """ diff --git a/src/Context/WebApiContext.php b/src/Context/WebApiContext.php index f21b24b..de918f0 100644 --- a/src/Context/WebApiContext.php +++ b/src/Context/WebApiContext.php @@ -10,11 +10,12 @@ namespace Behat\WebApiExtension\Context; +use Assert\Assertion; +use Assert\InvalidArgumentException; use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\RequestException; -use PHPUnit_Framework_Assert as Assertions; /** * Provides web API description definitions. @@ -196,7 +197,7 @@ public function theResponseCodeShouldBe($code) { $expected = intval($code); $actual = intval($this->response->getStatusCode()); - Assertions::assertSame($expected, $actual); + Assertion::same($actual, $expected); } /** @@ -210,7 +211,7 @@ public function theResponseShouldContain($text) { $expectedRegexp = '/' . preg_quote($text) . '/i'; $actual = (string) $this->response->getBody(); - Assertions::assertRegExp($expectedRegexp, $actual); + Assertion::regex($actual, $expectedRegexp); } /** @@ -224,7 +225,15 @@ public function theResponseShouldNotContain($text) { $expectedRegexp = '/' . preg_quote($text) . '/'; $actual = (string) $this->response->getBody(); - Assertions::assertNotRegExp($expectedRegexp, $actual); + + try { + Assertion::regex($actual, $expectedRegexp); + } catch (InvalidArgumentException $e) { + return; + } + + $message = sprintf('Value "%s" matches expression.', $actual); + throw new InvalidArgumentException($message, Assertion::INVALID_REGEX, null, $actual, ['pattern' => $expectedRegexp]); } /** @@ -249,10 +258,10 @@ public function theResponseShouldContainJson(PyStringNode $jsonString) ); } - Assertions::assertGreaterThanOrEqual(count($etalon), count($actual)); + Assertion::greaterOrEqualThan(count($actual), count($etalon)); foreach ($etalon as $key => $needle) { - Assertions::assertArrayHasKey($key, $actual); - Assertions::assertEquals($etalon[$key], $actual[$key]); + Assertion::keyExists($actual, $key); + Assertion::eq($actual[$key], $etalon[$key]); } } From 8e28374e7727bb43b1ac8d088793dabdf92c1652 Mon Sep 17 00:00:00 2001 From: Marcel Hernandez Date: Tue, 23 Feb 2016 00:52:45 +0100 Subject: [PATCH 2/2] Class name resolution via ::class is a PHP 5.5 feature, since the library supports PHP 5.4 it cannot be used. --- features/context.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/context.feature b/features/context.feature index 635233d..ac0a8bc 100644 --- a/features/context.feature +++ b/features/context.feature @@ -25,7 +25,7 @@ Feature: client aware context * @Then /^the client should be set$/ */ public function theClientShouldBeSet() { - Assertion::isInstanceOf($this->client, ClientInterface::class); + Assertion::isInstanceOf($this->client, 'GuzzleHttp\ClientInterface'); } } """