Skip to content

Commit

Permalink
Apply cache namespace from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kayzer committed Nov 6, 2023
1 parent 1789dac commit cbc53da
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Configuration/Cache/IlluminateCacheProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function resolve(array $settings = []): CacheItemPoolInterface
trigger_error('Using driver "' . $this->store . '" with a custom store is deprecated. Please use the "illuminate" driver.', E_USER_DEPRECATED);
}

return new Psr16Adapter($this->cache->store($store));
return new Psr16Adapter($this->cache->store($store), $settings['namespace'] ?? '');
}

public function getStore(): string
Expand Down
64 changes: 64 additions & 0 deletions tests/Configuration/Cache/IlluminateCacheProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Configuration\Cache;

use Illuminate\Contracts\Cache\Factory;
use Illuminate\Contracts\Cache\Repository;
use LaravelDoctrine\ORM\Configuration\Cache\IlluminateCacheProvider;
use Mockery as m;
use PHPUnit\Framework\TestCase;

class IlluminateCacheProviderTest extends TestCase
{
/**
* @var IlluminateCacheProvider
*/
private $driver;

/**
* @var Repository|m\LegacyMockInterface|m\MockInterface
*/
private $repository;

protected function setUp(): void
{
parent::setUp();

$this->repository = m::mock(Repository::class);
$manager = m::mock(Factory::class);
$manager->shouldReceive('store')
->once()
->andReturn($this->repository);

$this->driver = new IlluminateCacheProvider($manager);
}

public function test_driver_returns_provided_namespace(): void
{
$this->repository->shouldReceive('getMultiple')
->withSomeOfArgs(['namespace_item'])
->once();

$cache = $this->driver->resolve(['store' => 'redis', 'namespace' => 'namespace']);
$cache->getItem('item');

$this->assertTrue(true);
}

public function test_driver_has_no_namespace_by_default(): void
{
$this->repository->shouldReceive('getMultiple')
->withSomeOfArgs(['item'])
->once();

$cache = $this->driver->resolve(['store' => 'redis']);
$cache->getItem('item');

$this->assertTrue(true);
}

public function tearDown(): void
{
m::close();
}
}

0 comments on commit cbc53da

Please sign in to comment.