Completed
Pull Request — master (#5)
by Helpful
02:08
created

TocifierTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testProcess() 0 17 1
A testHtml() 0 7 1
A testTOC() 0 12 1
1
<?php
2
3
class TocifierTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    public function testProcess()
6
    {
7
        $tocifier = new Tocifier(1234);
8
        $this->assertFalse($tocifier->process());
9
10
        $tocifier = new Tocifier('');
11
        $this->assertFalse($tocifier->process());
12
13
        $tocifier = new Tocifier(null);
14
        $this->assertFalse($tocifier->process());
15
16
        $tocifier = new Tocifier(array('1234'));
0 ignored issues
show
Documentation introduced by
array('1234') is of type array<integer,string,{"0":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
17
        $this->assertFalse($tocifier->process());
18
19
        $tocifier = new Tocifier('1234');
20
        $this->assertTrue($tocifier->process());
21
    }
22
23
    public function testHtml()
24
    {
25
        $tocifier = new Tocifier(file_get_contents(__DIR__ . '/test1'));
26
        $this->assertEquals($tocifier->getHtml(), '');
27
        $this->assertTrue($tocifier->process());
28
        $this->assertStringEqualsFile(__DIR__ . '/html1', $tocifier->getHtml());
29
    }
30
31
    public function testTOC()
32
    {
33
        $tocifier = new Tocifier(file_get_contents(__DIR__ . '/test1'));
34
        $this->assertEquals($tocifier->getTOC(), array());
35
        $this->assertTrue($tocifier->process());
36
        $this->assertNotNull($tocifier->getTOC());
37
38
        ob_start();
39
        $tocifier->dumpTOC();
40
        $returned = ob_get_clean();
41
        $this->assertStringEqualsFile(__DIR__ . '/toc1', $returned);
42
    }
43
}
44