Completed
Push — http_cache_mvc ( 5374b9 )
by
unknown
27:11
created

ResponseCacheConfiguratorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 60.32 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 38
loc 63
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testEnableCache() 0 12 1
A testSetSharedMaxAge() 12 12 1
A testSetSharedMaxAgeNoReplace() 13 13 1
A testSetSharedMaxAgeReplace() 13 13 1
A testAddCacheTags() 0 6 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
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
7
namespace eZ\Publish\Core\MVC\Symfony\Cache\Tests\Http;
8
9
use eZ\Publish\Core\MVC\Symfony\Cache\Http\ResponseCacheConfigurator;
10
use PHPUnit_Framework_TestCase;
11
use Symfony\Component\HttpFoundation\Response;
12
13
class ResponseCacheConfiguratorTest extends PHPUnit_Framework_TestCase
14
{
15
    public function testEnableCache()
16
    {
17
        $configurator = new ResponseCacheConfigurator();
18
19
        $response = new Response();
20
        $configurator->enableCache($response);
21
22
        self::assertEquals(
23
            'public',
24
            $response->headers->get('cache-control')
25
        );
26
    }
27
28 View Code Duplication
    public function testSetSharedMaxAge()
29
    {
30
        $configurator = new ResponseCacheConfigurator();
31
32
        $response = new Response();
33
        $configurator->setSharedMaxAge($response, 30);
34
35
        self::assertEquals(
36
            30,
37
            $response->headers->getCacheControlDirective('s-maxage')
38
        );
39
    }
40
41 View Code Duplication
    public function testSetSharedMaxAgeNoReplace()
42
    {
43
        $configurator = new ResponseCacheConfigurator();
44
45
        $response = new Response();
46
        $configurator->setSharedMaxAge($response, 30);
47
        $configurator->setSharedMaxAge($response, 60);
48
49
        self::assertEquals(
50
            30,
51
            $response->headers->getCacheControlDirective('s-maxage')
52
        );
53
    }
54
55 View Code Duplication
    public function testSetSharedMaxAgeReplace()
56
    {
57
        $configurator = new ResponseCacheConfigurator();
58
59
        $response = new Response();
60
        $configurator->setSharedMaxAge($response, 30);
61
        $configurator->setSharedMaxAge($response, 60, true);
62
63
        self::assertEquals(
64
            60,
65
            $response->headers->getCacheControlDirective('s-maxage')
66
        );
67
    }
68
69
    public function testAddCacheTags()
70
    {
71
        $configurator = new ResponseCacheConfigurator();
0 ignored issues
show
Unused Code introduced by
$configurator is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
72
73
        $response = new Response();
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
74
    }
75
}
76