Completed
Pull Request — master (#22)
by James
03:22
created

testFromNonMultiOperationCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
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\Exception\CacheException
12
 */
13
final class CacheExceptionTest extends \PHPUnit_Framework_TestCase
14
{
15
    public function testFromNonMultiOperationCache()
16
    {
17
        /** @var DoctrineCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */
18
        $doctrineCache = $this->createMock(DoctrineCache::class);
19
20
        $exception = CacheException::fromNonMultiOperationCache($doctrineCache);
0 ignored issues
show
Bug introduced by
It seems like $doctrineCache defined by $this->createMock(\Doctr...mon\Cache\Cache::class) on line 18 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Roave\DoctrineSimpleCach...onMultiOperationCache() does only seem to accept object<Doctrine\Common\Cache\Cache>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
21
22
        self::assertInstanceOf(CacheException::class, $exception);
23
        self::assertInstanceOf(PsrCacheException::class, $exception);
24
25
        self::assertStringMatchesFormat(
26
            'The given cache %s does not support multiple operations, '
27
            . 'but you tried to use a feature that requires a multi-operation cache.',
28
            $exception->getMessage()
29
        );
30
    }
31
}
32