MapBuilderTest::tearDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace KochTest\Autoload;
4
5
use Koch\Autoload\MapBuilder;
6
use org\bovigo\vfs\vfsStream;
7
use org\bovigo\vfs\vfsStreamDirectory;
8
use org\bovigo\vfs\vfsStreamWrapper;
9
10
class MapBuilderTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var MapBuilder
14
     */
15
    protected $object;
16
17
    protected function setUp()
18
    {
19
        $this->object = new MapBuilder();
20
21
        vfsStreamWrapper::register();
22
23
        $this->vfsFileURL = vfsStream::url('root/classmap.file');
0 ignored issues
show
Bug introduced by
The property vfsFileURL 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...
24
        $this->file       = vfsStream::newFile('classmap.file', 0777);
0 ignored issues
show
Bug introduced by
The property file 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
26
        $this->vfsFileWithPHPClass = vfsStream::url('root/class.php');
0 ignored issues
show
Bug introduced by
The property vfsFileWithPHPClass 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...
27
        $content                   = '<?php namespace SomeNamespace; class MyClass(){} ?>';
28
        $this->file2               = vfsStream::newFile('class.php', 0777)->setContent($content);
0 ignored issues
show
Bug introduced by
The property file2 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...
29
30
        $this->root = new vfsStreamDirectory('root');
0 ignored issues
show
Bug introduced by
The property root 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...
31
        $this->root->addChild($this->file);
32
        $this->root->addChild($this->file2);
33
34
        vfsStreamWrapper::setRoot($this->root);
35
    }
36
37
    protected function tearDown()
38
    {
39
        unset($this->object);
40
    }
41
42
    /**
43
     * @covers Koch\Autoload\MapBuilder::build
44
     * @covers Koch\Autoload\MapBuilder::writeMapFile
45
     * @covers Koch\Autoload\MapBuilder::extractClassnames
46
     * @covers Koch\Functions\Functions::globRecursive
47
     * @covers Koch\Autoload\Loader::autoload
48
     * @covers Koch\Autoload\Loader::autoloadExclusions
49
     * @covers Koch\Autoload\Loader::autoloadInclusions
50
     * @covers Koch\Autoload\Loader::includeFileAndMap
51
     * @covers Koch\Autoload\Loader::autoloadByApcOrFileMap
52
     * @covers Koch\Autoload\Loader::autoloadIncludePath
53
     * @covers Koch\Autoload\Loader::writeAutoloadingMapFile
54
     * @covers Koch\Autoload\Loader::addMapping
55
     */
56
    public function testBuild()
57
    {
58
        // create classmap
59
       $this->object->build(
60
           [__DIR__ . '/../../../framework/Koch/Config/Adapter'],
61
           $this->vfsFileURL
62
       );
63
64
       // include classmap array
65
       $classmap = include $this->vfsFileURL;
66
67
        $this->assertTrue(is_array($classmap));
68
        $this->assertArrayHasKey('Koch\Config\Adapter\CSV', $classmap);
69
    }
70
71
    /**
72
     * @covers Koch\Autoload\MapBuilder::extractClassnames
73
     * @covers Koch\Autoload\Loader::autoload
74
     * @covers Koch\Autoload\Loader::autoloadExclusions
75
     * @covers Koch\Autoload\Loader::autoloadInclusions
76
     * @covers Koch\Autoload\Loader::includeFileAndMap
77
     * @covers Koch\Autoload\Loader::autoloadByApcOrFileMap
78
     * @covers Koch\Autoload\Loader::autoloadIncludePath
79
     * @covers Koch\Autoload\Loader::writeAutoloadingMapFile
80
     * @covers Koch\Autoload\Loader::addMapping
81
     */
82
    public function testExtractClassnames()
83
    {
84
        $classname = $this->object->extractClassnames($this->vfsFileWithPHPClass);
85
86
        $this->assertEquals($classname[0], 'SomeNamespace\MyClass');
87
    }
88
89
    /**
90
     * @covers Koch\Autoload\MapBuilder::extractClassnames
91
     * @covers Koch\Autoload\Loader::autoload
92
     * @covers Koch\Autoload\Loader::autoloadExclusions
93
     * @expectedException \InvalidArgumentException
94
     * @expectedExceptionMessage File from-not-existing-file.php does not exist.
95
     */
96
    public function testExtractClassnames_throwsException()
0 ignored issues
show
Coding Style introduced by
function testExtractClassnames_throwsException() 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...
97
    {
98
        $classname = $this->object->extractClassnames('from-not-existing-file.php');
0 ignored issues
show
Unused Code introduced by
$classname 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...
99
    }
100
101
    /**
102
     * @covers Koch\Autoload\MapBuilder::writeMapFile
103
     */
104
    public function testWriteMapFile()
105
    {
106
        $classmap = ['classname' => 'filename'];
107
        $mapfile  = $this->vfsFileURL;
108
        $res      = $this->object->writeMapFile($classmap, $mapfile);
109
        $this->assertTrue($res);
110
    }
111
}
112