Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Westin Shafer committed May 17, 2017
1 parent 555dffc commit afa46f6
Show file tree
Hide file tree
Showing 12 changed files with 601 additions and 18 deletions.
3 changes: 3 additions & 0 deletions phpunit.xml
Expand Up @@ -2,6 +2,9 @@
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">Exception</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
7 changes: 1 addition & 6 deletions src/Adaptor/LocalAdaptorFactory.php
Expand Up @@ -15,11 +15,6 @@ public function __invoke(array $options)
$linkHandling = $options['linkBehavior'] ?? Local::DISALLOW_LINKS;
$permissions = $options['permissions'] ?? [];

return new Local(
$root,
$writeFlags,
$linkHandling,
$permissions
);
return new Local($root, $writeFlags, $linkHandling, $permissions);
}
}
31 changes: 25 additions & 6 deletions src/Config/MainConfig.php
Expand Up @@ -49,27 +49,46 @@ public function validateConfig($config)
}
}

public function getFileSystemConfig($fileSystem) : FileSystemConfig {
/**
* @param $fileSystem
* @return FileSystemConfig|null
*/
public function getFileSystemConfig($fileSystem)
{
return $this->fileSystems[$fileSystem] ?? null;
}

public function getAdaptorConfig($adaptor) : AdaptorConfig {
/**
* @param $adaptor
* @return AdaptorConfig|null
*/
public function getAdaptorConfig($adaptor)
{
return $this->adaptors[$adaptor] ?? null;
}

public function getCacheConfig($cache) : CacheConfig {
/**
* @param $cache
*
* @return CacheConfig|null
*/
public function getCacheConfig($cache)
{
return $this->cache[$cache] ?? null;
}

public function hasFileSystemConfig($fileSystem) : bool {
public function hasFileSystemConfig($fileSystem) : bool
{
return key_exists($fileSystem, $this->fileSystems);
}

public function hasAdaptorConfig($adaptor) : bool {
public function hasAdaptorConfig($adaptor) : bool
{
return key_exists($adaptor, $this->adaptors);
}

public function hasCacheConfig($cache) : bool {
public function hasCacheConfig($cache) : bool
{
return key_exists($cache, $this->cache);
}

Expand Down
10 changes: 4 additions & 6 deletions src/Service/AdaptorManager.php
Expand Up @@ -41,7 +41,6 @@ public function __construct(

/**
* @param string $id
*
* @return AdapterInterface
*/
public function get($id)
Expand All @@ -63,13 +62,12 @@ public function get($id)
return $this->adaptors[$id];
}

/**
* @param string $id
* @return bool
*/
public function has($id)
{
return $this->config->hasAdaptorConfig($id);
}

public function getConfig()
{
return $this->config;
}
}
7 changes: 7 additions & 0 deletions src/Service/CacheManager.php
Expand Up @@ -6,6 +6,7 @@
use League\Flysystem\Cached\CacheInterface;
use Psr\Container\ContainerInterface;
use WShafer\PSR11FlySystem\Config\MainConfig;
use WShafer\PSR11FlySystem\Exception\UnknownCacheException;
use WShafer\PSR11FlySystem\MapperInterface;

class CacheManager implements ContainerInterface
Expand Down Expand Up @@ -41,6 +42,12 @@ public function __construct(
*/
public function get($id)
{
if (!$this->has($id)) {
throw new UnknownCacheException(
'Unable to locate cache '.$id.'. Please check your configuration.'
);
}

$cacheConfig = $this->getConfig()->getCacheConfig($id);
return $this->cacheMapper->get(
$cacheConfig->getType(),
Expand Down
1 change: 1 addition & 0 deletions tests/Config/AdaptorConfigTest.php
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace WShafer\PSR11FlySystem\Test\Config;

Expand Down
1 change: 1 addition & 0 deletions tests/Config/CacheConfigTest.php
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace WShafer\PSR11FlySystem\Test\Config;

Expand Down
1 change: 1 addition & 0 deletions tests/Config/FileSystemConfigTest.php
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace WShafer\PSR11FlySystem\Test\Config;

Expand Down
76 changes: 76 additions & 0 deletions tests/Config/MainConfigFactoryTest.php
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);

namespace WShafer\PSR11FlySystem\Test\Config;

use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use WShafer\PSR11FlySystem\Config\MainConfig;
use WShafer\PSR11FlySystem\Config\MainConfigFactory;

/**
* @covers \WShafer\PSR11FlySystem\Config\MainConfigFactory
*/
class MainConfigFactoryTest extends TestCase
{
public function testInvoke()
{
$config = [
'flysystem' => [
'adaptors' => [
'adaptorOne' => [
'type' => 'null',
'options' => [],
],

'adaptorTwo' => [
'type' => 'null',
'options' => [],
],
],

'caches' => [
'cacheOne' => [
'type' => 'memory',
'options' => [],
],

'cacheTwo' => [
'type' => 'memory',
'options' => [],
],
],

'fileSystems' => [
'one' => [
'adaptor' => 'adaptorOne',
'cache' => 'cacheOne',
'plugins' => []
],

'two' => [
'adaptor' => 'adaptorTwo',
'cache' => 'cacheTwo',
'plugins' => []
]
],
],
];

/** @var ContainerInterface|\PHPUnit_Framework_MockObject_MockObject $container */
$container = $this->createMock(ContainerInterface::class);
$container->expects($this->once())
->method('get')
->with('config')
->willReturn($config);

$container->expects($this->once())
->method('has')
->with('config')
->willReturn(true);

$factory = new MainConfigFactory();
$mainConfig = $factory($container);
$this->assertInstanceOf(MainConfig::class, $mainConfig);
}
}

0 comments on commit afa46f6

Please sign in to comment.