These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | use Robo\Robo; |
||
3 | |||
4 | class OutputTest extends \Codeception\TestCase\Test |
||
5 | { |
||
6 | use \Robo\Common\IO { |
||
7 | say as public; |
||
8 | yell as public; |
||
9 | ask as public; |
||
10 | output as protected; |
||
11 | } |
||
12 | |||
13 | protected $expectedAnswer; |
||
14 | |||
15 | /** |
||
16 | * @var \CodeGuy |
||
17 | */ |
||
18 | protected $guy; |
||
19 | |||
20 | /** |
||
21 | * @vAspectMock\Proxy\ClassProxyroxy |
||
22 | */ |
||
23 | protected $dialog; |
||
24 | |||
25 | protected function _before() |
||
26 | { |
||
27 | $this->dialog = new Symfony\Component\Console\Helper\QuestionHelper; |
||
28 | $this->setOutput(Robo::service('output')); |
||
29 | } |
||
30 | |||
31 | public function testSay() |
||
32 | { |
||
33 | $this->say('Hello, world!'); |
||
34 | $this->guy->seeInOutput('> Hello, world!'); |
||
35 | } |
||
36 | |||
37 | public function testAskReply() |
||
38 | { |
||
39 | $this->expectedAnswer = 'jon'; |
||
40 | verify($this->ask('What is your name?'))->equals('jon'); |
||
41 | $this->guy->seeOutputEquals('? What is your name? '); |
||
42 | } |
||
43 | View Code Duplication | public function testAskMethod() |
|
0 ignored issues
–
show
|
|||
44 | { |
||
45 | if (method_exists($this, 'createMock')) { |
||
46 | $this->dialog = $this->createMock('\Symfony\Component\Console\Helper\QuestionHelper', ['ask']); |
||
47 | } else { |
||
48 | $this->dialog = $this->getMock('\Symfony\Component\Console\Helper\QuestionHelper', ['ask']); |
||
49 | } |
||
50 | $this->dialog->expects($this->once()) |
||
51 | ->method('ask'); |
||
52 | $this->ask('What is your name?'); |
||
53 | } |
||
54 | View Code Duplication | public function testAskHiddenMethod() |
|
0 ignored issues
–
show
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. ![]() |
|||
55 | { |
||
56 | if (method_exists($this, 'createMock')) { |
||
57 | $this->dialog = $this->createMock('\Symfony\Component\Console\Helper\QuestionHelper', ['ask']); |
||
58 | } else { |
||
59 | $this->dialog = $this->getMock('\Symfony\Component\Console\Helper\QuestionHelper', ['ask']); |
||
60 | } |
||
61 | $this->dialog->expects($this->once()) |
||
62 | ->method('ask'); |
||
63 | $this->ask('What is your name?', true); |
||
64 | } |
||
65 | public function testYell() |
||
66 | { |
||
67 | $this->yell('Buuuu!'); |
||
68 | $this->guy->seeInOutput('Buuuu!'); |
||
69 | } |
||
70 | protected function getDialog() |
||
71 | { |
||
72 | $stream = fopen('php://memory', 'r+', false); |
||
73 | fputs($stream, $this->expectedAnswer); |
||
74 | rewind($stream); |
||
75 | // Use StreamableInputInterface when it's available |
||
76 | if ($this->input() instanceof \Symfony\Component\Console\Input\StreamableInputInterface) { |
||
77 | $this->input()->setStream($stream); |
||
78 | } else { |
||
79 | // setInputStream deprecated in Symfony 3.2. |
||
80 | $this->dialog->setInputStream($stream); |
||
0 ignored issues
–
show
The method
setInputStream does only exist in Symfony\Component\Console\Helper\QuestionHelper , but not in PHPUnit_Framework_MockObject_MockObject .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
81 | } |
||
82 | return $this->dialog; |
||
83 | } |
||
84 | } |
||
85 |
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.