Skip to content

Commit

Permalink
Resolved #24, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dusta committed Dec 17, 2018
1 parent d5b4099 commit 5fdf083
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"autoload-dev": {
"psr-4": {
"Dframe\\FileStorage\\Tests\\": "tests/"
"Dframe\\FileStorage\\Tests\\": "tests"
}
},
"scripts": {
Expand Down
7 changes: 5 additions & 2 deletions tests/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<?php
$autoloader = include dirname(__DIR__) . '/vendor/autoload.php';
$autoloader->addPsr4('Dframe\\FileStorage\\tests\\', __DIR__);

require_once __DIR__ . '/../vendor/autoload.php';

define('APP_NAME', 'Dframe');
define('APP_DIR', __DIR__.'/');
63 changes: 63 additions & 0 deletions tests/FakeDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Dframe\FileStorage\Tests;

use Dframe\FileStorage\Drivers\DatabaseDriverInterface;

/**
* Class FakeDriver
*
* @package Dframe\FileStorage\Tests
*/
class FakeDriver implements DatabaseDriverInterface
{
/**
* @param $adapter
* @param $path
* @param bool $cache
*
* @return mixed
*/
public function get($adapter, $path, $cache = false)
{
// TODO: Implement get() method.
}

/**
* @param $adapter
* @param $path
* @param $mine
* @param $stream
*
* @return mixed
*/
public function put($adapter, $path, $mine, $stream)
{
// TODO: Implement put() method.
}

/**
* @param $adapter
* @param $originalId
* @param $path
* @param $mine
* @param $stream
*
* @return mixed
*/
public function cache($adapter, $originalId, $path, $mine, $stream)
{
// TODO: Implement cache() method.
}

/**
* @param $adapter
* @param $path
*
* @return mixed
*/
public function drop($adapter, $path)
{
// TODO: Implement drop() method.
}
}
52 changes: 52 additions & 0 deletions tests/FileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Dframe\FileStorage\Tests;

use Dframe\FileStorage\Storage;
use League\Flysystem\Filesystem;
use PHPUnit\Framework\TestCase;

/**
* Class FileTests
*
* @package Dframe\FileStorage\Tests
*/
class FileTest extends TestCase
{

/** @var Storage */
protected $Storage;

public function setUp()
{
clearstatcache();
$fs = new \League\Flysystem\Adapter\Local(__DIR__ . '/');
$fs->deleteDir('files');
$fs->createDir('files', new \League\Flysystem\Config());
$fs->write('file.txt', 'contents', new \League\Flysystem\Config());
$local = new Filesystem($fs);

$driver = new FakeDriver();
$config = [
'pluginsDir' => __DIR__ . '/plugins',
'adapters' => [
'local' => $local,
]
];

$this->Storage = new Storage($driver, $config);
}

public function testHas()
{

$this->assertTrue($this->Storage->getManager()->has('local://file.txt'));
}

public function testPut()
{
$put = $this->Storage->put('local', __DIR__ . '/file.txt', 'files/file.txt');
$this->assertTrue($put['return']);
}

}
7 changes: 0 additions & 7 deletions tests/FileTests.php

This file was deleted.

11 changes: 3 additions & 8 deletions tests/SetupTest.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<?php
namespace Dframe\FileStorage\tests;
namespace Dframe\FileStorage\Tests;

ini_set('session.use_cookies', 0);

// backward compatibility
if (!class_exists('\PHPUnit\Framework\TestCase') and class_exists('\PHPUnit_Framework_TestCase')) {
class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');
}
use PHPUnit\Framework\TestCase;

/**
* Class SetupTest
*
* @package Dframe\FileStorage\tests
*/
class SetupTest extends \PHPUnit\Framework\TestCase
class SetupTest extends TestCase
{
public function setUp()
{
Expand Down
1 change: 1 addition & 0 deletions tests/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contents

0 comments on commit 5fdf083

Please sign in to comment.