Passed
Pull Request — master (#64)
by Christian
01:49
created

CLIControllerTest::testMain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 0
dl 0
loc 30
rs 9.6666
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A CLIControllerTest::setUp() 0 24 1
1
<?php
2
/**
3
 * Test case
4
 *
5
 * Copyright (c) 2007-2010, Mayflower GmbH
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 *
12
 *   * Redistributions of source code must retain the above copyright
13
 *     notice, this list of conditions and the following disclaimer.
14
 *
15
 *   * Redistributions in binary form must reproduce the above copyright
16
 *     notice, this list of conditions and the following disclaimer in
17
 *     the documentation and/or other materials provided with the
18
 *     distribution.
19
 *
20
 *   * Neither the name of Mayflower GmbH nor the names of his
21
 *     contributors may be used to endorse or promote products derived
22
 *     from this software without specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
 * POSSIBILITY OF SUCH DAMAGE.
36
 *
37
 * @category   PHP_CodeBrowser
38
 *
39
 * @author     Simon Kohlmeyer <[email protected]
40
 *
41
 * @copyright  2007-2010 Mayflower GmbH
42
 *
43
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
44
 *
45
 * @version    SVN: $Id$
46
 *
47
 * @link       http://www.phpunit.de/
48
 *
49
 * @since      File available since  0.1.0
50
 */
51
52
53
namespace PHPCodeBrowser\Tests;
54
55
use Monolog\Logger;
56
use PHPCodeBrowser\CLIController;
57
use PHPCodeBrowser\Helper\IOHelper;
58
use PHPCodeBrowser\Plugins\ErrorCRAP;
59
60
/**
61
 * CLIControllerTest
62
 *
63
 * @category   PHP_CodeBrowser
64
 *
65
 * @author     Simon Kohlmeyer <[email protected]>
66
 *
67
 * @copyright  2007-2010 Mayflower GmbH
68
 *
69
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
70
 *
71
 * @version    Release: @package_version@
72
 *
73
 * @link       http://www.phpunit.de/
74
 *
75
 * @since      Class available since  0.1.0
76
 */
77
class CLIControllerTest extends AbstractTestCase
78
{
79
    /**
80
     * @var CLIController $controller
81
     */
82
    public $controller;
83
84
    /**
85
     * Create and configure a CLIController instance.
86
     */
87
    public function setUp(): void
88
    {
89
        parent::setUp();
90
91
        $this->controller = new CLIController(
92
            null,
93
            [self::$phpcbSourceDir],
94
            self::$testOutputDir,
95
            [],
96
            [],
97
            [ErrorCRAP::class => ['threshold' => 1]],
98
            new IOHelper(),
99
            new Logger('PHPCodeBrowser'),
100
            ['php']
101
        );
102
103
        $this->controller->addErrorPlugins(
104
            [
105
                'ErrorCheckstyle',
106
                'ErrorPMD',
107
                'ErrorCPD',
108
                'ErrorPadawan',
109
                'ErrorCoverage',
110
                'ErrorCRAP',
111
            ]
112
        );
113
    }
114
115
    /**
116
     * Assert a set of directories and files are present in output dir.
117
     */
118
    public function assertOutputIsPresent(): void
119
    {
120
        self::assertFileExists(self::$testOutputDir.'/index.html');
121
        self::assertFileExists(self::$testOutputDir.'/CLIController.php.html');
122
        self::assertDirectoryExists(self::$testOutputDir.'/css');
123
        self::assertDirectoryExists(self::$testOutputDir.'/img');
124
        self::assertDirectoryExists(self::$testOutputDir.'/js');
125
    }
126
127
    /**
128
     * Run a full system test based on phpcs output.
129
     */
130
    public function testRunCreatesFilesAndDirs(): void
131
    {
132
        $this->controller->run();
133
134
        $this->assertOutputIsPresent();
135
    }
136
137
    /**
138
     * Assert existing files and directories within output dir are removed.
139
     */
140
    public function testRunCleansExistingOutputDir(): void
141
    {
142
        mkdir(self::$testOutputDir.'/clear-directory');
143
        touch(self::$testOutputDir.'/clear-file');
144
        touch(self::$testOutputDir.'/clear-directory/clear-file');
145
146
        $this->controller->run();
147
148
        $this->assertOutputIsPresent();
149
        $this->assertDirectoryNotExists(self::$testOutputDir.'/clear-directory');
150
        $this->assertFileNotExists(self::$testOutputDir.'/clear-file');
151
    }
152
153
    /**
154
     * Assert that if there is a file with outputs name, it is replaced with a directory.
155
     */
156
    public function testRunCleansExistingOutputFile(): void
157
    {
158
        rmdir(self::$testOutputDir);
159
        touch(self::$testOutputDir);
160
161
        $this->controller->run();
162
163
        $this->assertOutputIsPresent();
164
    }
165
}
166