Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

AdminBundle/Tests/Helper/Menu/MenuBuilderTest.php (15 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
     * @return \PHPUnit\Framework\MockObject\MockObject|MenuBuilder
20
     */
21
    public function setUpMenuBuilderMock(?array $methods)
22
    {
23
        $menuBuilderMock = $this->getMockBuilder(MenuBuilder::class)
24
            ->setConstructorArgs([$this->createMock(RequestStack::class)])
25
            ->setMethods($methods)
26
            ->getMock()
27
        ;
28
29
        return $menuBuilderMock;
30
    }
31
32
    /**
33
     * @group legacy
34
     * @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.
35
     */
36
    public function testConstructorContainerDeprecation()
37
    {
38
        $container = $this->createMock(ContainerInterface::class);
39
        new MenuBuilder($container);
40
    }
41
42
    public function testGetChildrenAndTopChildren()
43
    {
44
        $menuBuilderMock = $this->setUpMenuBuilderMock(null);
45
46
        /** @var MenuAdaptorInterface $menuAdaptorInterfaceMock */
47
        $menuAdaptorInterfaceMock = $this->createMock(MenuAdaptorInterface::class);
48
        $menuAdaptorInterfaceMock
0 ignored issues
show
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...
49
            ->expects($this->exactly(2))
50
            ->method('adaptChildren')
51
        ;
52
53
        $menuBuilderMock->addAdaptMenu($menuAdaptorInterfaceMock);
0 ignored issues
show
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...
54
55
        $menuItemMock = $this->createMock(MenuItem::class);
56
        $this->assertIsArray($menuBuilderMock->getChildren($menuItemMock));
0 ignored issues
show
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...
57
        $this->assertIsArray($menuBuilderMock->getChildren());
58
    }
59
60
    public function testGetCurrentAndBreadCrumb()
61
    {
62
        $menuItemMock = $this->createMock(MenuItem::class);
63
        $menuItemMock
64
            ->expects($this->any())
65
            ->method('getActive')
66
            ->willReturn(true)
67
        ;
68
69
        $menuBuilderMock = $this->setUpMenuBuilderMock(['getChildren']);
70
        $menuBuilderMock
0 ignored issues
show
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...
71
            ->expects($this->any())
72
            ->method('getChildren')
73
            ->will($this->onConsecutiveCalls([$menuItemMock], []))
74
        ;
75
76
        $current = $menuBuilderMock->getCurrent();
0 ignored issues
show
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...
77
        $this->assertInstanceOf(MenuItem::class, $current);
78
        $this->assertContainsOnlyInstancesOf(MenuItem::class, $menuBuilderMock->getBreadCrumb());
0 ignored issues
show
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...
79
    }
80
81
    public function testGetLowestTopChildWithCurrentTopMenuItem()
82
    {
83
        $menuItemMock = $this->createMock(TopMenuItem::class);
84
        $menuItemMock
85
            ->expects($this->any())
86
            ->method('getActive')
87
            ->willReturn(true)
88
        ;
89
90
        $menuBuilderMock = $this->setUpMenuBuilderMock(['getChildren']);
91
        $menuBuilderMock
0 ignored issues
show
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...
92
            ->expects($this->any())
93
            ->method('getChildren')
94
            ->will($this->onConsecutiveCalls([$menuItemMock], []))
95
        ;
96
97
        $this->assertInstanceOf(TopMenuItem::class, $menuBuilderMock->getLowestTopChild());
0 ignored issues
show
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...
98
    }
99
100
    public function testGetLowestTopChildWithMenuItem()
101
    {
102
        $menuItemMock = $this->createMock(MenuItem::class);
103
        $menuItemMock
104
            ->expects($this->any())
105
            ->method('getActive')
106
            ->willReturn(true)
107
        ;
108
        $menuItemMock
109
            ->expects($this->once())
110
            ->method('getParent')
111
            ->willReturn($this->createMock(TopMenuItem::class))
112
        ;
113
114
        $menuBuilderMock = $this->setUpMenuBuilderMock(['getChildren']);
115
        $menuBuilderMock
0 ignored issues
show
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...
116
            ->expects($this->any())
117
            ->method('getChildren')
118
            ->will($this->onConsecutiveCalls([$menuItemMock], []))
119
        ;
120
121
        $this->assertInstanceOf(TopMenuItem::class, $menuBuilderMock->getLowestTopChild());
0 ignored issues
show
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...
122
    }
123
124
    public function testGetLowestTopChildWithCurrentNull()
125
    {
126
        $menuItemMock = $this->createMock(TopMenuItem::class);
127
        $menuItemMock
128
            ->expects($this->any())
129
            ->method('getActive')
130
            ->willReturn(false)
131
        ;
132
133
        $menuBuilderMock = $this->setUpMenuBuilderMock(['getChildren']);
134
        $menuBuilderMock
0 ignored issues
show
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...
135
            ->expects($this->any())
136
            ->method('getChildren')
137
            ->will($this->onConsecutiveCalls([$menuItemMock], []))
138
        ;
139
140
        $this->assertNull($menuBuilderMock->getLowestTopChild());
0 ignored issues
show
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...
141
    }
142
143
    public function testGetTopChildren()
144
    {
145
        /** @var MenuAdaptorInterface $menuAdaptorInterfaceMock */
146
        $menuAdaptorInterfaceMock = $this->createMock(MenuAdaptorInterface::class);
147
        $menuAdaptorInterfaceMock
0 ignored issues
show
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...
148
            ->expects($this->once())
149
            ->method('adaptChildren')
150
        ;
151
152
        $menuBuilderMock = $this->setUpMenuBuilderMock(null);
153
        $menuBuilderMock->addAdaptMenu($menuAdaptorInterfaceMock);
0 ignored issues
show
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...
154
155
        $this->assertIsArray($menuBuilderMock->getTopChildren());
0 ignored issues
show
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...
156
    }
157
}
158