1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* A test class for testing RSSFeed class |
4
|
|
|
* |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Miax\RSSFeed; |
8
|
|
|
use SimplePie; |
9
|
|
|
define('CACHE', __DIR__.'/../webroot/cache/'); |
10
|
|
|
require_once(__DIR__."/simplepie/simplepie_1.3.1.mini.php"); |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class CRSSFeedTest extends \PHPUnit_Framework_TestCase { |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** ------------------------------------------------------- |
17
|
|
|
* Test 1 |
18
|
|
|
* |
19
|
|
|
*/ |
20
|
|
|
/*public function testGetFeed(){ |
|
|
|
|
21
|
|
|
$feed = new \Miax\RSSFeed\CRSSFeed('test'); |
22
|
|
|
$res = $el['name']; |
23
|
|
|
$exp = 'test'; |
24
|
|
|
$this->assertEquals($res, $exp, "Created element name missmatch."); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
/** --------------------------------------------------------- |
30
|
|
|
* Test 2 Mock of SimplePie |
31
|
|
|
* |
32
|
|
|
*/ |
33
|
|
|
|
34
|
|
|
//private $rss; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/*public function setUp(){ |
|
|
|
|
38
|
|
|
$feed = new SimplePie(); |
39
|
|
|
$feed = getFeed('http://feeds.feedburner.com/idg/vzzs/'); |
40
|
|
|
$rss = new Miax\RSSFeed\CRSSFeed($feed); |
41
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function tearDown(){ |
45
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testCorrectFeed() { |
49
|
|
|
$this->assertTrue( |
50
|
|
|
$this->rss->getFeed('http://feeds.feedburner.com/idg/vzzs/'), |
51
|
|
|
"Expecting successful result" |
52
|
|
|
); echo setVerboseErrorHandler(); |
53
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testFalseFeed(){ |
57
|
|
|
$feed = $this->getMock("SimplePie"); |
58
|
|
|
$this->rss = new Miax\RSSFeed\CRSSFeed($feed); |
59
|
|
|
->method('get_items') |
60
|
|
|
->with($this->equalTo('/../webroot/cache/','http://feeds.feedburner.com/idg/vzzs/', 3600)); |
61
|
|
|
|
62
|
|
|
$feed->expects($this->once()) |
63
|
|
|
->method('getTitle') |
64
|
|
|
->with($this->equalTo('Senaste nytt från IDG')); |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
$feed->expects($this->once()) |
68
|
|
|
$this->rss->getFeed("http://feeds.feedburner.com/idg/vzzs/", "wrong"); |
69
|
|
|
} |
70
|
|
|
*/ |
71
|
|
|
|
72
|
|
|
/** --------------------------------------------------------- |
73
|
|
|
* Test 3 |
74
|
|
|
* |
75
|
|
|
*/ |
76
|
|
|
|
77
|
|
|
/*protected function setVerboseErrorHandler(){ |
|
|
|
|
78
|
|
|
$handler = function($errorNumber, $errorString, $errorFile, $errorLine) { |
79
|
|
|
echo " |
80
|
|
|
ERROR INFO |
81
|
|
|
Message: $errorString |
82
|
|
|
File: $errorFile |
83
|
|
|
Line: $errorLine |
84
|
|
|
"; |
85
|
|
|
}; |
86
|
|
|
set_error_handler($handler); |
87
|
|
|
}*/ |
88
|
|
|
|
89
|
|
|
/* public function testGetFeed() { |
|
|
|
|
90
|
|
|
$feed = new Miax\RSSFeed\CRSSFeed(['http://feeds.feedburner.com/idg/vzzs/']); |
91
|
|
|
$content = $this->feed->getFeed(); |
92
|
|
|
$this->assertEqual($feed, $content, "Return type is not a valid type"); |
93
|
|
|
// echo setVerboseErrorHandler(); |
94
|
|
|
}*/ |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** --------------------------------------------------------- |
98
|
|
|
* Test test |
99
|
|
|
* |
100
|
|
|
*/ |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
public function testTesting() { |
104
|
|
|
$this->assertEquals(1, 1, "Just making sure this is being checked."); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.