Completed
Push — master ( 6c409f...23b86d )
by James
11s
created

InvalidArgumentExceptionTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 85.71 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 24
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testFromKeyAndInvalidTTLObject() 12 12 1
A testFromKeyAndInvalidTTLNonObject() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
declare(strict_types = 1);
3
4
namespace RoaveTest\DoctrineSimpleCache\Exception;
5
6
use Roave\DoctrineSimpleCache\Exception\InvalidArgumentException;
7
8
/**
9
 * @covers \Roave\DoctrineSimpleCache\Exception\InvalidArgumentException
10
 */
11
final class InvalidArgumentExceptionTest extends \PHPUnit_Framework_TestCase
12
{
13 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...
14
    {
15
        $invalidTTL = new \stdClass();
16
        $exception = InvalidArgumentException::fromKeyAndInvalidTTL('key', $invalidTTL);
17
        self::assertInstanceOf(InvalidArgumentException::class, $exception);
18
        self::assertInstanceOf(\Psr\SimpleCache\InvalidArgumentException::class, $exception);
19
20
        self::assertStringMatchesFormat(
21
            'TTL for "%s" should be defined by an integer or a DateInterval, but stdClass is given.',
22
            $exception->getMessage()
23
        );
24
    }
25
26 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...
27
    {
28
        $invalidTTL = random_int(100, 200);
29
        $exception = InvalidArgumentException::fromKeyAndInvalidTTL('key', $invalidTTL);
30
        self::assertInstanceOf(InvalidArgumentException::class, $exception);
31
        self::assertInstanceOf(\Psr\SimpleCache\InvalidArgumentException::class, $exception);
32
33
        self::assertStringMatchesFormat(
34
            'TTL for "%s" should be defined by an integer or a DateInterval, but integer is given.',
35
            $exception->getMessage()
36
        );
37
    }
38
}
39