diff --git a/composer.json b/composer.json index b92f462..789c8eb 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ }, "require-dev": { "codacy/coverage": "dev-master", - "codeclimate/php-test-reporter": "dev-master" + "codeclimate/php-test-reporter": "dev-master", + "giorgiosironi/eris": "dev-master" }, "autoload": { "psr-4": { diff --git a/lib/Vizhash16x16.php b/lib/Vizhash16x16.php index 604c86e..44eb885 100644 --- a/lib/Vizhash16x16.php +++ b/lib/Vizhash16x16.php @@ -80,7 +80,7 @@ class Vizhash16x16 */ public function generate($text) { - if (!function_exists('gd_info')) { + if (!function_exists('gd_info') || strlen($text) < 1) { return ''; } diff --git a/tst/README.md b/tst/README.md index 76e69ee..9d7320c 100644 --- a/tst/README.md +++ b/tst/README.md @@ -6,11 +6,12 @@ and its dependencies: * phpunit * php-gd * php-sqlite3 -* php-xdebug (for code coverage reports) +* php-curl (optional, for codeclimate test reporter) +* php-xdebug (optional, for code coverage reports) Example for Debian and Ubuntu: ```console -$ sudo apt install phpunit php-gd php-sqlite php-xdebug +$ sudo apt install phpunit php-gd php-sqlite php-curl php-xdebug ``` To run the tests, just change into this directory and run phpunit: diff --git a/tst/Vizhash16x16Test.php b/tst/Vizhash16x16Test.php index afcda56..417d092 100644 --- a/tst/Vizhash16x16Test.php +++ b/tst/Vizhash16x16Test.php @@ -2,9 +2,12 @@ use PrivateBin\Persistence\ServerSalt; use PrivateBin\Vizhash16x16; +use Eris\Generator; class Vizhash16x16Test extends PHPUnit_Framework_TestCase { + use Eris\TestTrait; + private $_file; private $_path; @@ -27,6 +30,35 @@ class Vizhash16x16Test extends PHPUnit_Framework_TestCase Helper::rmDir($this->_path); } + public function testVizhashGeneratesPngs() + { + $this->forAll( + Generator\string(), + Generator\string() + )->then( + function ($string1, $string2) + { + $vz = new Vizhash16x16(); + $pngdata = $vz->generate($string1); + + if (empty($string1)) + { + $this->assertEquals($pngdata, ''); + } else { + $this->assertNotEquals($pngdata, ''); + file_put_contents($this->_file, $pngdata); + $finfo = new finfo(FILEINFO_MIME_TYPE); + $this->assertEquals('image/png', $finfo->file($this->_file)); + if ($string1 !== $string2) + { + $this->assertNotEquals($pngdata, $string2); + } + } + $this->assertEquals($pngdata, $vz->generate($string1)); + } + ); + } + public function testVizhashGeneratesUniquePngsPerIp() { $vz = new Vizhash16x16();