1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace RoaveTest\DoctrineSimpleCache\Exception; |
5
|
|
|
|
6
|
|
|
use Doctrine\Common\Cache\Cache as DoctrineCache; |
7
|
|
|
use Psr\SimpleCache\CacheException as PsrCacheException; |
8
|
|
|
use Roave\DoctrineSimpleCache\Exception\CacheException; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers \Roave\DoctrineSimpleCache\CacheException |
12
|
|
|
*/ |
13
|
|
|
final class CacheExceptionTest extends \PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
View Code Duplication |
public function testFromNonClearableCache() |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
/** @var DoctrineCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
18
|
|
|
$doctrineCache = $this->createMock(DoctrineCache::class); |
19
|
|
|
|
20
|
|
|
$exception = CacheException::fromNonClearableCache($doctrineCache); |
|
|
|
|
21
|
|
|
|
22
|
|
|
self::assertInstanceOf(CacheException::class, $exception); |
23
|
|
|
self::assertInstanceOf(PsrCacheException::class, $exception); |
24
|
|
|
|
25
|
|
|
self::assertStringMatchesFormat( |
26
|
|
|
'The given cache %s was not clearable, but you tried to use a feature that requires a clearable cache.', |
27
|
|
|
$exception->getMessage() |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
public function testFromNonMultiGetCache() |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
/** @var DoctrineCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
34
|
|
|
$doctrineCache = $this->createMock(DoctrineCache::class); |
35
|
|
|
|
36
|
|
|
$exception = CacheException::fromNonMultiGetCache($doctrineCache); |
|
|
|
|
37
|
|
|
|
38
|
|
|
self::assertInstanceOf(CacheException::class, $exception); |
39
|
|
|
self::assertInstanceOf(PsrCacheException::class, $exception); |
40
|
|
|
|
41
|
|
|
self::assertStringMatchesFormat( |
42
|
|
|
'The given cache %s cannot multi-get, but you tried to use a feature that requires a multi-get cache.', |
43
|
|
|
$exception->getMessage() |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
public function testFromNonMultiPutCache() |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
/** @var DoctrineCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
50
|
|
|
$doctrineCache = $this->createMock(DoctrineCache::class); |
51
|
|
|
|
52
|
|
|
$exception = CacheException::fromNonMultiPutCache($doctrineCache); |
|
|
|
|
53
|
|
|
|
54
|
|
|
self::assertInstanceOf(CacheException::class, $exception); |
55
|
|
|
self::assertInstanceOf(PsrCacheException::class, $exception); |
56
|
|
|
|
57
|
|
|
self::assertStringMatchesFormat( |
58
|
|
|
'The given cache %s cannot multi-put, but you tried to use a feature that requires a multi-put cache.', |
59
|
|
|
$exception->getMessage() |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.