Skip to content

Commit

Permalink
Make it compatible with PHPUnit 6
Browse files Browse the repository at this point in the history
  • Loading branch information
soullivaneuh committed Oct 12, 2017
1 parent f7b3a2a commit 88df57d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
35 changes: 28 additions & 7 deletions src/Context/WebApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

/**
Expand All @@ -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);
}
}

/**
Expand All @@ -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);
}
}

/**
Expand Down Expand Up @@ -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]);
}
}
}

Expand Down

0 comments on commit 88df57d

Please sign in to comment.