Completed
Push — develop ( 8fda15...dbbcf5 )
by Jaap
14s
created

tests/unit/phpDocumentor/ApplicationTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace phpDocumentor;
4
5
use Mockery as m;
6
use Monolog\Logger;
7
use Symfony\Component\Console\Application as ConsoleApplication;
8
9
class ApplicationTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
10
{
11
    /** @var Application */
12
    private $fixture;
13
14
    /**
15
     * Initializes the fixture for this test.
16
     */
17
    public function setUp()
18
    {
19
        $this->fixture = new Application();
20
    }
21
22
    /**
23
     * @covers phpDocumentor\Application::__construct
24
     */
25
    public function testIfStopwatchIsStarted()
26
    {
27
        $this->assertTrue(isset($this->fixture['kernel.timer.start']));
28
        $this->assertTrue(isset($this->fixture['kernel.stopwatch']));
29
    }
30
31
    /**
32
     * @covers phpDocumentor\Application::__construct
33
     */
34
    public function testIfVersionIsPopulated()
35
    {
36
        $this->assertRegExp('/^[\d]+\.[\d]+\.[\d]+(\-[\w]+)?$/', Application::$VERSION);
37
    }
38
39
    /**
40
     * @covers phpDocumentor\Application::__construct
41
     */
42
    public function testIfAutoloaderIsRegistered()
43
    {
44
        // Arrange
45
        $autoloader = m::mock('Composer\Autoload\ClassLoader');
46
47
        // Act
48
        $application = new Application($autoloader);
49
50
        // Assert
51
        $this->assertSame($autoloader, $application['autoloader']);
52
    }
53
54
    /**
55
     * @covers phpDocumentor\Application::__construct
56
     */
57
    public function testIfSerializerIsRegistered()
58
    {
59
        $this->assertTrue(isset($this->fixture['serializer']));
60
    }
61
62
    /**
63
     * @covers phpDocumentor\Application::__construct
64
     */
65
    public function testIfConfigurationIsRegistered()
66
    {
67
        $this->assertTrue(isset($this->fixture['config']));
68
        $this->assertInstanceOf('phpDocumentor\Configuration', $this->fixture['config']);
69
    }
70
71
    /**
72
     * @covers phpDocumentor\Application::__construct
73
     * @covers phpDocumentor\Application::addEventDispatcher
74
     */
75
    public function testIfEventDispatcherIsRegistered()
76
    {
77
        $this->assertTrue(isset($this->fixture['event_dispatcher']));
78
        $this->assertInstanceOf('phpDocumentor\Event\Dispatcher', $this->fixture['event_dispatcher']);
79
    }
80
81
    /**
82
     * @covers phpDocumentor\Application::__construct
83
     */
84
    public function testIfTranslatorIsRegistered()
85
    {
86
        $this->assertTrue(isset($this->fixture['translator']));
87
    }
88
89
    /**
90
     * @covers phpDocumentor\Application::__construct
91
     */
92
    public function testIfDescriptorBuilderIsRegistered()
93
    {
94
        $this->assertTrue(isset($this->fixture['descriptor.builder']));
95
    }
96
97
    /**
98
     * @covers phpDocumentor\Application::__construct
99
     */
100
    public function testIfParserIsRegistered()
101
    {
102
        $this->assertTrue(isset($this->fixture['parser']));
103
    }
104
105
    /**
106
     * @covers phpDocumentor\Application::__construct
107
     */
108
    public function testIfPartialsAreRegistered()
109
    {
110
        $this->assertTrue(isset($this->fixture['partials']));
111
    }
112
113
    /**
114
     * @covers phpDocumentor\Application::__construct
115
     */
116
    public function testIfTransformerIsRegistered()
117
    {
118
        $this->assertTrue(isset($this->fixture['transformer']));
119
    }
120
121
    /**
122
     * @covers phpDocumentor\Application::__construct
123
     */
124
    public function testIfPluginsAreRegistered()
125
    {
126
        $this->assertTrue(isset($this->fixture['transformer.writer.collection']['checkstyle']));
127
    }
128
129
    /**
130
     * @covers phpDocumentor\Application::__construct
131
     * @covers phpDocumentor\Application::addCommandsForProjectNamespace
132
     */
133
    public function testIfRunCommandIsRegistered()
134
    {
135
        /** @var ConsoleApplication $console */
136
        $console = $this->fixture['console'];
137
        $this->assertTrue($console->has('project:run'));
138
    }
139
140
    /**
141
     * @covers phpDocumentor\Application::__construct
142
     * @covers phpDocumentor\Application::defineIniSettings
143
     */
144
    public function testIfMemoryLimitIsDisabled()
145
    {
146
        $this->assertSame('-1', ini_get('memory_limit'));
147
    }
148
149
    /**
150
     * Test setting loglevel to logger.
151
     *
152
     * @param string $loglevel
153
     * @param string $expectedLogLevel
154
     *
155
     * @dataProvider loglevelProvider
156
     * @covers phpDocumentor\Application::configureLogger
157
     */
158
    public function testSetLogLevel($loglevel, $expectedLogLevel)
159
    {
160
        $logger = m::mock('Monolog\Logger')
161
            ->shouldReceive('pushHandler')->with(m::on(function ($stream) use ($expectedLogLevel) {
162
                if (!$stream instanceof \Monolog\Handler\StreamHandler) {
163
                    return false;
164
                }
165
166
                return $stream->getLevel() === $expectedLogLevel;
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison === seems to always evaluate to false as the types of $stream->getLevel() (integer) and $expectedLogLevel (string) can never be identical. Maybe you want to use a loose comparison == instead?
Loading history...
167
            }))
168
            ->shouldReceive('popHandler')
169
            ->getMock();
170
        $this->fixture->configureLogger($logger, $loglevel);
171
        $this->assertSame($expectedLogLevel, $this->fixture['monolog.level']);
172
    }
173
174
    /**
175
     * Data provider for testSetLogLevel
176
     *
177
     * @return array[]
178
     */
179
    public function loglevelProvider()
180
    {
181
        return [
182
            [
183
                'emergency',
184
                Logger::EMERGENCY,
185
            ],
186
            [
187
                'emerg',
188
                Logger::EMERGENCY,
189
            ],
190
            [
191
                'alert',
192
                Logger::ALERT,
193
            ],
194
            [
195
                'critical',
196
                Logger::CRITICAL,
197
            ],
198
            [
199
                'error',
200
                Logger::ERROR,
201
            ],
202
            [
203
                'err',
204
                Logger::ERROR,
205
            ],
206
            [
207
                'warning',
208
                Logger::WARNING,
209
            ],
210
            [
211
                'warn',
212
                Logger::WARNING,
213
            ],
214
            [
215
                'notice',
216
                Logger::NOTICE,
217
            ],
218
            [
219
                'info',
220
                Logger::INFO,
221
            ],
222
            [
223
                'debug',
224
                Logger::DEBUG,
225
            ],
226
        ];
227
    }
228
}
229