Skip to content

Commit

Permalink
phpcs fixes, add some missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mike42 committed Feb 23, 2019
1 parent c6ed41a commit 6d5c679
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Mike42/GfxPhp/Codec/Gif/GifGraphicsBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public static function fromBin(DataInputStream $in) : GifGraphicsBlock
}
while ($blockId == GifData::GIF_EXTENSION && $extensionId != GifData::GIF_EXTENSION_PLAINTEXT) {
// We would need a slight re-structure to record these blocks correctly.
if($extensionId == GifData::GIF_EXTENSION_APPLICATION) {
if ($extensionId == GifData::GIF_EXTENSION_APPLICATION) {
// ImageMagick drops an 'application' block here, which we can discard (gfx-php does not use it at this stage)
GifApplicationExt::fromBin($in);
} else if($extensionId == GifData::GIF_EXTENSION_COMMENT) {
} else if ($extensionId == GifData::GIF_EXTENSION_COMMENT) {
// Also GIMP places a 'comment' block here.
GifCommentExt::fromBin($in);
} else {
Expand Down
77 changes: 77 additions & 0 deletions test/integration/SmallFileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

use Mike42\GfxPhp\Image;
use PHPUnit\Framework\TestCase;

class SmallFileTest extends TestCase
{
function loadImage(string $filename) {
$img = Image::fromFile(__DIR__ . "/../resources/small-files/$filename");
return $img -> toBlackAndWhite();
}

function testWhite() {
$expected = " \n";
$width = 1;
$height = 1;
foreach(['canvas_white.gif', 'canvas_white.png'] as $fn) { // Also jpg and bmp
$img = $this -> loadImage($fn);
$this -> assertEquals($expected, $img -> toString());
$this -> assertEquals($height, $img -> getHeight());
$this -> assertEquals($width, $img -> getWidth());
}
}

function testBlack() {
$expected = "\n";
$width = 1;
$height = 1;
foreach(['canvas_black.gif', 'canvas_black.png'] as $fn) { // Also jpg and bmp
$img = $this -> loadImage($fn);
$this -> assertEquals($expected, $img -> toString());
$this -> assertEquals($height, $img -> getHeight());
$this -> assertEquals($width, $img -> getWidth());
}
}

function testBlackWhite() {
$expected = "▀▀\n";
$width = 2;
$height = 2;
foreach(['black_white.gif', 'black_white.png'] as $fn) { // Also jpg and bmp
$img = $this -> loadImage($fn);
$this -> assertEquals($expected, $img -> toString());
$this -> assertEquals($height, $img -> getHeight());
$this -> assertEquals($width, $img -> getWidth());
}
}

function testBlackTransparent() {
$expected = "▀▀\n";
$width = 2;
$height = 2;
foreach(['black_transparent.gif', 'black_transparent.png'] as $fn) { // Also jpg and bmp
$img = $this -> loadImage($fn);
$this -> assertEquals($expected, $img -> toString());
$this -> assertEquals($height, $img -> getHeight());
$this -> assertEquals($width, $img -> getWidth());
}
}

function testBlackWhiteTall() {
$expected = "██\n" .
"██\n" .
"██\n" .
"██\n" .
" \n" .
" \n" .
" \n" .
" \n";
$width = 2;
$height = 16;
$img = $this -> loadImage('black_white_tall.png');
$this -> assertEquals($expected, $img -> toString());
$this -> assertEquals($height, $img -> getHeight());
$this -> assertEquals($width, $img -> getWidth());
}
}
12 changes: 12 additions & 0 deletions test/unit/ImageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use Mike42\GfxPhp\Image;
use PHPUnit\Framework\TestCase;

class ImageTest extends TestCase
{
public function testBadFilename() {
$this -> expectException(Exception::class);
Image::fromFile("not a real file");
}
}

0 comments on commit 6d5c679

Please sign in to comment.