CliControllerTest::testNonZeroExitCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModuleTest\Controller;
6
7
use DoctrineModuleTest\Controller\Mock\FailingCommand;
8
use DoctrineModuleTest\ServiceManagerFactory;
9
use Laminas\Console\Request;
10
use Laminas\Test\PHPUnit\Controller\AbstractConsoleControllerTestCase;
11
use Symfony\Component\Console\Output\BufferedOutput;
12
13
/**
14
 * Tests for {@see \DoctrineModule\Controller\CliController}
15
 *
16
 * @covers \DoctrineModule\Controller\CliController
17
 */
18
class CliControllerTest extends AbstractConsoleControllerTestCase
19
{
20
    protected function setUp() : void
21
    {
22
        $this->setApplicationConfig(ServiceManagerFactory::getConfiguration());
23
        parent::setUp();
24
25
        $this->output = new BufferedOutput();
0 ignored issues
show
Bug introduced by
The property output cannot be accessed from this context as it is declared private in class PHPUnit\Framework\TestCase.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Documentation Bug introduced by
It seems like new \Symfony\Component\C...Output\BufferedOutput() of type object<Symfony\Component...\Output\BufferedOutput> is incompatible with the declared type string of property $output.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
26
        $controller   = $this->getApplicationServiceLocator()
27
             ->get('ControllerManager')
28
             ->get('DoctrineModule\Controller\Cli');
29
        $controller->setOutput($this->output);
0 ignored issues
show
Bug introduced by
The property output cannot be accessed from this context as it is declared private in class PHPUnit\Framework\TestCase.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
30
31
        $this->getApplicationServiceLocator()->get('doctrine.cli')
32
            ->add(new FailingCommand());
33
    }
34
35
    /**
36
     * Verifies that the controller handling the DoctrineModule CLI functionality can be reached
37
     */
38
    public function testIndexActionCanBeAccessed() : void
39
    {
40
        $this->dispatch(new Request(['scriptname.php', 'list']));
41
42
        $this->assertResponseStatusCode(0);
43
        $this->assertModuleName('doctrinemodule');
44
        $this->assertControllerName('doctrinemodule\controller\cli');
45
        $this->assertControllerClass('clicontroller');
46
        $this->assertActionName('cli');
47
        $this->assertMatchedRouteName('doctrine_cli');
48
    }
49
50
    public function testNonZeroExitCode() : void
51
    {
52
        $this->dispatch(new Request(['scriptname.php', 'fail']));
53
54
        $this->assertNotResponseStatusCode(0);
55
    }
56
57
    public function testException() : void
58
    {
59
        $this->dispatch(new Request(['scriptname.php', '-q', 'fail', '--exception']));
60
61
        $this->assertNotResponseStatusCode(0);
62
    }
63
}
64