Completed
Pull Request — master (#671)
by Antonio
05:59
created

RelativeNamespaceDiscoveryTest::callProtected()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
3
use Robo\ClassDiscovery\RelativeNamespaceDiscovery;
4
use Composer\Autoload\ClassLoader;
5
6
/**
7
 * Class RelativeNamespaceDiscoveryTest
8
 */
9
class RelativeNamespaceDiscoveryTest extends \Codeception\Test\Unit
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...
10
{
11
    public function testGetClasses()
12
    {
13
        $classLoader = new ClassLoader();
14
        $classLoader->addPsr4('\\Robo\\', [realpath(__DIR__.'/../../src')]);
15
16
        $discovery = new RelativeNamespaceDiscovery('\Commands');
17
        $discovery->setClassLoader($classLoader);
18
19
        $classes = $discovery->getClasses();
20
21
        $this->assertContains('\Robo\FirstCustomCommands', $classes);
22
        $this->assertContains('\Robo\SecondCustomCommands', $classes);
23
    }
24
25
    /**
26
     * @dataProvider testConvertPathToNamespaceData
27
     *
28
     * @param $path
29
     * @param $expected
30
     */
31
    public function testConvertPathToNamespace($path, $expected)
32
    {
33
        $discovery = new RelativeNamespaceDiscovery('');
34
        $actual = $this->callProtected($discovery, 'convertPathToNamespace', [$path]);
35
        $this->assertEquals($expected, $actual);
36
    }
37
38
    public function testConvertPathToNamespaceData()
39
    {
40
        return [
41
          ['/A/B/C', 'A\B\C'],
42
          ['A/B/C', 'A\B\C'],
43
          ['A/B/C', 'A\B\C'],
44
          ['A/B/C.php', 'A\B\C'],
45
        ];
46
    }
47
48
    /**
49
     * @dataProvider testConvertNamespaceToPathData
50
     *
51
     * @param $namespace
52
     * @param $expected
53
     */
54
    public function testConvertNamespaceToPath($namespace, $expected)
55
    {
56
        $discovery = new RelativeNamespaceDiscovery('');
57
        $actual = $this->callProtected($discovery, 'convertNamespaceToPath', [$namespace]);
58
        $this->assertEquals($expected, $actual);
59
    }
60
61
    public function testConvertNamespaceToPathData()
62
    {
63
        return [
64
          ['A\B\C', '/A/B/C'],
65
          ['\A\B\C\\', '/A/B/C'],
66
          ['A\B\C\\', '/A/B/C'],
67
        ];
68
    }
69
70
    function callProtected($object, $method, $args = [])
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
71
    {
72
        $r = new \ReflectionMethod($object, $method);
73
        $r->setAccessible(true);
74
        return $r->invokeArgs($object, $args);
75
    }
76
}