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

StreamControllerTest::testIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
cc 1
nc 1
nop 0
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