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.

Repository/ContainerRepositoryFactoryTest.php (17 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 Doctrine\Bundle\DoctrineBundle\Tests\Repository;
4
5
use Doctrine\Bundle\DoctrineBundle\Repository\ContainerRepositoryFactory;
6
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
7
use Doctrine\ORM\Configuration;
8
use Doctrine\ORM\EntityManagerInterface;
9
use Doctrine\ORM\EntityRepository;
10
use Doctrine\ORM\Mapping\ClassMetadata;
11
use Doctrine\Persistence\ObjectRepository;
12
use PHPUnit\Framework\MockObject\MockObject;
13
use PHPUnit\Framework\TestCase;
14
use Psr\Container\ContainerInterface;
15
use stdClass;
16
17
class ContainerRepositoryFactoryTest extends TestCase
18
{
19
    public function testGetRepositoryReturnsService() : void
20
    {
21
        $em        = $this->createEntityManager(['Foo\CoolEntity' => 'my_repo']);
22
        $repo      = new StubRepository();
23
        $container = $this->createContainer(['my_repo' => $repo]);
24
25
        $factory = new ContainerRepositoryFactory($container);
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...
26
        $this->assertSame($repo, $factory->getRepository($em, 'Foo\CoolEntity'));
0 ignored issues
show
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

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...
27
    }
28
29
    public function testGetRepositoryReturnsEntityRepository() : void
30
    {
31
        $container = $this->createContainer([]);
32
        $em        = $this->createEntityManager(['Foo\BoringEntity' => null]);
33
34
        $factory    = new ContainerRepositoryFactory($container);
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...
35
        $actualRepo = $factory->getRepository($em, 'Foo\BoringEntity');
0 ignored issues
show
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

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...
36
        $this->assertInstanceOf(EntityRepository::class, $actualRepo);
37
        // test the same instance is returned
38
        $this->assertSame($actualRepo, $factory->getRepository($em, 'Foo\BoringEntity'));
0 ignored issues
show
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

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...
39
    }
40
41
    public function testCustomRepositoryIsReturned() : void
42
    {
43
        $container = $this->createContainer([]);
44
        $em        = $this->createEntityManager([
45
            'Foo\CustomNormalRepoEntity' => StubRepository::class,
46
        ]);
47
48
        $factory    = new ContainerRepositoryFactory($container);
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...
49
        $actualRepo = $factory->getRepository($em, 'Foo\CustomNormalRepoEntity');
0 ignored issues
show
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

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...
50
        $this->assertInstanceOf(StubRepository::class, $actualRepo);
51
        // test the same instance is returned
52
        $this->assertSame($actualRepo, $factory->getRepository($em, 'Foo\CustomNormalRepoEntity'));
0 ignored issues
show
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

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...
53
    }
54
55
    /**
56
     * @expectedException \RuntimeException
57
     * @expectedExceptionMessage The service "my_repo" must implement ObjectRepository (or extend a base class, like ServiceEntityRepository).
58
     */
59
    public function testServiceRepositoriesMustExtendObjectRepository() : void
60
    {
61
        $repo = new stdClass();
62
63
        $container = $this->createContainer(['my_repo' => $repo]);
64
65
        $em = $this->createEntityManager(['Foo\CoolEntity' => 'my_repo']);
66
67
        $factory = new ContainerRepositoryFactory($container);
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...
68
        $factory->getRepository($em, 'Foo\CoolEntity');
0 ignored issues
show
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

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...
69
    }
70
71
    public function testServiceRepositoriesCanNotExtendsEntityRepository() : void
72
    {
73
        $repo = $this->getMockBuilder(ObjectRepository::class)->getMock();
74
75
        $container = $this->createContainer(['my_repo' => $repo]);
76
77
        $em = $this->createEntityManager(['Foo\CoolEntity' => 'my_repo']);
78
79
        $factory = new ContainerRepositoryFactory($container);
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...
80
        $factory->getRepository($em, 'Foo\CoolEntity');
0 ignored issues
show
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

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...
81
        $actualRepo = $factory->getRepository($em, 'Foo\CoolEntity');
0 ignored issues
show
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

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...
82
        $this->assertSame($repo, $actualRepo);
83
    }
84
85
    /**
86
     * @expectedException \RuntimeException
87
     * @expectedExceptionMessage The "Doctrine\Bundle\DoctrineBundle\Tests\Repository\StubServiceRepository" entity repository implements "Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface", but its service could not be found. Make sure the service exists and is tagged with "doctrine.repository_service".
88
     */
89
    public function testRepositoryMatchesServiceInterfaceButServiceNotFound() : void
90
    {
91
        $container = $this->createContainer([]);
92
93
        $em = $this->createEntityManager([
94
            'Foo\CoolEntity' => StubServiceRepository::class,
95
        ]);
96
97
        $factory = new ContainerRepositoryFactory($container);
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...
98
        $factory->getRepository($em, 'Foo\CoolEntity');
0 ignored issues
show
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

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...
99
    }
100
101
    /**
102
     * @expectedException \RuntimeException
103
     * @expectedExceptionMessage The "Foo\CoolEntity" entity has a repositoryClass set to "not_a_real_class", but this is not a valid class. Check your class naming. If this is meant to be a service id, make sure this service exists and is tagged with "doctrine.repository_service".
104
     */
105
    public function testCustomRepositoryIsNotAValidClass() : void
106
    {
107
        $container = $this->createContainer([]);
108
109
        $em = $this->createEntityManager(['Foo\CoolEntity' => 'not_a_real_class']);
110
111
        $factory = new ContainerRepositoryFactory($container);
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...
112
        $factory->getRepository($em, 'Foo\CoolEntity');
0 ignored issues
show
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

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...
113
    }
114
115
    private function createContainer(array $services) : MockObject
116
    {
117
        $container = $this->getMockBuilder(ContainerInterface::class)->getMock();
118
        $container->expects($this->any())
119
            ->method('has')
120
            ->willReturnCallback(static function ($id) use ($services) {
121
                return isset($services[$id]);
122
            });
123
        $container->expects($this->any())
124
            ->method('get')
125
            ->willReturnCallback(static function ($id) use ($services) {
126
                return $services[$id];
127
            });
128
129
        return $container;
130
    }
131
132
    private function createEntityManager(array $entityRepositoryClasses) : MockObject
133
    {
134
        $classMetadatas = [];
135
        foreach ($entityRepositoryClasses as $entityClass => $entityRepositoryClass) {
136
            $metadata                            = new ClassMetadata($entityClass);
137
            $metadata->customRepositoryClassName = $entityRepositoryClass;
138
139
            $classMetadatas[$entityClass] = $metadata;
140
        }
141
142
        $em = $this->getMockBuilder(EntityManagerInterface::class)->getMock();
143
        $em->expects($this->any())
144
            ->method('getClassMetadata')
145
            ->willReturnCallback(static function ($class) use ($classMetadatas) {
146
                return $classMetadatas[$class];
147
            });
148
149
        $em->expects($this->any())
150
            ->method('getConfiguration')
151
            ->willReturn(new Configuration());
152
153
        return $em;
154
    }
155
}
156
157
/**
158
 * Repository implementing non-deprecated interface, as current interface implemented in ORM\EntityRepository
159
 * uses deprecated one and Composer autoload triggers deprecations that can't be silenced by @group legacy
160
 */
161
class NonDeprecatedRepository implements ObjectRepository
162
{
163
    /**
164
     * {@inheritDoc}
165
     */
166
    public function find($id)
167
    {
168
        return null;
169
    }
170
171
    public function findAll() : array
172
    {
173
        return [];
174
    }
175
176
    public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null) : array
177
    {
178
        return [];
179
    }
180
181
    /**
182
     * {@inheritDoc}
183
     */
184
    public function findOneBy(array $criteria)
185
    {
186
        return null;
187
    }
188
189
    public function getClassName() : string
190
    {
191
        return '';
192
    }
193
}
194
195
class StubRepository extends NonDeprecatedRepository
196
{
197
}
198
199
class StubServiceRepository extends NonDeprecatedRepository implements ServiceEntityRepositoryInterface
200
{
201
}
202