From 5b7a87e47144b731d8614450e1efc5357e0bf65a Mon Sep 17 00:00:00 2001 From: codisart Date: Sat, 21 Mar 2020 23:10:27 +0100 Subject: [PATCH] add all php versions on travis testing --- .travis.yml | 4 ++++ src/Client/Console.php | 12 +++++------- src/Server/Server.php | 2 +- test/api/ConfigTest.php | 2 +- test/unit/Client/HttpTest.php | 14 +++++++++++--- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index cf3ae93f..6fbb654c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ language: php php: - 7.0 + - 7.1 + - 7.2 + - 7.3 + - 7.4 cache: directories: diff --git a/src/Client/Console.php b/src/Client/Console.php index 584e6fbf..dafaf1b9 100644 --- a/src/Client/Console.php +++ b/src/Client/Console.php @@ -1,11 +1,5 @@ configPath) { $command .= " -c $this->configPath"; } - pclose(popen("$command &", 'r')); + $handler = popen("$command &", 'r'); + + // Since php 7.4, the speed of php is so fast that there is a race condition without this waiting time + \usleep(1000000); + pclose($handler); } } \ No newline at end of file diff --git a/src/Server/Server.php b/src/Server/Server.php index cacf3feb..3c5f3bb2 100644 --- a/src/Server/Server.php +++ b/src/Server/Server.php @@ -12,7 +12,7 @@ */ class Server { - const PORT = 2424; + const PORT = 2424; /** * @var Container diff --git a/test/api/ConfigTest.php b/test/api/ConfigTest.php index c21ce404..dfe88917 100644 --- a/test/api/ConfigTest.php +++ b/test/api/ConfigTest.php @@ -30,7 +30,7 @@ public function logPath() ->returnBody('{"response" :"okay"}') ->send(); - $client = new \GuzzleHttp\Client(); + $client = new \GuzzleHttp\Client(); try { $client->post('http://localhost:8081/users/2')->getBody()->getContents(); diff --git a/test/unit/Client/HttpTest.php b/test/unit/Client/HttpTest.php index 60cc7fea..54aa2a55 100644 --- a/test/unit/Client/HttpTest.php +++ b/test/unit/Client/HttpTest.php @@ -8,7 +8,6 @@ namespace Imposter\Client; - use Imposter\Common\Model\Mock; use Imposter\Common\Model\MockAbstract; use PHPUnit\Framework\TestCase; @@ -37,7 +36,8 @@ public function insertMockWithExceptions($code, $content, $withException) self::expectException(\Exception::class); } - $mock = \Mockery::mock(MockAbstract::class); + $mock = new MockAsset(8081); + $response = \Mockery::mock(\Psr\Http\Message\ResponseInterface::class); $response->shouldReceive('getBody->getContents')->andReturn($content); $response->shouldReceive('getStatusCode')->andReturn($code); @@ -46,7 +46,7 @@ public function insertMockWithExceptions($code, $content, $withException) $client->shouldReceive('post')->andReturn($response); $http = new Http($client, \Mockery::mock(Console::class)); - $returnedMock =$http->insert($mock); + $returnedMock = $http->insert($mock); self::assertInstanceOf(MockAbstract::class, $returnedMock); } @@ -226,4 +226,12 @@ public function tearDown() $this->addToAssertionCount(\Mockery::getContainer()->mockery_getExpectationCount()); \Mockery::close(); } +} + +class MockAsset extends MockAbstract +{ + public function toString(): string + { + return 'asset'; + } } \ No newline at end of file