diff --git a/.travis.yml b/.travis.yml index 7e1486d..28df844 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ sudo: false before_script: - composer install + - php -S localhost:8000 -t tests/ script: - vendor/bin/phpunit diff --git a/tests/DataTest.php b/tests/DataTest.php index a4ada48..4d096fd 100644 --- a/tests/DataTest.php +++ b/tests/DataTest.php @@ -129,13 +129,17 @@ public function testBuildFromFile() */ public function testBuildFromUrlShouldThrowFileNotFoundException() { - $url = 'http://via.placeholder.com/x150.png'; + $this->skipIfLocalWebServerDown(); + + $url = 'http://localhost:8000/unknown.png'; Data::buildFromUrl($url); } public function testBuildFromUrl() { - $url = 'http://via.placeholder.com/350x150.png'; + $this->skipIfLocalWebServerDown(); + + $url = 'http://localhost:8000/smile.png'; $dataURI = Data::buildFromUrl($url); $this->assertInstanceOf('DataURI\Data', $dataURI); $this->assertEquals('image/png', $dataURI->getMimeType()); @@ -185,4 +189,21 @@ private function createEmptyFile($filename) fwrite($handle, ''); fclose($handle); } + + private function skipIfLocalWebServerDown() + { + $url = 'http://localhost:8000/'; + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_HEADER, true); + curl_setopt($ch, CURLOPT_NOBODY, true); + curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); + curl_setopt($ch, CURLOPT_TIMEOUT,10); + curl_exec($ch); + $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if (0 === $httpcode) { + $this->markTestSkipped('The local web server is down. Run it with `php -S localhost:8000 -t tests/`.'); + } + } }