From a9a9b379dce79fad9ddb7dc7f09d25128d366e3e Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 26 Dec 2019 19:25:59 +0200 Subject: [PATCH] Add unit tests for storage library --- tests/unit/Storage/StorageTest.php | 42 +++++++++++++++++++ .../unit/Storage/Validators/FileNameTest.php | 33 +++++++++++++++ .../unit/Storage/Validators/FileSizeTest.php | 30 +++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 tests/unit/Storage/StorageTest.php create mode 100644 tests/unit/Storage/Validators/FileNameTest.php create mode 100644 tests/unit/Storage/Validators/FileSizeTest.php diff --git a/tests/unit/Storage/StorageTest.php b/tests/unit/Storage/StorageTest.php new file mode 100644 index 000000000..c20c91407 --- /dev/null +++ b/tests/unit/Storage/StorageTest.php @@ -0,0 +1,42 @@ +assertEquals(get_class(Storage::getDevice('disk-a')), 'Storage\Devices\Local'); + $this->assertEquals(get_class(Storage::getDevice('disk-b')), 'Storage\Devices\Local'); + + try { + get_class(Storage::getDevice('disk-c')); + $this->fail("Expected exception not thrown"); + } catch(Exception $e) { + $this->assertEquals('The device "disk-c" is not listed', $e->getMessage()); + } + } + + public function testExists() + { + $this->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 diff --git a/tests/unit/Storage/Validators/FileNameTest.php b/tests/unit/Storage/Validators/FileNameTest.php new file mode 100644 index 000000000..c22182ea9 --- /dev/null +++ b/tests/unit/Storage/Validators/FileNameTest.php @@ -0,0 +1,33 @@ +object = new FileName(); + } + + public function tearDown() + { + } + + public function testValues() + { + $this->assertEquals($this->object->isValid(''), false); + $this->assertEquals($this->object->isValid(null), false); + $this->assertEquals($this->object->isValid(false), false); + $this->assertEquals($this->object->isValid('../test'), false); + $this->assertEquals($this->object->isValid('test.png'), true); + $this->assertEquals($this->object->isValid('test'), true); + } +} \ No newline at end of file diff --git a/tests/unit/Storage/Validators/FileSizeTest.php b/tests/unit/Storage/Validators/FileSizeTest.php new file mode 100644 index 000000000..c4acd175e --- /dev/null +++ b/tests/unit/Storage/Validators/FileSizeTest.php @@ -0,0 +1,30 @@ +object = new FileSize(1000); + } + + public function tearDown() + { + } + + public function testValues() + { + $this->assertEquals($this->object->isValid(1001), false); + $this->assertEquals($this->object->isValid(1000), true); + $this->assertEquals($this->object->isValid(999), true); + } +} \ No newline at end of file