Completed
Push — master ( 23b86d...e09bdb )
by Marco
9s
created

testFromNonIterableKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace RoaveTest\DoctrineSimpleCache\Exception;
5
6
use Roave\DoctrineSimpleCache\Exception\InvalidArgumentException;
7
use Psr\SimpleCache\InvalidArgumentException as PsrInvalidArgumentException;
8
9
/**
10
 * @covers \Roave\DoctrineSimpleCache\Exception\InvalidArgumentException
11
 */
12
final class InvalidArgumentExceptionTest extends \PHPUnit_Framework_TestCase
13
{
14 View Code Duplication
    public function testFromKeyAndInvalidTTLObject()
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...
15
    {
16
        $invalidTTL = new \stdClass();
17
        $exception = InvalidArgumentException::fromKeyAndInvalidTTL('key', $invalidTTL);
18
        self::assertInstanceOf(InvalidArgumentException::class, $exception);
19
        self::assertInstanceOf(PsrInvalidArgumentException::class, $exception);
20
21
        self::assertStringMatchesFormat(
22
            'TTL for "%s" should be defined by an integer or a DateInterval, but stdClass is given.',
23
            $exception->getMessage()
24
        );
25
    }
26 View Code Duplication
    public function testFromInvalidKeyCharacters()
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...
27
    {
28
        $invalidKey = uniqid('invalidKey', true);
29
        $exception = InvalidArgumentException::fromInvalidKeyCharacters($invalidKey);
30
        self::assertInstanceOf(InvalidArgumentException::class, $exception);
31
        self::assertInstanceOf(PsrInvalidArgumentException::class, $exception);
32
        self::assertSame(
33
            sprintf(
34
                'Key "%s" is in an invalid format - must not contain characters: {}()/\@:',
35
                $invalidKey
36
            ),
37
            $exception->getMessage()
38
        );
39
    }
40
41 View Code Duplication
    public function testFromInvalidType()
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...
42
    {
43
        $invalidKey = random_int(100, 200);
44
        $exception = InvalidArgumentException::fromInvalidType($invalidKey);
45
        self::assertInstanceOf(InvalidArgumentException::class, $exception);
46
        self::assertInstanceOf(PsrInvalidArgumentException::class, $exception);
47
        self::assertSame(
48
            'Key was not a valid type. Expected string, received integer',
49
            $exception->getMessage()
50
        );
51
    }
52
53
    public function testFromEmptyKey()
54
    {
55
        $exception = InvalidArgumentException::fromEmptyKey();
56
        self::assertInstanceOf(InvalidArgumentException::class, $exception);
57
        self::assertInstanceOf(PsrInvalidArgumentException::class, $exception);
58
        self::assertSame(
59
            'Requested key was an empty string.',
60
            $exception->getMessage()
61
        );
62
    }
63
64 View Code Duplication
    public function testFromKeyAndInvalidTTLNonObject()
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...
65
    {
66
        $invalidTTL = random_int(100, 200);
67
        $exception = InvalidArgumentException::fromKeyAndInvalidTTL('key', $invalidTTL);
68
        self::assertInstanceOf(InvalidArgumentException::class, $exception);
69
        self::assertInstanceOf(\Psr\SimpleCache\InvalidArgumentException::class, $exception);
70
71
        self::assertStringMatchesFormat(
72
            'TTL for "%s" should be defined by an integer or a DateInterval, but integer is given.',
73
            $exception->getMessage()
74
        );
75
    }
76
77 View Code Duplication
    public function testFromNonIterableKeys()
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...
78
    {
79
        $invalidKey = random_int(100, 200);
80
        $exception = InvalidArgumentException::fromNonIterableKeys($invalidKey);
81
        self::assertInstanceOf(InvalidArgumentException::class, $exception);
82
        self::assertInstanceOf(PsrInvalidArgumentException::class, $exception);
83
        self::assertSame(
84
            'Keys passed were not iterable (i.e. \Traversable or array), received: integer',
85
            $exception->getMessage()
86
        );
87
    }
88
89 View Code Duplication
    public function testFromNonIterableValues()
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...
90
    {
91
        $invalidValue = random_int(100, 200);
92
        $exception = InvalidArgumentException::fromNonIterableValues($invalidValue);
93
        self::assertInstanceOf(InvalidArgumentException::class, $exception);
94
        self::assertInstanceOf(PsrInvalidArgumentException::class, $exception);
95
        self::assertSame(
96
            'Values passed were not iterable (i.e. \Traversable or array), received: integer',
97
            $exception->getMessage()
98
        );
99
    }
100
}
101