Completed
Push — master ( fc3afa...aedcee )
by Marco
8s
created

CacheExceptionTest::testFromNonClearableCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 1
eloc 8
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\CacheException
12
 */
13
final class CacheExceptionTest extends \PHPUnit_Framework_TestCase
14
{
15 View Code Duplication
    public function testFromNonClearableCache()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
16
    {
17
        /** @var DoctrineCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */
18
        $doctrineCache = $this->createMock(DoctrineCache::class);
19
20
        $exception = CacheException::fromNonClearableCache($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...fromNonClearableCache() 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 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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
32
    {
33
        /** @var DoctrineCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */
34
        $doctrineCache = $this->createMock(DoctrineCache::class);
35
36
        $exception = CacheException::fromNonMultiGetCache($doctrineCache);
0 ignored issues
show
Bug introduced by
It seems like $doctrineCache defined by $this->createMock(\Doctr...mon\Cache\Cache::class) on line 34 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Roave\DoctrineSimpleCach...:fromNonMultiGetCache() 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...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
48
    {
49
        /** @var DoctrineCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */
50
        $doctrineCache = $this->createMock(DoctrineCache::class);
51
52
        $exception = CacheException::fromNonMultiPutCache($doctrineCache);
0 ignored issues
show
Bug introduced by
It seems like $doctrineCache defined by $this->createMock(\Doctr...mon\Cache\Cache::class) on line 50 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Roave\DoctrineSimpleCach...:fromNonMultiPutCache() 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...
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