Completed
Pull Request — master (#203)
by Alister
09:00
created

ModifiedSinceTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 82.35 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 6
dl 42
loc 51
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetValue() 11 11 1
A testGetBadValue() 10 10 1
A testGetEmptyArrayValue() 10 10 1
A testGetValueInArray() 11 11 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
namespace Debril\RssAtomBundle\Tests\Request;
4
5
use Debril\RssAtomBundle\Request\ModifiedSince;
6
use PHPUnit\Framework\TestCase;
7
use Psr\Log\NullLogger;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\RequestStack;
10
11
class ModifiedSinceTest extends TestCase
12
{
13
14 View Code Duplication
    public function testGetValue()
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
        $stack = new RequestStack();
17
        $request = new Request();
18
        $date = new \DateTime('2018-06-01');
19
        $request->headers->set('If-Modified-Since', $date->format(\DATE_RSS));
20
        $stack->push($request);
21
22
        $modifiedSince = new ModifiedSince($stack, new NullLogger());
23
        $this->assertEquals($date, $modifiedSince->getValue());
24
    }
25
26 View Code Duplication
    public function testGetBadValue()
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
        $stack = new RequestStack();
29
        $request = new Request();
30
        $request->headers->set('If-Modified-Since', 'something that is not a date');
31
        $stack->push($request);
32
33
        $modifiedSince = new ModifiedSince($stack, new NullLogger());
34
        $this->assertInstanceOf('\DateTime', $modifiedSince->getValue());
35
    }
36
37 View Code Duplication
    public function testGetEmptyArrayValue()
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...
38
    {
39
        $stack = new RequestStack();
40
        $request = new Request();
41
        $request->headers->set('If-Modified-Since', array());
42
        $stack->push($request);
43
44
        $modifiedSince = new ModifiedSince($stack, new NullLogger());
45
        $this->assertInstanceOf('\DateTime', $modifiedSince->getValue());
46
    }
47
48
49 View Code Duplication
    public function testGetValueInArray()
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...
50
    {
51
        $stack = new RequestStack();
52
        $request = new Request();
53
        $date = new \DateTime('2018-06-01');
54
        $request->headers->set('If-Modified-Since', [$date->format(\DATE_RSS)]);
55
        $stack->push($request);
56
57
        $modifiedSince = new ModifiedSince($stack, new NullLogger());
58
        $this->assertEquals($date, $modifiedSince->getValue());
59
    }
60
61
}
62