1
0
Fork 0
mirror of synced 2024-06-25 17:50:38 +12:00

Add unit tests for storage library

This commit is contained in:
Eldad Fux 2019-12-26 19:25:59 +02:00
parent 7705ec661d
commit a9a9b379dc
3 changed files with 105 additions and 0 deletions

View 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);
}
}

View 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);
}
}

View 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);
}
}