Completed
Push — master ( ab1be0...645350 )
by Андрей
03:27 queued 01:20
created

ModuleTest::testLoadModule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/entry-name-resolver
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\EntryNameResolver\PhpUnit\Test;
7
8
use Nnx\EntryNameResolver\PhpUnit\TestData\TestPaths;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
11
use Nnx\EntryNameResolver\Module;
12
use Zend\ModuleManager\ModuleManagerInterface;
13
use Zend\ModuleManager\ModuleManager;
14
use Zend\ModuleManager\ModuleEvent;
15
16
/**
17
 * Class ModuleTest
18
 *
19
 * @package Nnx\EntryNameResolver\PhpUnit\Test
20
 */
21
class ModuleTest extends AbstractHttpControllerTestCase
22
{
23
    /**
24
     * Установка окружения
25
     *
26
     * @throws \Zend\Stdlib\Exception\LogicException
27
     */
28
    public function setUp()
29
    {
30
        /** @noinspection PhpIncludeInspection */
31
        $this->setApplicationConfig(
32
            include TestPaths::getPathToDefaultAppConfig()
33
        );
34
35
        parent::setUp();
36
    }
37
38
    /**
39
     * Проверка что модуль загружается
40
     *
41
     * @return void
42
     */
43
    public function testLoadModule()
44
    {
45
        $this->assertModulesLoaded([Module::MODULE_NAME]);
46
    }
47
48
    /**
49
     * Проверка ситуации когда в модуль придет некорректный ModuleManager
50
     *
51
     * @expectedException \Nnx\EntryNameResolver\Exception\InvalidArgumentException
52
     * @expectedExceptionMessage Module manager not implement Zend\ModuleManager\ModuleManager
53
     *
54
     * @throws \PHPUnit_Framework_Exception
55
     * @throws \Nnx\EntryNameResolver\Exception\InvalidArgumentException
56
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
57
     */
58
    public function testInvalidModuleManager()
59
    {
60
        $module = new Module();
61
        /** @var ModuleManagerInterface $moduleManagerMock */
62
        $moduleManagerMock = $this->getMock(ModuleManagerInterface::class);
63
64
        $module->init($moduleManagerMock);
65
    }
66
67
68
69
    /**
70
     * Проверка ситуации когда не удается получить ServiceLocator
71
     *
72
     * @expectedException \Nnx\EntryNameResolver\Exception\InvalidArgumentException
73
     * @expectedExceptionMessage Service locator not implement Zend\ServiceManager\ServiceLocatorInterface
74
     *
75
     * @throws \PHPUnit_Framework_Exception
76
     * @throws \Nnx\EntryNameResolver\Exception\InvalidArgumentException
77
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
78
     */
79
    public function testInvalidServiceManager()
80
    {
81
        $module = new Module();
82
        /** @var ModuleManager|\PHPUnit_Framework_MockObject_MockObject $moduleManagerMock */
83
        $moduleManagerMock = $this->getMock(ModuleManager::class, [], [], '', false);
84
85
        /** @var ModuleEvent|\PHPUnit_Framework_MockObject_MockObject $eventMock */
86
        $eventMock = $this->getMock(ModuleEvent::class);
87
        $eventMock->expects(static::once())->method('getParam')->with(static::equalTo('ServiceManager'))->will(static::returnValue(null));
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Zend\ModuleManager\ModuleEvent.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
88
89
        $moduleManagerMock->expects(static::once())->method('getEvent')->will(static::returnValue($eventMock));
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Zend\ModuleManager\ModuleManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
90
91
        $module->init($moduleManagerMock);
92
    }
93
94
95
96
    /**
97
     * Проверка ситуации когда не удается получить ServiceListener
98
     *
99
     * @expectedException \Nnx\EntryNameResolver\Exception\InvalidArgumentException
100
     * @expectedExceptionMessage ServiceListener not implement Zend\ModuleManager\Listener\ServiceListenerInterface
101
     *
102
     * @throws \PHPUnit_Framework_Exception
103
     * @throws \Nnx\EntryNameResolver\Exception\InvalidArgumentException
104
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
105
     */
106
    public function testInvalidServiceListener()
107
    {
108
        $module = new Module();
109
        /** @var ModuleManager|\PHPUnit_Framework_MockObject_MockObject $moduleManagerMock */
110
        $moduleManagerMock = $this->getMock(ModuleManager::class, [], [], '', false);
111
112
        /** @var ModuleEvent|\PHPUnit_Framework_MockObject_MockObject $eventMock */
113
        $eventMock = $this->getMock(ModuleEvent::class);
114
        $moduleManagerMock->expects(static::once())->method('getEvent')->will(static::returnValue($eventMock));
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Zend\ModuleManager\ModuleManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
115
116
        /** @var ServiceLocatorInterface||\PHPUnit_Framework_MockObject_MockObject $slMock */
0 ignored issues
show
Documentation introduced by
The doc-type ServiceLocatorInterface|...k_MockObject_MockObject could not be parsed: Unknown type name "|" at position 24. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
117
        $slMock = $this->getMock(ServiceLocatorInterface::class);
118
        $slMock->expects(static::once())->method('get')->with(static::equalTo('ServiceListener'))->will(static::returnValue(null));
119
120
        $eventMock->expects(static::once())->method('getParam')->with(static::equalTo('ServiceManager'))->will(static::returnValue($slMock));
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Zend\ModuleManager\ModuleEvent.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
121
122
123
        $module->init($moduleManagerMock);
124
    }
125
}
126