ModuleTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
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
Documentation Bug introduced by
It seems like $this->getMockBuilder('L...onstructor()->getMock() of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<DoctrineModuleTes...aminas\Mvc\Application> of property $application.

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...
38
            ->disableOriginalConstructor()
39
            ->getMock();
40
        $this->event          = $this->createMock('Laminas\Mvc\MvcEvent');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock('Laminas\\Mvc\\MvcEvent') of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<DoctrineModuleTes...t<Laminas\Mvc\MvcEvent> of property $event.

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...
41
        $this->serviceManager = $this->createMock('Laminas\ServiceManager\ServiceManager');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock('Lamin...nager\\ServiceManager') of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<DoctrineModuleTes...Manager\ServiceManager> of property $serviceManager.

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...
42
        $this->cli            = $this->createPartialMock('Symfony\Component\Console\Application', ['run']);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createPartialMock...ication', array('run')) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<DoctrineModuleTes...nt\Console\Application> of property $cli.

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...
43
44
        $this
45
            ->serviceManager
46
            ->expects($this->any())
47
            ->method('get')
48
            ->with('doctrine.cli')
49
            ->will($this->returnValue($this->cli));
50
51
        $this
52
            ->application
53
            ->expects($this->any())
54
            ->method('getServiceManager')
55
            ->will($this->returnValue($this->serviceManager));
56
57
        $this
58
            ->event
59
            ->expects($this->any())
60
            ->method('getTarget')
61
            ->will($this->returnValue($this->application));
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);
74
        $this->assertArrayHasKey('doctrine', $config);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $module->getConfig() on line 71 can also be of type object<Traversable>; however, PHPUnit\Framework\Assert::assertArrayHasKey() does only seem to accept array|object<ArrayAccess>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
75
        $this->assertArrayHasKey('doctrine_factories', $config);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $module->getConfig() on line 71 can also be of type object<Traversable>; however, PHPUnit\Framework\Assert::assertArrayHasKey() does only seem to accept array|object<ArrayAccess>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
76
        $this->assertArrayHasKey('service_manager', $config);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $module->getConfig() on line 71 can also be of type object<Traversable>; however, PHPUnit\Framework\Assert::assertArrayHasKey() does only seem to accept array|object<ArrayAccess>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
77
        $this->assertArrayHasKey('controllers', $config);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $module->getConfig() on line 71 can also be of type object<Traversable>; however, PHPUnit\Framework\Assert::assertArrayHasKey() does only seem to accept array|object<ArrayAccess>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
78
        $this->assertArrayHasKey('route_manager', $config);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $module->getConfig() on line 71 can also be of type object<Traversable>; however, PHPUnit\Framework\Assert::assertArrayHasKey() does only seem to accept array|object<ArrayAccess>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
79
        $this->assertArrayHasKey('console', $config);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $module->getConfig() on line 71 can also be of type object<Traversable>; however, PHPUnit\Framework\Assert::assertArrayHasKey() does only seem to accept array|object<ArrayAccess>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
80
81
        $this->assertSame($config, unserialize(serialize($config)));
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())
94
            ->method('run')
95
            ->with(
96
                $this->isInstanceOf('Symfony\Component\Console\Input\InputInterface'),
97
                $this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface')
98
            )
99
            ->will($this->returnCallback(static function (InputInterface $input, OutputInterface $output) : void {
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(
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 object<PHPUnit\Framework\MockObject\MockObject>, 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