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

[FIX] Apply cache namespace from settings #569

Merged
merged 1 commit into from
Nov 6, 2023
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 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();
}
}