Skip to content

Commit

Permalink
Add Psr6NullModule
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Nov 6, 2021
1 parent 13a5e8b commit 39a1259
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/Psr6NullModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Ray\PsrCacheModule;

use Psr\Cache\CacheItemPoolInterface;
use Ray\Di\AbstractModule;
use Ray\Di\Scope;
use Ray\PsrCacheModule\Annotation\Local;
use Ray\PsrCacheModule\Annotation\Shared;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\NullAdapter;

final class Psr6NullModule extends AbstractModule
{
protected function configure(): void
{
$this->bind(CacheItemPoolInterface::class)->annotatedWith(Local::class)->to(NullAdapter::class)->in(Scope::SINGLETON);
$this->bind(CacheItemPoolInterface::class)->annotatedWith(Shared::class)->to(NullAdapter::class)->in(Scope::SINGLETON);
}
}
14 changes: 12 additions & 2 deletions tests/Psr6CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@
namespace Ray\PsrCacheModule;

use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemPoolInterface;
use Ray\Di\AbstractModule;
use Ray\Di\Injector;
use Ray\PsrCacheModule\Annotation\CacheDir;
use Ray\PsrCacheModule\Annotation\Shared;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\NullAdapter;

class Psr6CacheTest extends TestCase
{
public function testDevPsrCacheModule(): void
{
$module = new Psr6ArrayModule();
$this->assertInstanceOf(AbstractModule::class, $module);
$cache = (new Injector(new Psr6NullModule()))->getInstance(CacheItemPoolInterface::class, Shared::class);
$this->assertInstanceOf(NullAdapter::class, $cache);
}

public function testArrayCacheModule(): void
{
$cache = (new Injector(new Psr6ArrayModule()))->getInstance(CacheItemPoolInterface::class, Shared::class);
$this->assertInstanceOf(ArrayAdapter::class, $cache);
}

public function testCacheDirModule(): void
Expand Down

0 comments on commit 39a1259

Please sign in to comment.