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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
|
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.