Add unit tests for storage library
This commit is contained in:
parent
7705ec661d
commit
a9a9b379dc
3 changed files with 105 additions and 0 deletions
42
tests/unit/Storage/StorageTest.php
Normal file
42
tests/unit/Storage/StorageTest.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Tests;
|
||||
|
||||
use Exception;
|
||||
use Storage\Storage;
|
||||
use Storage\Devices\Local;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
Storage::addDevice('disk-a', new Local(__DIR__ . '../../resources/disk-a'));
|
||||
Storage::addDevice('disk-b', new Local(__DIR__ . '../../resources/disk-b'));
|
||||
|
||||
class StorageTest extends TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
public function testGetters()
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
33
tests/unit/Storage/Validators/FileNameTest.php
Normal file
33
tests/unit/Storage/Validators/FileNameTest.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Tests;
|
||||
|
||||
use Storage\Validators\FileName;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FileNameTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var FileName
|
||||
*/
|
||||
protected $object = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
30
tests/unit/Storage/Validators/FileSizeTest.php
Normal file
30
tests/unit/Storage/Validators/FileSizeTest.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Tests;
|
||||
|
||||
use Storage\Validators\FileSize;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FileSizeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var FileSize
|
||||
*/
|
||||
protected $object = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue