From e9e8acc1aec9ac22468cad3a50577f6d45237930 Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Thu, 12 Oct 2017 19:04:26 +0200 Subject: [PATCH 1/5] Require at least PHP 5.6 PHP 5.4 and 5.5 are not maintained anymore. --- .travis.yml | 2 -- composer.json | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b5c0d14..ab1cea1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: php php: - - 5.4 - - 5.5 - 5.6 - 7.0 - hhvm diff --git a/composer.json b/composer.json index fd79253..49e4dc2 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { - "php": ">=5.4", + "php": ">=5.6", "behat/behat": "~3.0", "guzzlehttp/guzzle": "4 - 6", "phpunit/phpunit": "4 - 5" From f7b3a2adcb0b026b719ba35f7cde713f9cdb3fe4 Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Thu, 12 Oct 2017 19:12:47 +0200 Subject: [PATCH 2/5] Add PHP 7.1 on Travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ab1cea1..f092c23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: php php: - 5.6 - 7.0 + - 7.1 - hhvm matrix: From d0161fa6d33374313bde6ef4f6ac637066dbe756 Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Thu, 12 Oct 2017 19:26:45 +0200 Subject: [PATCH 3/5] Change tmp directory name generation logic The old one throws notices on PHP 7. --- features/bootstrap/FeatureContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 37dc500..9ac56af 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -44,7 +44,7 @@ public static function cleanTestFolders() public function prepareScenario() { $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'behat-web-api' . DIRECTORY_SEPARATOR . - md5(microtime() * rand(0, 10000)); + md5(uniqid(rand(0, 10000))); mkdir($dir . '/features/bootstrap', 0777, true); From 12eda35f88a0b633d565c5f51ab2e73da6f8a559 Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Thu, 12 Oct 2017 19:04:58 +0200 Subject: [PATCH 4/5] Make it compatible with PHPUnit 6 --- composer.json | 2 +- features/bootstrap/FeatureContext.php | 19 ++++++++++++--- features/context.feature | 7 +++++- src/Context/WebApiContext.php | 35 +++++++++++++++++++++------ 4 files changed, 51 insertions(+), 12 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/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 9ac56af..2205899 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/features/context.feature b/features/context.feature index 368ceca..5d5fcc3 100644 --- a/features/context.feature +++ b/features/context.feature @@ -10,6 +10,7 @@ Feature: client aware context use Behat\WebApiExtension\Context\ApiClientAwareContext; use GuzzleHttp\ClientInterface; + use PHPUnit\Framework\Assert; class FeatureContext implements ApiClientAwareContext { @@ -24,7 +25,11 @@ Feature: client aware context * @Then /^the client should be set$/ */ public function theClientShouldBeSet() { - PHPUnit_Framework_Assert::assertInstanceOf('GuzzleHttp\Client', $this->client); + if (class_exists(Assert::class)) { + Assert::assertInstanceOf('GuzzleHttp\Client', $this->client); + } else { + PHPUnit_Framework_Assert::assertInstanceOf('GuzzleHttp\Client', $this->client); + } } } """ 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]); + } } } From e2f702e29cabb1df7a01c83c61d467792c44ced0 Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Thu, 12 Oct 2017 19:04:58 +0200 Subject: [PATCH 5/5] Make it compatible with PHPUnit 6 --- bin/start_server.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/start_server.sh b/bin/start_server.sh index 990c3f8..0f579c6 100755 --- a/bin/start_server.sh +++ b/bin/start_server.sh @@ -34,7 +34,7 @@ http { root $TRAVIS_BUILD_DIR/testapp; location / { - fastcgi_pass 127.0.0.1:9000; + fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME \$document_root/index.php; include /etc/nginx/fastcgi_params; @@ -43,7 +43,7 @@ http { } CONF echo " Starting the HHVM daemon" - hhvm --mode server -vServer.Type=fastcgi -vServer.IP='127.0.0.1' -vServer.Port=9000 > "$TRAVIS_BUILD_DIR/server.log" 2>&1 & + hhvm --mode server -vServer.Type=fastcgi -vServer.IP='127.0.0.1' -vServer.Port=9001 > "$TRAVIS_BUILD_DIR/server.log" 2>&1 & echo " Starting nginx" sudo mkdir -p /var/log/nginx/ sudo nginx -c "$TRAVIS_BUILD_DIR/.nginx.conf"