Completed
Push — master ( 2196f1...1dc6e5 )
by Jeroen
21s queued 13s
created

testConstructorContainerDeprecation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Kunstmaan\AdminBundle\Tests\Helper\Menu;
4
5
use Kunstmaan\AdminBundle\Helper\Menu\MenuAdaptorInterface;
6
use Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder;
7
use Kunstmaan\AdminBundle\Helper\Menu\MenuItem;
8
use Kunstmaan\AdminBundle\Helper\Menu\TopMenuItem;
9
use PHPUnit\Framework\TestCase;
10
use Symfony\Component\DependencyInjection\ContainerInterface;
11
use Symfony\Component\HttpFoundation\RequestStack;
12
13
/**
14
 * Class MenuBuilderTest
15
 */
16
class MenuBuilderTest extends TestCase
17
{
18
    /**
19
     * @param array|null $methods
20
     *
21
     * @return \PHPUnit\Framework\MockObject\MockObject|MenuBuilder
22
     */
23
    public function setUpMenuBuilderMock(?array $methods)
24
    {
25
        $menuBuilderMock = $this->getMockBuilder(MenuBuilder::class)
26
            ->setConstructorArgs([$this->createMock(RequestStack::class)])
27
            ->setMethods($methods)
28
            ->getMock()
29
        ;
30
31
        return $menuBuilderMock;
32
    }
33
34
    /**
35
     * @group legacy
36
     * @expectedDeprecation Passing the container as the first argument of "Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder" is deprecated in KunstmaanAdminBundle 5.4 and will be removed in KunstmaanAdminBundle 6.0. Inject the "request_stack" service instead.
37
     */
38
    public function testConstructorContainerDeprecation()
39
    {
40
        $container = $this->createMock(ContainerInterface::class);
41
        new MenuBuilder($container);
0 ignored issues
show
Documentation introduced by
$container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...oundation\RequestStack>.

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...
42
    }
43
44
    public function testGetChildrenAndTopChildren()
45
    {
46
        $menuBuilderMock = $this->setUpMenuBuilderMock(null);
47
48
        /** @var MenuAdaptorInterface $menuAdaptorInterfaceMock */
49
        $menuAdaptorInterfaceMock = $this->createMock(MenuAdaptorInterface::class);
50
        $menuAdaptorInterfaceMock
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Kunstmaan\AdminBu...u\MenuAdaptorInterface>.

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...
51
            ->expects($this->exactly(2))
52
            ->method('adaptChildren')
53
        ;
54
55
        $menuBuilderMock->addAdaptMenu($menuAdaptorInterfaceMock);
0 ignored issues
show
Bug introduced by
The method addAdaptMenu does only exist in Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder, but not in PHPUnit\Framework\MockObject\MockObject.

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...
56
57
        $menuItemMock = $this->createMock(MenuItem::class);
58
        $this->assertIsArray($menuBuilderMock->getChildren($menuItemMock));
0 ignored issues
show
Documentation introduced by
$menuItemMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Kunstmaan\Ad...e\Helper\Menu\MenuItem>.

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...
Bug introduced by
The method getChildren does only exist in Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder, but not in PHPUnit\Framework\MockObject\MockObject.

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...
59
        $this->assertIsArray($menuBuilderMock->getChildren());
60
    }
61
62
    public function testGetCurrentAndBreadCrumb()
63
    {
64
        $menuItemMock = $this->createMock(MenuItem::class);
65
        $menuItemMock
66
            ->expects($this->any())
67
            ->method('getActive')
68
            ->willReturn(true)
69
        ;
70
71
        $menuBuilderMock = $this->setUpMenuBuilderMock(['getChildren']);
72
        $menuBuilderMock
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder.

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...
73
            ->expects($this->any())
74
            ->method('getChildren')
75
            ->will($this->onConsecutiveCalls([$menuItemMock], []))
76
        ;
77
78
        $current = $menuBuilderMock->getCurrent();
0 ignored issues
show
Bug introduced by
The method getCurrent does only exist in Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder, but not in PHPUnit\Framework\MockObject\MockObject.

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...
79
        $this->assertInstanceOf(MenuItem::class, $current);
80
        $this->assertContainsOnlyInstancesOf(MenuItem::class, $menuBuilderMock->getBreadCrumb());
0 ignored issues
show
Bug introduced by
The method getBreadCrumb does only exist in Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder, but not in PHPUnit\Framework\MockObject\MockObject.

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...
81
    }
82
83
    public function testGetLowestTopChildWithCurrentTopMenuItem()
84
    {
85
        $menuItemMock = $this->createMock(TopMenuItem::class);
86
        $menuItemMock
87
            ->expects($this->any())
88
            ->method('getActive')
89
            ->willReturn(true)
90
        ;
91
92
        $menuBuilderMock = $this->setUpMenuBuilderMock(['getChildren']);
93
        $menuBuilderMock
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder.

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...
94
            ->expects($this->any())
95
            ->method('getChildren')
96
            ->will($this->onConsecutiveCalls([$menuItemMock], []))
97
        ;
98
99
        $this->assertInstanceOf(TopMenuItem::class, $menuBuilderMock->getLowestTopChild());
0 ignored issues
show
Bug introduced by
The method getLowestTopChild does only exist in Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder, but not in PHPUnit\Framework\MockObject\MockObject.

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...
100
    }
101
102
    public function testGetLowestTopChildWithMenuItem()
103
    {
104
        $menuItemMock = $this->createMock(MenuItem::class);
105
        $menuItemMock
106
            ->expects($this->any())
107
            ->method('getActive')
108
            ->willReturn(true)
109
        ;
110
        $menuItemMock
111
            ->expects($this->once())
112
            ->method('getParent')
113
            ->willReturn($this->createMock(TopMenuItem::class))
114
        ;
115
116
        $menuBuilderMock = $this->setUpMenuBuilderMock(['getChildren']);
117
        $menuBuilderMock
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder.

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...
118
            ->expects($this->any())
119
            ->method('getChildren')
120
            ->will($this->onConsecutiveCalls([$menuItemMock], []))
121
        ;
122
123
        $this->assertInstanceOf(TopMenuItem::class, $menuBuilderMock->getLowestTopChild());
0 ignored issues
show
Bug introduced by
The method getLowestTopChild does only exist in Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder, but not in PHPUnit\Framework\MockObject\MockObject.

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...
124
    }
125
126
    public function testGetLowestTopChildWithCurrentNull()
127
    {
128
        $menuItemMock = $this->createMock(TopMenuItem::class);
129
        $menuItemMock
130
            ->expects($this->any())
131
            ->method('getActive')
132
            ->willReturn(false)
133
        ;
134
135
        $menuBuilderMock = $this->setUpMenuBuilderMock(['getChildren']);
136
        $menuBuilderMock
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder.

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...
137
            ->expects($this->any())
138
            ->method('getChildren')
139
            ->will($this->onConsecutiveCalls([$menuItemMock], []))
140
        ;
141
142
        $this->assertNull($menuBuilderMock->getLowestTopChild());
0 ignored issues
show
Bug introduced by
The method getLowestTopChild does only exist in Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder, but not in PHPUnit\Framework\MockObject\MockObject.

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...
143
    }
144
145
    public function testGetTopChildren()
146
    {
147
        /** @var MenuAdaptorInterface $menuAdaptorInterfaceMock */
148
        $menuAdaptorInterfaceMock = $this->createMock(MenuAdaptorInterface::class);
149
        $menuAdaptorInterfaceMock
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Kunstmaan\AdminBu...u\MenuAdaptorInterface>.

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...
150
            ->expects($this->once())
151
            ->method('adaptChildren')
152
        ;
153
154
        $menuBuilderMock = $this->setUpMenuBuilderMock(null);
155
        $menuBuilderMock->addAdaptMenu($menuAdaptorInterfaceMock);
0 ignored issues
show
Bug introduced by
The method addAdaptMenu does only exist in Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder, but not in PHPUnit\Framework\MockObject\MockObject.

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...
156
157
        $this->assertIsArray($menuBuilderMock->getTopChildren());
0 ignored issues
show
Bug introduced by
The method getTopChildren does only exist in Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder, but not in PHPUnit\Framework\MockObject\MockObject.

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...
158
    }
159
}
160