Issues (220)

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/RegistryTest.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 Doctrine\Bundle\DoctrineBundle\Tests;
4
5
use Closure;
6
use Doctrine\Bundle\DoctrineBundle\Registry;
7
use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures\TestKernel;
8
use Doctrine\ORM\EntityManagerInterface;
9
use Fixtures\Bundles\RepositoryServiceBundle\Entity\TestCustomClassRepoEntity;
10
use Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomClassRepoRepository;
11
use ProxyManager\Proxy\LazyLoadingInterface;
12
use ProxyManager\Proxy\ProxyInterface;
13
use stdClass;
14
15
class RegistryTest extends TestCase
16
{
17 View Code Duplication
    public function testGetDefaultConnectionName() : void
18
    {
19
        $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
20
        $registry  = new Registry($container, [], [], 'default', 'default');
21
22
        $this->assertEquals('default', $registry->getDefaultConnectionName());
23
    }
24
25 View Code Duplication
    public function testGetDefaultEntityManagerName() : void
26
    {
27
        $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
28
        $registry  = new Registry($container, [], [], 'default', 'default');
29
30
        $this->assertEquals('default', $registry->getDefaultManagerName());
31
    }
32
33 View Code Duplication
    public function testGetDefaultConnection() : void
34
    {
35
        $conn      = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
36
        $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
37
        $container->expects($this->once())
38
                  ->method('get')
39
                  ->with($this->equalTo('doctrine.dbal.default_connection'))
40
                  ->will($this->returnValue($conn));
41
42
        $registry = new Registry($container, ['default' => 'doctrine.dbal.default_connection'], [], 'default', 'default');
43
44
        $this->assertSame($conn, $registry->getConnection());
45
    }
46
47 View Code Duplication
    public function testGetConnection() : void
48
    {
49
        $conn      = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
50
        $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
51
        $container->expects($this->once())
52
                  ->method('get')
53
                  ->with($this->equalTo('doctrine.dbal.default_connection'))
54
                  ->will($this->returnValue($conn));
55
56
        $registry = new Registry($container, ['default' => 'doctrine.dbal.default_connection'], [], 'default', 'default');
57
58
        $this->assertSame($conn, $registry->getConnection('default'));
59
    }
60
61
    /**
62
     * @expectedException \InvalidArgumentException
63
     * @expectedExceptionMessage Doctrine ORM Connection named "default" does not exist.
64
     */
65 View Code Duplication
    public function testGetUnknownConnection() : void
66
    {
67
        $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
68
        $registry  = new Registry($container, [], [], 'default', 'default');
69
70
        $registry->getConnection('default');
71
    }
72
73
    public function testGetConnectionNames() : void
74
    {
75
        $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
76
        $registry  = new Registry($container, ['default' => 'doctrine.dbal.default_connection'], [], 'default', 'default');
77
78
        $this->assertEquals(['default' => 'doctrine.dbal.default_connection'], $registry->getConnectionNames());
79
    }
80
81 View Code Duplication
    public function testGetDefaultEntityManager() : void
82
    {
83
        $em        = new stdClass();
84
        $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
85
        $container->expects($this->once())
86
                  ->method('get')
87
                  ->with($this->equalTo('doctrine.orm.default_entity_manager'))
88
                  ->will($this->returnValue($em));
89
90
        $registry = new Registry($container, [], ['default' => 'doctrine.orm.default_entity_manager'], 'default', 'default');
91
92
        $this->assertSame($em, $registry->getManager());
93
    }
94
95 View Code Duplication
    public function testGetEntityManager() : void
96
    {
97
        $em        = new stdClass();
98
        $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
99
        $container->expects($this->once())
100
                  ->method('get')
101
                  ->with($this->equalTo('doctrine.orm.default_entity_manager'))
102
                  ->will($this->returnValue($em));
103
104
        $registry = new Registry($container, [], ['default' => 'doctrine.orm.default_entity_manager'], 'default', 'default');
105
106
        $this->assertSame($em, $registry->getManager('default'));
107
    }
108
109
    /**
110
     * @expectedException \InvalidArgumentException
111
     * @expectedExceptionMessage Doctrine ORM Manager named "default" does not exist.
112
     */
113 View Code Duplication
    public function testGetUnknownEntityManager() : void
114
    {
115
        $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
116
        $registry  = new Registry($container, [], [], 'default', 'default');
117
118
        $registry->getManager('default');
119
    }
120
121
    /**
122
     * @expectedException \InvalidArgumentException
123
     * @expectedExceptionMessage Doctrine ORM Manager named "default" does not exist.
124
     */
125 View Code Duplication
    public function testResetUnknownEntityManager() : void
126
    {
127
        $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
128
        $registry  = new Registry($container, [], [], 'default', 'default');
129
130
        $registry->resetManager('default');
131
    }
132
133
    public function testReset() : void
134
    {
135
        $noProxyManager = $this->getMockBuilder(EntityManagerInterface::class)->getMock();
136
        $noProxyManager->expects($this->once())
137
            ->method('clear');
138
139
        $proxyManager = $this->getMockBuilder([LazyLoadingInterface::class, EntityManagerInterface::class])->getMock();
140
        $proxyManager->expects($this->once())
141
            ->method('setProxyInitializer')
142
            ->with($this->isInstanceOf(Closure::class));
143
144
        $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
145
        $container->expects($this->any())
146
            ->method('initialized')
147
            ->withConsecutive(['doctrine.orm.uninitialized_entity_manager'], ['doctrine.orm.noproxy_entity_manager'], ['doctrine.orm.proxy_entity_manager'])
148
            ->willReturnOnConsecutiveCalls(false, true, true, true);
149
150
        $container->expects($this->any())
151
            ->method('get')
152
            ->withConsecutive(['doctrine.orm.noproxy_entity_manager'], ['doctrine.orm.proxy_entity_manager'], ['doctrine.orm.proxy_entity_manager'])
153
            ->willReturnOnConsecutiveCalls($noProxyManager, $proxyManager, $proxyManager);
154
155
        $entityManagers = [
156
            'uninitialized' => 'doctrine.orm.uninitialized_entity_manager',
157
            'noproxy' => 'doctrine.orm.noproxy_entity_manager',
158
            'proxy' => 'doctrine.orm.proxy_entity_manager',
159
        ];
160
161
        $registry = new Registry($container, [], $entityManagers, 'default', 'default');
0 ignored issues
show
$container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Container\ContainerInterface>.

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...
162
        $registry->reset();
163
    }
164
165
    public function testIdentityMapsStayConsistentAfterReset()
166
    {
167
        $kernel = new TestKernel();
168
        $kernel->boot();
169
170
        $container     = $kernel->getContainer();
171
        $registry      = $container->get('doctrine');
172
        $entityManager = $container->get('doctrine.orm.default_entity_manager');
173
        $repository    = $entityManager->getRepository(TestCustomClassRepoEntity::class);
174
175
        $this->assertInstanceOf(ProxyInterface::class, $entityManager);
176
        assert($entityManager instanceof EntityManagerInterface);
177
        assert($registry instanceof Registry);
178
        assert($repository instanceof TestCustomClassRepoRepository);
179
180
        $entity = new TestCustomClassRepoEntity();
181
        $repository->getEntityManager()->persist($entity);
182
183
        $this->assertTrue($entityManager->getUnitOfWork()->isEntityScheduled($entity));
184
        $this->assertTrue($repository->getEntityManager()->getUnitOfWork()->isEntityScheduled($entity));
185
186
        $registry->reset();
187
188
        $this->assertFalse($entityManager->getUnitOfWork()->isEntityScheduled($entity));
189
        $this->assertFalse($repository->getEntityManager()->getUnitOfWork()->isEntityScheduled($entity));
190
191
        $entityManager->flush();
192
    }
193
}
194