Completed
Push — master ( e0017c...6b1304 )
by Tom
14s queued 11s
created

ModuleTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 94
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 28 1
A testGetConfig() 0 16 1
A testGetConsoleUsage() 0 24 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModuleTest;
6
7
use DoctrineModule\Module;
8
use Laminas\Mvc\Application;
9
use Laminas\Mvc\MvcEvent;
10
use Laminas\ServiceManager\ServiceManager;
11
use PHPUnit\Framework\TestCase;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use function serialize;
15
use function unserialize;
16
17
/**
18
 * @covers \DoctrineModule\Module
19
 */
20
class ModuleTest extends TestCase
21
{
22
    /** @var PHPUnit_Framework_MockObject_MockObject|Application */
23
    private $application;
24
25
    /** @var PHPUnit_Framework_MockObject_MockObject|MvcEvent */
26
    private $event;
27
28
29
    /** @var PHPUnit_Framework_MockObject_MockObject|ServiceManager */
30
    private $serviceManager;
31
32
    /** @var PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\Console\Application */
33
    private $cli;
34
35
    protected function setUp() : void
36
    {
37
        $this->application    = $this->getMockBuilder('Laminas\Mvc\Application')
0 ignored issues
show
Bug introduced by
The method disableOriginalConstructor cannot be called on $this->getMockBuilder('L...nas\\Mvc\\Application') (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
38
            ->disableOriginalConstructor()
39
            ->getMock();
40
        $this->event          = $this->createMock('Laminas\Mvc\MvcEvent');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->event is correct as $this->createMock('Laminas\\Mvc\\MvcEvent') (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
41
        $this->serviceManager = $this->createMock('Laminas\ServiceManager\ServiceManager');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->serviceManager is correct as $this->createMock('Lamin...nager\\ServiceManager') (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
42
        $this->cli            = $this->createPartialMock('Symfony\Component\Console\Application', ['run']);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->cli is correct as $this->createPartialMock...ication', array('run')) (which targets PHPUnit\Framework\TestCase::createPartialMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
43
44
        $this
0 ignored issues
show
Bug introduced by
The method expects cannot be called on $this->serviceManager (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
45
            ->serviceManager
46
            ->expects($this->any())
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
47
            ->method('get')
48
            ->with('doctrine.cli')
49
            ->will($this->returnValue($this->cli));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
50
51
        $this
52
            ->application
53
            ->expects($this->any())
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
54
            ->method('getServiceManager')
55
            ->will($this->returnValue($this->serviceManager));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
56
57
        $this
0 ignored issues
show
Bug introduced by
The method expects cannot be called on $this->event (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
58
            ->event
59
            ->expects($this->any())
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
60
            ->method('getTarget')
61
            ->will($this->returnValue($this->application));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
62
    }
63
64
    /**
65
     * @covers \DoctrineModule\Module::getConfig
66
     */
67
    public function testGetConfig() : void
68
    {
69
        $module = new Module();
70
71
        $config = $module->getConfig();
72
73
        $this->assertIsArray($config);
0 ignored issues
show
Bug introduced by
The method assertIsArray() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
74
        $this->assertArrayHasKey('doctrine', $config);
0 ignored issues
show
Bug introduced by
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
75
        $this->assertArrayHasKey('doctrine_factories', $config);
0 ignored issues
show
Bug introduced by
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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
        $this->assertArrayHasKey('service_manager', $config);
0 ignored issues
show
Bug introduced by
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
77
        $this->assertArrayHasKey('controllers', $config);
0 ignored issues
show
Bug introduced by
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
78
        $this->assertArrayHasKey('route_manager', $config);
0 ignored issues
show
Bug introduced by
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
79
        $this->assertArrayHasKey('console', $config);
0 ignored issues
show
Bug introduced by
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
80
81
        $this->assertSame($config, unserialize(serialize($config)));
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
82
    }
83
84
    /**
85
     * Should display the help message in plain message
86
     *
87
     * @covers \DoctrineModule\Module::getConsoleUsage
88
     */
89
    public function testGetConsoleUsage() : void
90
    {
91
        $this
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component\Console\Application>.

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...
92
            ->cli
93
            ->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
94
            ->method('run')
95
            ->with(
96
                $this->isInstanceOf('Symfony\Component\Console\Input\InputInterface'),
0 ignored issues
show
Bug introduced by
The method isInstanceOf() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
97
                $this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface')
0 ignored issues
show
Bug introduced by
The method isInstanceOf() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
98
            )
99
            ->will($this->returnCallback(static function (InputInterface $input, OutputInterface $output) : void {
0 ignored issues
show
Bug introduced by
The method returnCallback() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
100
                $output->write($input->getFirstArgument() . ' - TEST');
101
                $output->write(' - More output');
102
            }));
103
104
        $module = new Module();
105
106
        $module->onBootstrap($this->event);
107
108
        $this->assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DoctrineModuleTest\ModuleTest>.

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...
109
            'list - TEST - More output',
110
            $module->getConsoleUsage($this->createMock('Laminas\Console\Adapter\AdapterInterface'))
0 ignored issues
show
Documentation introduced by
$this->createMock('Lamin...ter\\AdapterInterface') is of type null, but the function expects a object<Laminas\Console\Adapter\AdapterInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
111
        );
112
    }
113
}
114