Issues (145)

Security Analysis    no request data  

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/EntitySpecificationRepositorySpec.php (10 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
/**
4
 * This file is part of the Happyr Doctrine Specification package.
5
 *
6
 * (c) Tobias Nyholm <[email protected]>
7
 *     Kacper Gunia <[email protected]>
8
 *     Peter Gribanov <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace tests\Happyr\DoctrineSpecification\Repository;
15
16
use Doctrine\ORM\AbstractQuery;
17
use Doctrine\ORM\EntityManager;
18
use Doctrine\ORM\Mapping\ClassMetadata;
19
use Doctrine\ORM\NonUniqueResultException as DoctrineNonUniqueResultException;
20
use Doctrine\ORM\NoResultException as DoctrineNoResultException;
21
use Doctrine\ORM\QueryBuilder;
22
use Happyr\DoctrineSpecification\Exception\NonUniqueResultException;
23
use Happyr\DoctrineSpecification\Exception\NoResultException;
24
use Happyr\DoctrineSpecification\Exception\UnexpectedResultException;
25
use Happyr\DoctrineSpecification\Filter\Filter;
26
use Happyr\DoctrineSpecification\Query\QueryModifier;
27
use Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository;
28
use Happyr\DoctrineSpecification\Result\ResultModifier;
29
use Happyr\DoctrineSpecification\Specification\Specification;
30
use PhpSpec\ObjectBehavior;
31
use Prophecy\Argument;
32
33
/**
34
 * @mixin EntitySpecificationRepository
35
 */
36
class EntitySpecificationRepositorySpec extends ObjectBehavior
37
{
38
    private $alias = 'e';
39
40
    private $expression = 'expression';
41
42
    private $result = 'result';
43
44
    public function let(EntityManager $entityManager, ClassMetadata $classMetadata)
45
    {
46
        $this->beConstructedWith($entityManager, $classMetadata);
47
    }
48
49
    public function it_should_modify_query(
50
        QueryModifier $specification,
51
        EntityManager $entityManager,
52
        QueryBuilder $qb,
53
        AbstractQuery $query
54
    ) {
55
        $this->prepareEntityManagerStub($entityManager, $qb);
56
        $this->prepareQueryBuilderStub($qb, $query);
57
        $query->execute()->willReturn($this->result);
58
59
        $specification->modify($qb, $this->alias)->shouldBeCalled();
60
61
        $this->match($specification);
62
    }
63
64 View Code Duplication
    public function it_should_apply_filter(
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
        Filter $specification,
66
        EntityManager $entityManager,
67
        QueryBuilder $qb,
68
        AbstractQuery $query
69
    ) {
70
        $this->prepareEntityManagerStub($entityManager, $qb);
71
        $this->prepareQueryBuilderStub($qb, $query);
72
        $specification->getFilter($qb, $this->alias)->willReturn($this->expression);
73
74
        $qb->andWhere($this->expression)->willReturn($qb);
75
        $qb->where()->shouldNotBeCalled();
76
77
        $this->match($specification);
78
    }
79
80
    public function it_should_skip_apply_empty_specification(
81
        EntityManager $entityManager,
82
        QueryBuilder $qb,
83
        AbstractQuery $query
84
    ) {
85
        $this->prepareEntityManagerStub($entityManager, $qb);
86
        $this->prepareQueryBuilderStub($qb, $query);
87
88
        $qb->andWhere()->shouldNotBeCalled();
89
        $qb->where()->shouldNotBeCalled();
90
91
        $this->match(null);
92
    }
93
94
    public function it_should_throw_exception_when_apply_not_specification(
95
        EntityManager $entityManager,
96
        QueryBuilder $qb,
97
        AbstractQuery $query
98
    ) {
99
        $this->prepareEntityManagerStub($entityManager, $qb);
100
        $this->prepareQueryBuilderStub($qb, $query);
101
102
        $this->shouldThrow('\InvalidArgumentException')->duringMatch(new \stdClass());
103
        $this->shouldThrow('\InvalidArgumentException')->duringMatch(['fake', 'array']);
104
        $this->shouldThrow('\InvalidArgumentException')->duringMatch('fake');
105
    }
106
107
    public function it_matches_a_specification_with_empty_filter(
108
        Specification $specification,
109
        EntityManager $entityManager,
110
        QueryBuilder $qb,
111
        AbstractQuery $query
112
    ) {
113
        $this->prepareEntityManagerStub($entityManager, $qb);
114
        $this->prepareQueryBuilderStub($qb, $query);
115
        $query->execute()->willReturn($this->result);
116
117
        $qb->andWhere()->shouldNotBeCalled();
118
        $qb->where()->shouldNotBeCalled();
119
120
        $this->match($specification)->shouldReturn($this->result);
121
    }
122
123
    public function it_matches_a_specification_without_result_modifier(
124
        Specification $specification,
125
        EntityManager $entityManager,
126
        QueryBuilder $qb,
127
        AbstractQuery $query
128
    ) {
129
        $this->prepareStubs($specification, $entityManager, $qb, $query);
130
        $query->execute()->willReturn($this->result);
131
132
        $specification->modify($qb, $this->alias)->shouldBeCalled();
133
134
        $this->match($specification)->shouldReturn($this->result);
135
    }
136
137 View Code Duplication
    public function it_matches_a_single_result_without_result_modifier(
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
138
        Specification $specification,
139
        EntityManager $entityManager,
140
        QueryBuilder $qb,
141
        AbstractQuery $query
142
    ) {
143
        $singleResult = new \stdClass();
144
145
        $this->prepareStubs($specification, $entityManager, $qb, $query);
146
147
        $specification->modify($qb, $this->alias)->shouldBeCalled();
148
149
        $query->getSingleResult()->willReturn($singleResult);
150
151
        $this->matchSingleResult($specification)->shouldReturn($singleResult);
152
    }
153
154 View Code Duplication
    public function it_throws_exception_when_expecting_single_result_finding_none_without_result_modifier(
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
155
        Specification $specification,
156
        EntityManager $entityManager,
157
        QueryBuilder $qb,
158
        AbstractQuery $query
159
    ) {
160
        $this->prepareStubs($specification, $entityManager, $qb, $query);
161
162
        $specification->modify($qb, $this->alias)->shouldBeCalled();
163
164
        $query->getSingleResult()->willThrow(new DoctrineNoResultException());
165
166
        $this->shouldThrow(NoResultException::class)->duringMatchSingleResult($specification);
167
    }
168
169 View Code Duplication
    public function it_throws_exception_when_expecting_single_result_finding_multiple_without_result_modifier(
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
170
        Specification $specification,
171
        EntityManager $entityManager,
172
        QueryBuilder $qb,
173
        AbstractQuery $query
174
    ) {
175
        $this->prepareStubs($specification, $entityManager, $qb, $query);
176
177
        $specification->modify($qb, $this->alias)->shouldBeCalled();
178
179
        $query->getSingleResult()->willThrow(new DoctrineNonUniqueResultException());
180
181
        $this->shouldThrow(NonUniqueResultException::class)->duringMatchSingleResult($specification);
182
    }
183
184 View Code Duplication
    public function it_matches_a_single_scalar_result_without_result_modifier(
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
185
        Specification $specification,
186
        EntityManager $entityManager,
187
        QueryBuilder $qb,
188
        AbstractQuery $query
189
    ) {
190
        $singleScalarResult = '1';
191
192
        $this->prepareStubs($specification, $entityManager, $qb, $query);
193
194
        $specification->modify($qb, $this->alias)->shouldBeCalled();
195
196
        $query->getSingleScalarResult()->willReturn($singleScalarResult);
197
198
        $this->matchSingleScalarResult($specification)->shouldReturn($singleScalarResult);
199
    }
200
201 View Code Duplication
    public function it_throws_exception_when_expecting_single_scalar_result_finding_multiple_without_result_modifier(
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
202
        Specification $specification,
203
        EntityManager $entityManager,
204
        QueryBuilder $qb,
205
        AbstractQuery $query
206
    ) {
207
        $this->prepareStubs($specification, $entityManager, $qb, $query);
208
209
        $specification->modify($qb, $this->alias)->shouldBeCalled();
210
211
        $query->getSingleScalarResult()->willThrow(new DoctrineNonUniqueResultException());
212
213
        $this->shouldThrow(NonUniqueResultException::class)->duringMatchSingleScalarResult($specification);
214
    }
215
216
    public function it_matches_a_scalar_result_when_expecting_one_or_null_without_result_modifier(
217
        Specification $specification,
218
        EntityManager $entityManager,
219
        QueryBuilder $qb,
220
        AbstractQuery $query
221
    ) {
222
        $scalarResult = ['1', '2', '3'];
223
224
        $this->prepareStubs($specification, $entityManager, $qb, $query);
225
226
        $specification->modify($qb, $this->alias)->shouldBeCalled();
227
228
        $query->getScalarResult()->willReturn($scalarResult);
229
230
        $this->matchScalarResult($specification)->shouldReturn($scalarResult);
231
    }
232
233 View Code Duplication
    public function it_matches_a_single_result_when_expecting_one_or_null_without_result_modifier(
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
234
        Specification $specification,
235
        EntityManager $entityManager,
236
        QueryBuilder $qb,
237
        AbstractQuery $query
238
    ) {
239
        $singleResult = new \stdClass();
240
241
        $this->prepareStubs($specification, $entityManager, $qb, $query);
242
243
        $specification->modify($qb, $this->alias)->shouldBeCalled();
244
245
        $query->getSingleResult()->willReturn($singleResult);
246
247
        $this->matchOneOrNullResult($specification)->shouldReturn($singleResult);
248
    }
249
250 View Code Duplication
    public function it_matches_null_when_expecting_one_or_null_without_result_modifier(
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
251
        Specification $specification,
252
        EntityManager $entityManager,
253
        QueryBuilder $qb,
254
        AbstractQuery $query
255
    ) {
256
        $this->prepareStubs($specification, $entityManager, $qb, $query);
257
258
        $specification->modify($qb, $this->alias)->shouldBeCalled();
259
260
        $query->getSingleResult()->willThrow(new DoctrineNonUniqueResultException());
261
262
        $this->shouldThrow(NonUniqueResultException::class)->duringMatchOneOrNullResult($specification);
263
    }
264
265 View Code Duplication
    public function it_throws_exception_when_expecting_one_or_null_finding_multiple_without_result_modifier(
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
266
        Specification $specification,
267
        EntityManager $entityManager,
268
        QueryBuilder $qb,
269
        AbstractQuery $query
270
    ) {
271
        $this->prepareStubs($specification, $entityManager, $qb, $query);
272
273
        $specification->modify($qb, $this->alias)->shouldBeCalled();
274
275
        $query->getSingleResult()->willThrow(new DoctrineNonUniqueResultException());
276
277
        $this->shouldThrow(UnexpectedResultException::class)->duringMatchOneOrNullResult($specification);
278
    }
279
280 View Code Duplication
    public function it_matches_a_specification_with_result_modifier(
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
281
        Specification $specification,
282
        EntityManager $entityManager,
283
        QueryBuilder $qb,
284
        AbstractQuery $query,
285
        ResultModifier $modifier
286
    ) {
287
        $this->prepareStubs($specification, $entityManager, $qb, $query);
288
        $query->execute()->willReturn($this->result);
289
290
        $specification->modify($qb, $this->alias)->shouldBeCalled();
291
        $modifier->modify($query)->shouldBeCalled();
292
293
        $this->match($specification, $modifier)->shouldReturn($this->result);
294
    }
295
296
    private function prepareStubs(Specification $specification, EntityManager $entityManager, QueryBuilder $qb, AbstractQuery $query)
297
    {
298
        $this->prepareEntityManagerStub($entityManager, $qb);
299
        $this->prepareSpecificationStub($specification, $qb);
300
        $this->prepareQueryBuilderStub($qb, $query);
301
    }
302
303
    private function prepareEntityManagerStub(EntityManager $entityManager, QueryBuilder $qb)
304
    {
305
        $entityManager->createQueryBuilder()->willReturn($qb);
306
    }
307
308
    private function prepareSpecificationStub(Specification $specification, QueryBuilder $qb)
309
    {
310
        $specification->getFilter($qb, $this->alias)->willReturn($this->expression);
311
    }
312
313
    private function prepareQueryBuilderStub(QueryBuilder $qb, Query $query)
314
    {
315
        $qb->from(Argument::any(), $this->alias, null)->willReturn($qb);
316
        $qb->select($this->alias)->willReturn($qb);
317
        $qb->andWhere($this->expression)->willReturn($qb);
318
        $qb->getQuery()->willReturn($query);
319
    }
320
}
321