1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace KochTest\Feed; |
4
|
|
|
|
5
|
|
|
use Koch\Feed\Feed; |
6
|
|
|
|
7
|
|
|
class FeedTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
// path to valid rss feed |
10
|
|
|
public $feedUrl = ''; |
11
|
|
|
|
12
|
|
|
public $cacheFile = ''; |
13
|
|
|
|
14
|
|
|
public function setUp() |
15
|
|
|
{ |
16
|
|
|
if (!class_exists('SimplePie')) { |
17
|
|
|
$this->markTestSkipped('This test requires the vendor dependency "SimplePie".'); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
// valid rss feed online source |
21
|
|
|
#$this->feed_url = 'http://groups.google.com/group/clansuite/feed/rss_v2_0_msgs.xml'; |
|
|
|
|
22
|
|
|
$this->feedUrl = __DIR__ . '/fixtures/clansuite_rss_v2_0_msgs.xml';# |
23
|
|
|
|
24
|
|
|
$this->cacheFolder = __DIR__ . '/fixtures/'; |
|
|
|
|
25
|
|
|
$this->cacheFile = $this->cacheFolder . md5($this->feedUrl); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @covers Koch\Feed\Feed::fetchRSS |
30
|
|
|
*/ |
31
|
|
|
public function testMethodFetchRSS() |
32
|
|
|
{ |
33
|
|
|
$simplepie_feed_object = Feed::fetchRSS($this->feedUrl); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$this->assertInstanceOf('SimplePie', $simplepie_feed_object); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @covers Koch\Feed\Feed::fetchRawRSS |
40
|
|
|
*/ |
41
|
|
|
public function testMethodFetchRawRSSWithoutCaching() |
42
|
|
|
{ |
43
|
|
|
// read feed |
44
|
|
|
$feedcontent = Feed::fetchRawRSS($this->feedUrl, false); |
45
|
|
|
$this->assertContains('title>clansuite.com Google Group</title>', $feedcontent); |
46
|
|
|
|
47
|
|
|
// return null, if feed not found |
48
|
|
|
$feedcontent = Feed::fetchRawRSS('non-existant-feed-URL', false); |
49
|
|
|
$this->assertNull($feedcontent); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @covers Koch\Feed\Feed::fetchRawRSS |
54
|
|
|
*/ |
55
|
|
|
public function testMethodFetchRawRSSWithCaching() |
56
|
|
|
{ |
57
|
|
|
// fetch and cache |
58
|
|
|
$feedcontent = Feed::fetchRawRSS($this->feedUrl, true, $this->cacheFolder); |
59
|
|
|
// check for cache file |
60
|
|
|
$this->assertFileExists($this->cacheFile); |
61
|
|
|
// check for content |
62
|
|
|
$this->assertContains('title>clansuite.com Google Group</title>', $feedcontent); |
63
|
|
|
|
64
|
|
|
// fetch from cache |
65
|
|
|
$feedcontent = Feed::fetchRawRSS($this->feedUrl, true, $this->cacheFolder); |
66
|
|
|
$this->assertContains('title>clansuite.com Google Group</title>', $feedcontent); |
67
|
|
|
|
68
|
|
|
if (is_file($this->cacheFile)) { |
69
|
|
|
unlink($this->cacheFile); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// re-create cache - fetch and cache |
73
|
|
|
$feedcontent = Feed::fetchRawRSS($this->feedUrl, true, $this->cacheFolder); |
|
|
|
|
74
|
|
|
// check for cache file |
75
|
|
|
$this->assertFileExists($this->cacheFile); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.