Passed
Push — master ( bf5f5b...c9bc7e )
by Adrian Florin
15:14
created

ClassFinderTest::testLogOutput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
namespace NeedleProject\Common;
3
4
use Psr\Log\LoggerInterface;
5
6
class ClassFinderTest extends \PHPUnit_Framework_TestCase
7
{
8
    /**
9
     * @dataProvider provideScenarios
10
     * @param string $className
11
     * @param array $expectedFoundClasses
12
     */
13
    public function testClassSearch($className, $expectedFoundClasses)
14
    {
15
        $classFinder = new ClassFinder(
16
            realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR,
17
            $className
18
        );
19
20
        $foundClasses = $classFinder->findClasses();
21
        sort($foundClasses);
22
        sort($expectedFoundClasses);
23
        $this->assertEquals(
24
            $expectedFoundClasses,
25
            $foundClasses
26
        );
27
    }
28
29
    /**
30
     * Test that the Log will output - fixed to cover
31
     */
32
    public function testLogOutput()
33
    {
34
        $classFinder = new ClassFinder(
35
            realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR,
36
            \Fixture\BaseInterface::class
37
        );
38
39
        $loggerMock = $this->getMockBuilder(
40
            LoggerInterface::class
41
        );
42
        $loggerMock = $loggerMock->getMock();
43
        $loggerMock->expects($this->atLeastOnce())
44
            ->method('log')
45
            ->will($this->returnValue(null));
46
47
        $classFinder->setLogger(
48
            $loggerMock
49
        );
50
51
        $classFinder->findClasses();
52
    }
53
54
    /**
55
     * @return array
56
     */
57
    public function provideScenarios()
58
    {
59
        return [
60
            [
61
                \Fixture\BaseInterface::class,
62
                [
63
                    \Fixture\Path\ClassList\BazClass::class,
64
                    \Fixture\Path\ClassList\GodClass::class,
65
                    \Fixture\Path\FooClass::class
66
                ]
67
            ],
68
            [
69
                \Fixture\BaseClass::class,
70
                [
71
                    \Fixture\Path\ExtendsBaseClass::class
72
                ]
73
            ],
74
            [
75
                \Fixture\AbstractBase::class,
76
                [
77
                    \Fixture\Path\FooClass::class,
78
                    \Fixture\Path\ClassList\BarClass::class,
79
                    \Fixture\Path\ClassList\BazClass::class,
80
                    \Fixture\Path\ClassList\GodClass::class
81
                ]
82
            ]
83
        ];
84
    }
85
}
86