FeedTest::testMethodFetchRSS()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 9.4285
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';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
22
        $this->feedUrl = __DIR__ . '/fixtures/clansuite_rss_v2_0_msgs.xml';#
23
24
        $this->cacheFolder = __DIR__ . '/fixtures/';
0 ignored issues
show
Bug introduced by
The property cacheFolder does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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);
0 ignored issues
show
Coding Style introduced by
$simplepie_feed_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
34
35
        $this->assertInstanceOf('SimplePie', $simplepie_feed_object);
0 ignored issues
show
Coding Style introduced by
$simplepie_feed_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
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);
0 ignored issues
show
Unused Code introduced by
$feedcontent is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
74
        // check for cache file
75
        $this->assertFileExists($this->cacheFile);
76
    }
77
}
78