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.

unit/Service/EntityVersionLockServiceTest.php (13 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\AdminListBundle\Tests\Service;
4
5
use Kunstmaan\AdminBundle\Entity\User;
6
use Kunstmaan\AdminListBundle\Entity\EntityVersionLock;
7
use Kunstmaan\AdminListBundle\Entity\LockableEntity;
8
use Kunstmaan\AdminListBundle\Service\EntityVersionLockService;
9
use Kunstmaan\AdminListBundle\Tests\unit\Model\TestLockableEntityInterfaceImplementation;
10
use PHPUnit\Framework\TestCase;
11
12
/**
13
 * class EntityVersionLockServiceTest
14
 */
15
class EntityVersionLockServiceTest extends TestCase
16
{
17
    protected static $TEST_CLASS = 'Kunstmaan\\AdminListBundle\\Tests\\unit\\Model\\TestLockableEntityInterfaceImplementation';
18
19
    protected static $TEST_NEW_ENTITY_ID = '1';
20
21
    protected static $TEST_ID = '5';
22
23
    protected static $TEST_ENTITY_ID = '5';
24
25
    protected static $ALTERNATIVE_TEST_ID = '391';
26
27
    protected static $ALTERNATIVE_TEST_ENTITY_ID = '391';
28
29
    protected static $USER_ID = '104';
30
31
    protected static $USER_NAME = 'Kevin Test';
32
33
    protected static $ALTERNATIVE_USER = 'Alternative Test';
34
35
    protected static $THRESHOLD = 35;
36
37
    /**
38
     * @var EntityVersionLockService
39
     */
40
    protected $object;
41
42
    /**
43
     * @var User
44
     */
45
    protected $user;
46
47
    /**
48
     * Sets up the fixture, for example, opens a network connection.
49
     * This method is called before a test is executed.
50
     */
51
    protected function setUp(): void
52
    {
53
        $user = new User();
54
        $user->setId(self::$USER_ID);
55
        $user->setUsername(self::$USER_NAME);
56
        $this->user = $user;
57
58
        $newEntity = $this->getMockBuilder(LockableEntity::class)->getMock();
59
        $newEntity->method('getId')->willReturn(null);
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
60
        $newEntity->method('getEntityClass')->willReturn(self::$TEST_CLASS);
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
61
        $newEntity->method('getEntityId')->willReturn(self::$TEST_NEW_ENTITY_ID);
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
62
        $newEntity->method('getUpdated')->willReturn(new \DateTime());
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
63
64
        $entity = $this->getMockBuilder(LockableEntity::class)->getMock();
65
        $entity->method('getId')->willReturn(self::$TEST_ID);
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
66
        $entity->method('getEntityClass')->willReturn(self::$TEST_CLASS);
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
67
        $entity->method('getEntityId')->willReturn(self::$TEST_ENTITY_ID);
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
68
        $entity->method('getUpdated')->willReturn(new \DateTime());
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
69
70
        $outDatedEntity = $this->getMockBuilder(LockableEntity::class)->getMock();
71
        $outDatedEntity->method('getId')->willReturn(self::$ALTERNATIVE_TEST_ID);
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
72
        $outDatedEntity->method('getEntityClass')->willReturn(self::$TEST_CLASS);
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
73
        $outDatedEntity->method('getEntityId')->willReturn(self::$ALTERNATIVE_TEST_ENTITY_ID);
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
74
        $outDatedEntity->method('getUpdated')->willReturn(new \DateTime('-1 days'));
75
76
        $newEntityVersionLock = new EntityVersionLock();
77
        $newEntityVersionLock->setOwner(self::$ALTERNATIVE_USER);
78
        $newEntityVersionLock->setLockableEntity($newEntity);
0 ignored issues
show
$newEntity is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\AdminLi...\Entity\LockableEntity>.

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...
79
        $newEntityVersionLock->setCreatedAt(new \DateTime());
80
81
        $entityVersionLock = new EntityVersionLock();
82
        $entityVersionLock->setOwner(self::$ALTERNATIVE_USER);
83
        $entityVersionLock->setLockableEntity($entity);
84
        $entityVersionLock->setCreatedAt(new \DateTime());
85
86
        $expiredEntityVersionLock = new EntityVersionLock();
87
        $expiredEntityVersionLock->setOwner($user->getUsername());
88
        $expiredEntityVersionLock->setLockableEntity($outDatedEntity);
0 ignored issues
show
$outDatedEntity is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\AdminLi...\Entity\LockableEntity>.

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...
89
        $expiredEntityVersionLock->setCreatedAt(new \DateTime('-1 days'));
90
91
        $locksMap = [
92
            [$newEntity, self::$THRESHOLD, $this->user, [$newEntityVersionLock]],
93
            [$entity, self::$THRESHOLD, $this->user, [$entityVersionLock]],
94
            [$outDatedEntity, self::$THRESHOLD, $this->user, []],
95
        ];
96
        $mockLockRepository = $this->getMockBuilder('Kunstmaan\AdminListBundle\Repository\EntityVersionLockRepository')
97
            ->disableOriginalConstructor()
98
            ->getMock();
99
        $mockLockRepository
100
            ->expects($this->any())
101
            ->method('findOneBy')
102
            ->will($this->returnValue($entityVersionLock));
103
        $mockLockRepository
104
            ->expects($this->any())
105
            ->method('getExpiredLocks')
106
            ->will($this->returnValue([$expiredEntityVersionLock]));
107
        $mockLockRepository
108
            ->expects($this->any())
109
            ->method('getLocksForLockableEntity')
110
            ->will($this->returnValueMap($locksMap));
111
112
        $lockableMap = [
113
            [self::$TEST_NEW_ENTITY_ID, self::$TEST_CLASS, $newEntity],
114
            [self::$TEST_ENTITY_ID, self::$TEST_CLASS, $entity],
115
            [self::$ALTERNATIVE_TEST_ENTITY_ID, self::$TEST_CLASS, $outDatedEntity],
116
        ];
117
        $mockLockableRepository = $this->getMockBuilder('Kunstmaan\AdminListBundle\Repository\LockableEntityRepository')
118
            ->disableOriginalConstructor()
119
            ->getMock();
120
        $mockLockableRepository
121
            ->expects($this->any())
122
            ->method('getOrCreate')
123
            ->will($this->returnValueMap($lockableMap));
124
125
        $repositoryMap = [
126
            [EntityVersionLock::class, $mockLockRepository],
127
            [LockableEntity::class, $mockLockableRepository],
128
        ];
129
        $mockObjectManager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')
130
            ->disableOriginalConstructor()
131
            ->getMock();
132
        $mockObjectManager
133
            ->expects($this->any())
134
            ->method('getRepository')
135
            ->will($this->returnValueMap($repositoryMap));
136
137
        $this->object = new EntityVersionLockService($mockObjectManager, self::$THRESHOLD, true);
138
    }
139
140
    public function testIsEntityBelowThresholdReturnsFalseWhenLockIsNew()
141
    {
142
        $result = $this->object->isEntityBelowThreshold(new TestLockableEntityInterfaceImplementation(self::$TEST_NEW_ENTITY_ID));
143
144
        $this->assertFalse($result);
145
    }
146
147
    public function testIsEntityBelowThresholdReturnsTrueWhenEntityUpdatedAtIsBelowThreshold()
148
    {
149
        $result = $this->object->isEntityBelowThreshold(new TestLockableEntityInterfaceImplementation(self::$TEST_ENTITY_ID));
150
151
        $this->assertTrue($result);
152
    }
153
154
    public function testIsEntityBelowThresholdReturnsFalseWhenEntityUpdatedAtIsOverTreshold()
155
    {
156
        $result = $this->object->isEntityBelowThreshold(new TestLockableEntityInterfaceImplementation(self::$ALTERNATIVE_TEST_ENTITY_ID));
157
158
        $this->assertFalse($result);
159
    }
160
161
    public function testIsEntityLockedReturnsTrueWhenEntityLocked()
162
    {
163
        $result = $this->object->isEntityLocked($this->user, new TestLockableEntityInterfaceImplementation(self::$TEST_ENTITY_ID));
164
165
        $this->assertTrue($result);
166
    }
167
168
    public function testIsEntityLockedReturnsFalseWhenEntityIsNotLocked()
169
    {
170
        $result = $this->object->isEntityLocked($this->user, new TestLockableEntityInterfaceImplementation(self::$ALTERNATIVE_TEST_ENTITY_ID));
171
172
        $this->assertFalse($result);
173
    }
174
175
    public function testGetUsersWithEntityVersionLockReturnsArrayWithOnlyUsernames()
176
    {
177
        $result = $this->object->getUsersWithEntityVersionLock(new TestLockableEntityInterfaceImplementation(self::$TEST_ENTITY_ID), $this->user);
178
179
        $this->assertContains(self::$ALTERNATIVE_USER, $result);
180
    }
181
}
182