Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved #24, Add phpunit #25

Merged
merged 2 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 0 additions & 2 deletions src/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,13 @@ public function isAllowedFileType($file, $extensions)
finfo_close($finfo);

if (isset($extensions[$extension])) {

if (!is_array($extensions[$extension])) {
$extensions[$extension] = [$extensions[$extension]];
}

if (in_array($mime, $extensions[$extension])) {
return true;
}

}

return false;
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.
}
}
50 changes: 50 additions & 0 deletions tests/FileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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