1
0
Fork 0
mirror of synced 2024-06-26 10:10:57 +12:00

Added unit tests for compression library

This commit is contained in:
Eldad Fux 2019-12-27 07:50:44 +02:00
parent 1107284a5d
commit 33a07bd858
3 changed files with 108 additions and 5 deletions

View file

@ -7,11 +7,6 @@ use PHPUnit\Framework\TestCase;
class OpenSSLTest extends TestCase
{
/**
* @var Cron
*/
protected $object = null;
public function setUp()
{
}

View file

@ -0,0 +1,82 @@
<?php
namespace Appwrite\Tests;
use Exception;
use Storage\Compression\Algorithms\GZIP;
use Storage\Devices\Local;
use PHPUnit\Framework\TestCase;
class GZIPTest extends TestCase
{
/**
* @var GZIP
*/
protected $object = null;
public function setUp()
{
$this->object = new GZIP();
}
public function tearDown()
{
}
public function testName()
{
$this->assertEquals($this->object->getName(), 'gzip');
}
public function testCompressDecompressWithText()
{
$demo = 'This is a demo string';
$demoSize = mb_strlen($demo, '8bit');
$data = $this->object->compress($demo);
$dataSize = mb_strlen($data, '8bit');
$this->assertEquals($demoSize, 21);
$this->assertEquals($dataSize, 39);
$this->assertEquals($this->object->decompress($data), $demo);
}
public function testCompressDecompressWithJPGImage()
{
$demo = \file_get_contents(__DIR__ . '/../../../../resources/disk-a/kitten-1.jpg');
$demoSize = mb_strlen($demo, '8bit');
$data = $this->object->compress($demo);
$dataSize = mb_strlen($data, '8bit');
$this->assertEquals($demoSize, 599639);
$this->assertEquals($dataSize, 599107);
$this->assertGreaterThan($dataSize, $demoSize);
$data = $this->object->decompress($data);
$dataSize = mb_strlen($data, '8bit');
$this->assertEquals($dataSize, 599639);
}
public function testCompressDecompressWithPNGImage()
{
$demo = \file_get_contents(__DIR__ . '/../../../../resources/disk-b/kitten-1.png');
$demoSize = mb_strlen($demo, '8bit');
$data = $this->object->compress($demo);
$dataSize = mb_strlen($data, '8bit');
$this->assertEquals($demoSize, 3038056);
$this->assertEquals($dataSize, 3029202);
$this->assertGreaterThan($dataSize, $demoSize);
$data = $this->object->decompress($data);
$dataSize = mb_strlen($data, '8bit');
$this->assertEquals($dataSize, 3038056);
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace Appwrite\Tests;
use Exception;
use Storage\Storage;
use Storage\Devices\Local;
use PHPUnit\Framework\TestCase;
class LocalTest extends TestCase
{
public function setUp()
{
}
public function tearDown()
{
}
public function testExists()
{
$this->assertEquals(Storage::exists('disk-a'), true);
$this->assertEquals(Storage::exists('disk-b'), true);
$this->assertEquals(Storage::exists('disk-c'), false);
}
}