ModuleTest::testGetConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
19
namespace ZfrCorsTest;
20
21
use PHPUnit\Framework\TestCase;
22
use ZfrCors\Module;
23
24
/**
25
 * Tests for {@see \ZfrCors\Module}
26
 *
27
 * @license MIT
28
 * @author  Marco Pivetta <[email protected]>
29
 *
30
 * @group Coverage
31
 */
32
class ModuleTest extends \PHPUnit\Framework\TestCase
33
{
34
    /**
35
     * @covers \ZfrCors\Module::getConfig
36
     */
37
    public function testGetConfig()
38
    {
39
        $module = new Module();
40
41
        $this->assertIsArray($module->getConfig());
42
        $this->assertSame($module->getConfig(), unserialize(serialize($module->getConfig())), 'Config is serializable');
43
    }
44
45
    /**
46
     * @covers \ZfrCors\Module::onBootstrap
47
     */
48
    public function testAssertListenerIsCorrectlyRegistered()
49
    {
50
        $module         = new Module();
51
        $mvcEvent       = $this->getMockBuilder('Zend\Mvc\MvcEvent')->getMock();
52
        $application    = $this->getMockBuilder('Zend\Mvc\Application', [], [], '', false)
0 ignored issues
show
Unused Code introduced by
The call to ModuleTest::getMockBuilder() has too many arguments starting with array().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
53
            ->disableOriginalConstructor()
54
            ->getMock();
55
        $eventManager   = $this->getMockBuilder('Zend\EventManager\EventManagerInterface')->getMock();
56
        $serviceManager = $this->getMockBuilder('Zend\ServiceManager\ServiceManager')->getMock();
57
        $corsListener   = $this->getMockBuilder('ZfrCors\Mvc\CorsRequestListener', [], [], '', false)
0 ignored issues
show
Unused Code introduced by
The call to ModuleTest::getMockBuilder() has too many arguments starting with array().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
58
            ->disableOriginalConstructor()
59
            ->getMock();
60
61
        $mvcEvent->expects($this->any())->method('getTarget')->will($this->returnValue($application));
62
        $application->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
63
        $application->expects($this->any())->method('getServiceManager')->will($this->returnValue($serviceManager));
64
        $serviceManager
65
            ->expects($this->any())
66
            ->method('get')
67
            ->with('ZfrCors\Mvc\CorsRequestListener')
68
            ->will($this->returnValue($corsListener));
69
70
        $corsListener->expects($this->once())->method('attach')->with($eventManager);
71
72
        $module->onBootstrap($mvcEvent);
0 ignored issues
show
Documentation introduced by
$mvcEvent is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Zend\EventManager\EventInterface>.

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...
73
    }
74
}
75