Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Added Lorempixel check for ImageTest.php #866

Merged
merged 4 commits into from
Mar 29, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions test/Faker/Provider/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you reverse the logic:

if ($httpCode < 200 || $httpCode > 300) {
   $this-> markTestSkipped('LoremPixel is offline, skipping image download');
  return;
}

cf. http://refactoring.com/catalog/replaceNestedConditionalWithGuardClauses.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, this can be done.

{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you move the opening brace to the previous line? That's the standard used across Faker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just clean up the rest of the PR. Do we need squashing the commits or is this OK on it's own?

$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);
}
}
}
}