mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2024-03-22 13:10:41 +08:00
introduced property based unit tests using the eris library, found an unhandled error case (empty string) in the Vizhash library and handled it
This commit is contained in:
parent
db307c3a77
commit
59adfc1962
|
@ -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": {
|
||||
|
|
|
@ -80,7 +80,7 @@ class Vizhash16x16
|
|||
*/
|
||||
public function generate($text)
|
||||
{
|
||||
if (!function_exists('gd_info')) {
|
||||
if (!function_exists('gd_info') || strlen($text) < 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user