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