Passed
Push — master ( 813fe9...62056b )
by Sebastian
06:01
created

DefaultIOTest::testIsDebug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 11
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace CaptainHook\App\Console\IO;
11
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
class DefaultIOTest extends \PHPUnit_Framework_TestCase
15
{
16
    /**
17
     * @return \Symfony\Component\Console\Input\InputInterface
18
     */
19
    public function getInputMock()
20
    {
21
        return $this->getMockBuilder('\\Symfony\\Component\\Console\\Input\\InputInterface')
22
                     ->disableOriginalConstructor()
23
                     ->getMock();
24
    }
25
26
    /**
27
     * @return \Symfony\Component\Console\Output\ConsoleOutputInterface
28
     */
29
    public function getConsoleOutputMock()
30
    {
31
        return $this->getMockBuilder('\\Symfony\\Component\\Console\\Output\\ConsoleOutputInterface')
32
                    ->disableOriginalConstructor()
33
                    ->getMock();
34
    }
35
36
    /**
37
     * @return \Symfony\Component\Console\Output\OutputInterface
38
     */
39
    public function getOutputMock()
40
    {
41
        return $this->getMockBuilder('\\Symfony\\Component\\Console\\Output\\OutputInterface')
42
                     ->disableOriginalConstructor()
43
                     ->getMock();
44
    }
45
46
    /**
47
     * @return \Symfony\Component\Console\Helper\HelperSet
48
     */
49
    public function getHelperSetMock()
50
    {
51
        return $this->getMockBuilder('\\Symfony\\Component\\Console\\Helper\\HelperSet')
52
                     ->disableOriginalConstructor()
53
                     ->getMock();
54
    }
55
56
    /**
57
     * @return \Symfony\Component\Console\Helper\QuestionHelper
58
     */
59
    public function getQuestionHelper()
60
    {
61
        return $this->getMockBuilder('\\Symfony\\Component\\Console\\Helper\\QuestionHelper')
62
                     ->disableOriginalConstructor()
63
                     ->getMock();
64
    }
65
66
    /**
67
     * Tests DefaultIO::isInteractive
68
     */
69 View Code Duplication
    public function testIsInteractive()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        $input  = $this->getInputMock();
72
        $output = $this->getOutputMock();
73
        $helper = $this->getHelperSetMock();
74
75
        $input->expects($this->once())->method('isInteractive')->willReturn(false);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...e\Input\InputInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
76
        $io = new DefaultIO($input, $output, $helper);
77
78
        $this->assertFalse($io->isInteractive());
79
    }
80
81
    /**
82
     * Tests DefaultIO::isVerbose
83
     */
84 View Code Duplication
    public function testIsVerbose()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
    {
86
        $input  = $this->getInputMock();
87
        $output = $this->getOutputMock();
88
        $helper = $this->getHelperSetMock();
89
90
        $output->expects($this->once())->method('getVerbosity')->willReturn(0);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...Output\OutputInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
        $io = new DefaultIO($input, $output, $helper);
92
93
        $this->assertFalse($io->isVerbose());
94
    }
95
96
    /**
97
     * Tests DefaultIO::isVeryVerbose
98
     */
99 View Code Duplication
    public function testIsVeryVerbose()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
    {
101
        $input  = $this->getInputMock();
102
        $output = $this->getOutputMock();
103
        $helper = $this->getHelperSetMock();
104
105
        $output->expects($this->once())->method('getVerbosity')->willReturn(0);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...Output\OutputInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
106
        $io = new DefaultIO($input, $output, $helper);
107
108
        $this->assertFalse($io->isVeryVerbose());
109
    }
110
111
    /**
112
     * Tests DefaultIO::isDebug
113
     */
114 View Code Duplication
    public function testIsDebug()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
115
    {
116
        $input  = $this->getInputMock();
117
        $output = $this->getOutputMock();
118
        $helper = $this->getHelperSetMock();
119
120
        $output->expects($this->once())->method('getVerbosity')->willReturn(0);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...Output\OutputInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
121
        $io = new DefaultIO($input, $output, $helper);
122
123
        $this->assertFalse($io->isDebug());
124
    }
125
126
    /**
127
     * Tests DefaultIO::writeError
128
     */
129 View Code Duplication
    public function testWriteError()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
130
    {
131
        $input  = $this->getInputMock();
132
        $output = $this->getOutputMock();
133
        $helper = $this->getHelperSetMock();
134
135
        $output->expects($this->once())->method('getVerbosity')->willReturn(OutputInterface::VERBOSITY_DEBUG);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...Output\OutputInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
136
        $io = new DefaultIO($input, $output, $helper);
137
138
        $io->writeError('foo');
139
    }
140
141
    /**
142
     * Tests DefaultIO::ask
143
     */
144 View Code Duplication
    public function testAsk()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
145
    {
146
        $input          = $this->getInputMock();
147
        $output         = $this->getOutputMock();
148
        $helper         = $this->getHelperSetMock();
149
        $questionHelper = $this->getQuestionHelper();
150
151
        $helper->expects($this->once())->method('get')->willReturn($questionHelper);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...nsole\Helper\HelperSet>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
152
        $questionHelper->expects($this->once())->method('ask')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...\Helper\QuestionHelper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
153
154
        $io     = new DefaultIO($input, $output, $helper);
155
        $answer = $io->ask('foo');
156
        $this->assertTrue($answer);
157
    }
158
159
    /**
160
     * Tests DefaultIO::askConfirmation
161
     */
162 View Code Duplication
    public function testAskConfirmation()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
163
    {
164
        $input          = $this->getInputMock();
165
        $output         = $this->getOutputMock();
166
        $helper         = $this->getHelperSetMock();
167
        $questionHelper = $this->getQuestionHelper();
168
169
        $helper->expects($this->once())->method('get')->willReturn($questionHelper);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...nsole\Helper\HelperSet>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
170
        $questionHelper->expects($this->once())->method('ask')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...\Helper\QuestionHelper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
171
172
        $io     = new DefaultIO($input, $output, $helper);
173
        $answer = $io->askConfirmation('foo');
174
        $this->assertTrue($answer);
175
    }
176
177
    /**
178
     * Tests DefaultIO::askAbdValidate
179
     */
180 View Code Duplication
    public function testAskAndValidate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
181
    {
182
        $input          = $this->getInputMock();
183
        $output         = $this->getOutputMock();
184
        $helper         = $this->getHelperSetMock();
185
        $questionHelper = $this->getQuestionHelper();
186
187
        $helper->expects($this->once())->method('get')->willReturn($questionHelper);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...nsole\Helper\HelperSet>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
188
        $questionHelper->expects($this->once())->method('ask')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...\Helper\QuestionHelper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
189
190
        $io     = new DefaultIO($input, $output, $helper);
191
        $answer = $io->askAndValidate('foo', function() { return true; });
192
        $this->assertTrue($answer);
193
    }
194
195
    /**
196
     * Tests DefaultIO::write
197
     */
198
    public function testWrite()
199
    {
200
        $input          = $this->getInputMock();
201
        $output         = $this->getConsoleOutputMock();
202
        $helper         = $this->getHelperSetMock();
203
204
        $output->expects($this->once())->method('getVerbosity')->willReturn(OutputInterface::VERBOSITY_DEBUG);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...ConsoleOutputInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
205
        $output->expects($this->once())->method('getErrorOutput')->willReturn($this->getOutputMock());
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...ConsoleOutputInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
206
207
        $io = new DefaultIO($input, $output, $helper);
208
        $io->writeError('foo');
209
    }
210
}
211