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

StreamControllerTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 98
Duplicated Lines 46.94 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 9
dl 46
loc 98
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testIndex() 0 26 1
A testGetAtom() 15 15 1
A testGetRss() 15 15 1
A testGetJson() 16 16 1
A testNotFound() 0 6 1
A testBadProvider() 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
namespace Debril\RssAtomBundle\Tests\Controller;
4
5
use FeedIo\Reader\Document;
6
use FeedIo\Rule\DateTimeBuilder;
7
use FeedIo\Standard\Atom;
8
use FeedIo\Standard\Json;
9
use FeedIo\Standard\Rss;
10
use Psr\Log\NullLogger;
11
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
12
13
/**
14
 * Class StreamControllerTest.
15
 */
16
class StreamControllerTest extends WebTestCase
17
{
18
    public function testIndex()
19
    {
20
        $client = static::createClient();
21
22
        $client->request('GET', '/mock/rss/id');
23
24
        $response = $client->getResponse();
25
        $this->assertEquals('200', $response->getStatusCode());
26
        $lastModified = $response->getLastModified();
27
28
        $lastModified->setTimezone(
29
            new \DateTimeZone(date_default_timezone_get())
30
        );
31
32
        $lastModified->add(new \DateInterval('PT10S'));
33
        $this->assertInstanceOf('\DateTime', $lastModified);
34
        $this->assertGreaterThan(0, $response->getMaxAge());
35
        $this->assertGreaterThan(0, strlen($response->getContent()));
36
        $this->assertTrue($response->isCacheable());
37
38
        $client->request('GET', '/mock/rss/id', array(), array(), array('HTTP_If-Modified-Since' => $lastModified->format(\DateTime::RSS)));
39
        $response2 = $client->getResponse();
40
41
        $this->assertEquals('304', $response2->getStatusCode());
42
        $this->assertEquals(0, strlen($response2->getContent()));
43
    }
44
45 View Code Duplication
    public function testGetAtom()
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...
46
    {
47
        $client = static::createClient();
48
49
        $client->request('GET', '/atom/1');
50
51
        $response = $client->getResponse();
52
        $this->assertEquals('200', $response->getStatusCode());
53
        $this->assertEquals('application/xhtml+xml', $response->headers->get('content-type'));
54
55
        $atom = new Document($response->getContent());
56
57
        $standard = new Atom(new DateTimeBuilder(new NullLogger()));
58
        $this->assertTrue($standard->canHandle($atom));
59
    }
60
61 View Code Duplication
    public function testGetRss()
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...
62
    {
63
        $client = static::createClient();
64
65
        $client->request('GET', '/rss/1');
66
67
        $response = $client->getResponse();
68
        $this->assertEquals('200', $response->getStatusCode());
69
        $this->assertEquals('application/xhtml+xml', $response->headers->get('content-type'));
70
71
        $rss = new Document($response->getContent());
72
73
        $standard = new Rss(new DateTimeBuilder(new NullLogger()));
74
        $this->assertTrue($standard->canHandle($rss));
75
    }
76
77 View Code Duplication
    public function testGetJson()
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
        $client = static::createClient();
80
81
        $client->request('GET', '/json/1');
82
83
        $response = $client->getResponse();
84
85
        $this->assertEquals('200', $response->getStatusCode());
86
        $this->assertEquals('application/json', $response->headers->get('content-type'));
87
88
        $json = new Document($response->getContent());
89
90
        $standard = new Json(new DateTimeBuilder(new NullLogger()));
91
        $this->assertTrue($standard->canHandle($json));
92
    }
93
94
    /**
95
     * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
96
     */
97
    public function testNotFound()
98
    {
99
        $client = static::createClient();
100
101
        $client->request('GET', '/mock/rss/not-found');
102
    }
103
104
    /**
105
     * @expectedException \Exception
106
     */
107
    public function testBadProvider()
108
    {
109
        $client = static::createClient();
110
111
        $client->request('GET', '/bad/provider');
112
    }
113
}
114