From fdf4fb83dfe0de88d584fb324fc5aa351b9770a4 Mon Sep 17 00:00:00 2001 From: Juha Remes Date: Tue, 29 Mar 2016 14:07:08 +0100 Subject: [PATCH 1/4] Added Lorempixel check for ImageTest.php --- test/Faker/Provider/ImageTest.php | 36 ++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/test/Faker/Provider/ImageTest.php b/test/Faker/Provider/ImageTest.php index 0535d4daa7..34f7af0917 100644 --- a/test/Faker/Provider/ImageTest.php +++ b/test/Faker/Provider/ImageTest.php @@ -45,18 +45,30 @@ public function testUrlWithDimensionsAndBadCategory() public function testDownloadWithDefaults() { - $file = Image::image(sys_get_temp_dir()); - $this->assertFileExists($file); - if (function_exists('getimagesize')) { - list($width, $height, $type, $attr) = getimagesize($file); - $this->assertEquals(640, $width); - $this->assertEquals(480, $height); - $this->assertEquals(constant('IMAGETYPE_JPEG'), $type); - } else { - $this->assertEquals('jpg', pathinfo($file, PATHINFO_EXTENSION)); - } - if (file_exists($file)) { - unlink($file); + $url = "http://www.lorempixel.com/"; + $curlPing = curl_init($url); + curl_setopt($curlPing, CURLOPT_TIMEOUT, 5); + curl_setopt($curlPing, CURLOPT_CONNECTTIMEOUT, 5); + curl_setopt($curlPing, CURLOPT_RETURNTRANSFER, true); + $data = curl_exec($curlPing); + $httpCode = curl_getinfo($curlPing, CURLINFO_HTTP_CODE); + curl_close($curlPing); + + if ($httpCode >= 200 && $httpCode < 300) + { + $file = Image::image(sys_get_temp_dir()); + $this->assertFileExists($file); + if (function_exists('getimagesize')) { + list($width, $height, $type, $attr) = getimagesize($file); + $this->assertEquals(640, $width); + $this->assertEquals(480, $height); + $this->assertEquals(constant('IMAGETYPE_JPEG'), $type); + } else { + $this->assertEquals('jpg', pathinfo($file, PATHINFO_EXTENSION)); + } + if (file_exists($file)) { + unlink($file); + } } } } From 9a1f69deaf8842ba6ab8c41c2b9684ad23095a9e Mon Sep 17 00:00:00 2001 From: Juha Remes Date: Tue, 29 Mar 2016 16:16:07 +0100 Subject: [PATCH 2/4] Reversed the logic --- test/Faker/Provider/ImageTest.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/test/Faker/Provider/ImageTest.php b/test/Faker/Provider/ImageTest.php index 34f7af0917..46e4380b89 100644 --- a/test/Faker/Provider/ImageTest.php +++ b/test/Faker/Provider/ImageTest.php @@ -54,21 +54,23 @@ public function testDownloadWithDefaults() $httpCode = curl_getinfo($curlPing, CURLINFO_HTTP_CODE); curl_close($curlPing); - if ($httpCode >= 200 && $httpCode < 300) + if ($httpCode < 200 | $httpCode > 300) { - $file = Image::image(sys_get_temp_dir()); - $this->assertFileExists($file); - if (function_exists('getimagesize')) { - list($width, $height, $type, $attr) = getimagesize($file); - $this->assertEquals(640, $width); - $this->assertEquals(480, $height); - $this->assertEquals(constant('IMAGETYPE_JPEG'), $type); - } else { - $this->assertEquals('jpg', pathinfo($file, PATHINFO_EXTENSION)); - } - if (file_exists($file)) { - unlink($file); - } + $this->markTestSkipped("LoremPixel is offline, skipping image download"); + } + + $file = Image::image(sys_get_temp_dir()); + $this->assertFileExists($file); + if (function_exists('getimagesize')) { + list($width, $height, $type, $attr) = getimagesize($file); + $this->assertEquals(640, $width); + $this->assertEquals(480, $height); + $this->assertEquals(constant('IMAGETYPE_JPEG'), $type); + } else { + $this->assertEquals('jpg', pathinfo($file, PATHINFO_EXTENSION)); + } + if (file_exists($file)) { + unlink($file); } } } From c053915d20b367dec8f77fb5f4657804865ca913 Mon Sep 17 00:00:00 2001 From: Juha Remes Date: Tue, 29 Mar 2016 16:26:38 +0100 Subject: [PATCH 3/4] Added comments --- test/Faker/Provider/ImageTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/Faker/Provider/ImageTest.php b/test/Faker/Provider/ImageTest.php index 46e4380b89..da9ca338ab 100644 --- a/test/Faker/Provider/ImageTest.php +++ b/test/Faker/Provider/ImageTest.php @@ -54,6 +54,9 @@ public function testDownloadWithDefaults() $httpCode = curl_getinfo($curlPing, CURLINFO_HTTP_CODE); curl_close($curlPing); + /** + * If HTTP response is something else than 200-299, skip the test + */ if ($httpCode < 200 | $httpCode > 300) { $this->markTestSkipped("LoremPixel is offline, skipping image download"); From 5579c983071ccccc4d142dcd633cba5e9748f3b1 Mon Sep 17 00:00:00 2001 From: Juha Remes Date: Tue, 29 Mar 2016 16:42:22 +0100 Subject: [PATCH 4/4] Removed unnecessary comment, standardised brackets --- test/Faker/Provider/ImageTest.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/Faker/Provider/ImageTest.php b/test/Faker/Provider/ImageTest.php index da9ca338ab..9f68ba827a 100644 --- a/test/Faker/Provider/ImageTest.php +++ b/test/Faker/Provider/ImageTest.php @@ -54,11 +54,7 @@ public function testDownloadWithDefaults() $httpCode = curl_getinfo($curlPing, CURLINFO_HTTP_CODE); curl_close($curlPing); - /** - * If HTTP response is something else than 200-299, skip the test - */ - if ($httpCode < 200 | $httpCode > 300) - { + if ($httpCode < 200 | $httpCode > 300) { $this->markTestSkipped("LoremPixel is offline, skipping image download"); }