Issues (3099)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Tests/unit/Helper/Menu/MenuBuilderTest.php (1 issue)

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
     * @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)
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/pull/3687

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
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);
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
51
            ->expects($this->exactly(2))
52
            ->method('adaptChildren')
53
        ;
54
55
        $menuBuilderMock->addAdaptMenu($menuAdaptorInterfaceMock);
56
57
        $menuItemMock = $this->createMock(MenuItem::class);
58
        $this->assertIsArray($menuBuilderMock->getChildren($menuItemMock));
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
73
            ->expects($this->any())
74
            ->method('getChildren')
75
            ->will($this->onConsecutiveCalls([$menuItemMock], []))
76
        ;
77
78
        $current = $menuBuilderMock->getCurrent();
79
        $this->assertInstanceOf(MenuItem::class, $current);
80
        $this->assertContainsOnlyInstancesOf(MenuItem::class, $menuBuilderMock->getBreadCrumb());
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
94
            ->expects($this->any())
95
            ->method('getChildren')
96
            ->will($this->onConsecutiveCalls([$menuItemMock], []))
97
        ;
98
99
        $this->assertInstanceOf(TopMenuItem::class, $menuBuilderMock->getLowestTopChild());
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
118
            ->expects($this->any())
119
            ->method('getChildren')
120
            ->will($this->onConsecutiveCalls([$menuItemMock], []))
121
        ;
122
123
        $this->assertInstanceOf(TopMenuItem::class, $menuBuilderMock->getLowestTopChild());
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
137
            ->expects($this->any())
138
            ->method('getChildren')
139
            ->will($this->onConsecutiveCalls([$menuItemMock], []))
140
        ;
141
142
        $this->assertNull($menuBuilderMock->getLowestTopChild());
143
    }
144
145
    public function testGetTopChildren()
146
    {
147
        /** @var MenuAdaptorInterface $menuAdaptorInterfaceMock */
148
        $menuAdaptorInterfaceMock = $this->createMock(MenuAdaptorInterface::class);
149
        $menuAdaptorInterfaceMock
150
            ->expects($this->once())
151
            ->method('adaptChildren')
152
        ;
153
154
        $menuBuilderMock = $this->setUpMenuBuilderMock(null);
155
        $menuBuilderMock->addAdaptMenu($menuAdaptorInterfaceMock);
156
157
        $this->assertIsArray($menuBuilderMock->getTopChildren());
158
    }
159
}
160