FinderTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 61
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testFindWrongParameterPattern() 0 7 1
A testFindNotFound() 0 9 1
A testFindOk() 0 12 1
1
<?php
2
/**
3
 * Class FinderTest
4
 *
5
 * @author Mauro Moreno <[email protected]>
6
 */
7
namespace MauroMoreno\FindBundle\Tests\Services;
8
9
use MauroMoreno\FindBundle\Service\Finder;
10
11
/**
12
 * Class FinderTest
13
 * @package MauroMoreno\FindBundle\Tests\Services
14
 */
15
class FinderTest extends \PHPUnit_Framework_TestCase
16
{
17
18
    /**
19
     * @var Finder
20
     */
21
    private $finder;
22
23
    /**
24
     * Set up
25
     */
26
    public function setUp()
27
    {
28
        parent::setUp();
29
30
        $this->finder = new Finder();
31
    }
32
33
    /**
34
     * Test find, wrong parameter pattern
35
     *
36
     * @expectedException \InvalidArgumentException
37
     */
38
    public function testFindWrongParameterPattern()
39
    {
40
        $found = $this->finder->find(
0 ignored issues
show
Unused Code introduced by
$found 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...
41
           [],
0 ignored issues
show
Documentation introduced by
array() is of type array, 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...
42
            new \SplFileInfo(__DIR__ . '/../Fixtures/directory/file_2')
43
        );
44
    }
45
46
    /**
47
     * Test find, not found
48
     */
49
    public function testFindNotFound()
50
    {
51
        $found = $this->finder->find(
52
            'pattern',
53
            new \SplFileInfo(__DIR__ . '/../Fixtures/directory/file_2')
54
        );
55
56
        $this->assertEquals($found, false);
57
    }
58
59
    /**
60
     * Test find Ok
61
     */
62
    public function testFindOk()
63
    {
64
        $file_info = new \SplFileInfo(
65
            __DIR__ . '/../Fixtures/directory/file_1'
66
        );
67
        $found = $this->finder->find(
68
            'pattern',
69
            $file_info
70
        );
71
72
        $this->assertEquals($found, $file_info);
73
    }
74
75
}