From 33a07bd858e3e5d5a51253e59def378e45d58e44 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 27 Dec 2019 07:50:44 +0200 Subject: [PATCH] Added unit tests for compression library --- tests/unit/OpenSSL/OpenSSLTest.php | 5 -- .../Compression/Algorithms/GZIPTest.php | 82 +++++++++++++++++++ tests/unit/Storage/Devices/LocalTest.php | 26 ++++++ 3 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 tests/unit/Storage/Compression/Algorithms/GZIPTest.php create mode 100644 tests/unit/Storage/Devices/LocalTest.php diff --git a/tests/unit/OpenSSL/OpenSSLTest.php b/tests/unit/OpenSSL/OpenSSLTest.php index 8497f6cc19..e08889f989 100644 --- a/tests/unit/OpenSSL/OpenSSLTest.php +++ b/tests/unit/OpenSSL/OpenSSLTest.php @@ -7,11 +7,6 @@ use PHPUnit\Framework\TestCase; class OpenSSLTest extends TestCase { - /** - * @var Cron - */ - protected $object = null; - public function setUp() { } diff --git a/tests/unit/Storage/Compression/Algorithms/GZIPTest.php b/tests/unit/Storage/Compression/Algorithms/GZIPTest.php new file mode 100644 index 0000000000..0083307afd --- /dev/null +++ b/tests/unit/Storage/Compression/Algorithms/GZIPTest.php @@ -0,0 +1,82 @@ +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); + } +} \ No newline at end of file diff --git a/tests/unit/Storage/Devices/LocalTest.php b/tests/unit/Storage/Devices/LocalTest.php new file mode 100644 index 0000000000..7692ce21e0 --- /dev/null +++ b/tests/unit/Storage/Devices/LocalTest.php @@ -0,0 +1,26 @@ +assertEquals(Storage::exists('disk-a'), true); + $this->assertEquals(Storage::exists('disk-b'), true); + $this->assertEquals(Storage::exists('disk-c'), false); + } +} \ No newline at end of file