This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | /** |
||
4 | * Created by PhpStorm. |
||
5 | * User: benedikt |
||
6 | * Date: 1/3/18 |
||
7 | * Time: 3:53 PM |
||
8 | */ |
||
9 | |||
10 | namespace Tfboe\FmLib\Tests\Unit\Service; |
||
11 | |||
12 | use Doctrine\Common\Collections\AbstractLazyCollection; |
||
13 | use Doctrine\Common\Collections\ArrayCollection; |
||
14 | use Doctrine\ORM\EntityManagerInterface; |
||
15 | use Tfboe\FmLib\Entity\CompetitionInterface; |
||
16 | use Tfboe\FmLib\Entity\GameInterface; |
||
17 | use Tfboe\FmLib\Entity\PhaseInterface; |
||
18 | use Tfboe\FmLib\Entity\TournamentInterface; |
||
19 | use Tfboe\FmLib\Service\LoadingService; |
||
20 | use Tfboe\FmLib\Tests\Helpers\UnitTestCase; |
||
21 | |||
22 | |||
23 | /** |
||
24 | * Class LoadingServiceTest |
||
25 | * @package Tfboe\FmLib\Tests\Unit\Service |
||
26 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
||
27 | */ |
||
28 | class LoadingServiceTest extends UnitTestCase |
||
29 | { |
||
30 | //<editor-fold desc="Public Methods"> |
||
31 | /** |
||
32 | * @covers \Tfboe\FmLib\Service\LoadingService::__construct |
||
33 | */ |
||
34 | View Code Duplication | public function testConstruct() |
|
0 ignored issues
–
show
|
|||
35 | { |
||
36 | /** @var EntityManagerInterface $entityManager */ |
||
37 | $entityManager = $this->getMockForAbstractClass(EntityManagerInterface::class); |
||
38 | $service = new LoadingService($entityManager); |
||
39 | self::assertInstanceOf(LoadingService::class, $service); |
||
40 | /** @noinspection PhpUnhandledExceptionInspection */ |
||
41 | self::assertEquals($entityManager, self::getProperty(get_class($service), 'em')->getValue($service)); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @covers \Tfboe\FmLib\Service\LoadingService::loadEntities |
||
46 | * @covers \Tfboe\FmLib\Service\LoadingService::keyOfPropertyMap |
||
47 | * @uses \Tfboe\FmLib\Service\LoadingService::__construct |
||
48 | */ |
||
49 | public function testLoadEntitiesAlreadyLoaded() |
||
50 | { |
||
51 | $service = new LoadingService($this->getEntityManagerMockForQueries([])); |
||
0 ignored issues
–
show
$this->getEntityManagerMockForQueries(array()) 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);
![]() |
|||
52 | |||
53 | $tournament = $this->createMock(TournamentInterface::class); |
||
54 | $tournament->method('getEntityId')->willReturn('t'); |
||
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. ![]() |
|||
55 | $initializedCollection = new ArrayCollection(); |
||
56 | $initializedCollection->__isInitialized__ = true; |
||
0 ignored issues
–
show
The property
__isInitialized__ does not seem to exist in Doctrine\Common\Collections\ArrayCollection .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
57 | $tournament->method('getCompetitions')->willReturn($initializedCollection); |
||
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. ![]() |
|||
58 | $service->loadEntities([$tournament], [TournamentInterface::class => [["competitions"]]]); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @covers \Tfboe\FmLib\Service\LoadingService::loadEntities |
||
63 | * @covers \Tfboe\FmLib\Service\LoadingService::loadProperties |
||
64 | * @covers \Tfboe\FmLib\Service\LoadingService::keyOfPropertyMap |
||
65 | * @uses \Tfboe\FmLib\Service\LoadingService::__construct |
||
66 | */ |
||
67 | public function testLoadEntitiesDefaultPropertiesGame() |
||
68 | { |
||
69 | $service = new LoadingService($this->getEntityManagerMockForQuery([], |
||
0 ignored issues
–
show
$this->getEntityManagerM...WHERE t1.id IN(\'g\')') 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);
![]() |
|||
70 | 'SELECT t1, t2, t3 FROM Tfboe\FmLib\Entity\GameInterface t1 LEFT JOIN t1.playersA t2 LEFT JOIN ' |
||
71 | . 't1.playersB t3 WHERE t1.id IN(\'g\')' |
||
72 | )); |
||
73 | $game = $this->createMock(GameInterface::class); |
||
74 | $game->method('getEntityId')->willReturn('g'); |
||
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. ![]() |
|||
75 | |||
76 | $uninitializedLazyCollection = $this->createMock(AbstractLazyCollection::class); |
||
77 | $uninitializedLazyCollection->method('isInitialized')->willReturn(false); |
||
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. ![]() |
|||
78 | |||
79 | $game->expects(self::exactly(2))->method('getPlayersA')->willReturnOnConsecutiveCalls($uninitializedLazyCollection, |
||
80 | new ArrayCollection()); |
||
81 | $game->expects(self::once())->method('getPlayersB')->willReturn(new ArrayCollection()); |
||
82 | $service->loadEntities([$game]); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @covers \Tfboe\FmLib\Service\LoadingService::loadEntities |
||
87 | * @covers \Tfboe\FmLib\Service\LoadingService::loadProperties |
||
88 | * @covers \Tfboe\FmLib\Service\LoadingService::keyOfPropertyMap |
||
89 | * @uses \Tfboe\FmLib\Service\LoadingService::__construct |
||
90 | */ |
||
91 | public function testLoadEntitiesMultipleLevels() |
||
92 | { |
||
93 | $tournament = $this->createMock(TournamentInterface::class); |
||
94 | $tournament->method('getEntityId')->willReturn('t'); |
||
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. ![]() |
|||
95 | |||
96 | $competition1 = $this->createMock(CompetitionInterface::class); |
||
97 | $competition1->method('getEntityId')->willReturn('c1'); |
||
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. ![]() |
|||
98 | |||
99 | $competition2 = $this->createMock(CompetitionInterface::class); |
||
100 | $competition2->method('getEntityId')->willReturn('c1'); |
||
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. ![]() |
|||
101 | |||
102 | $uninitializedLazyCollection = $this->createMock(AbstractLazyCollection::class); |
||
103 | $uninitializedLazyCollection->method('isInitialized')->willReturn(false); |
||
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. ![]() |
|||
104 | |||
105 | $tournament->method('getCompetitions')->willReturnOnConsecutiveCalls( |
||
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. ![]() |
|||
106 | $uninitializedLazyCollection, |
||
107 | new ArrayCollection([$competition1, $competition2]) |
||
108 | ); |
||
109 | |||
110 | $phase1 = $this->createMock(PhaseInterface::class); |
||
111 | $phase1->method('getEntityId')->willReturn('p1'); |
||
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. ![]() |
|||
112 | |||
113 | $competition1->method('getPhases')->willReturn(new ArrayCollection([$phase1])); |
||
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. ![]() |
|||
114 | |||
115 | $phase2 = $this->createMock(PhaseInterface::class); |
||
116 | $phase2->method('getEntityId')->willReturn('p2'); |
||
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. ![]() |
|||
117 | |||
118 | $competition2->method('getPhases')->willReturn(new ArrayCollection([$phase2])); |
||
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. ![]() |
|||
119 | |||
120 | $entityManager = $this->getEntityManagerMockForQueries([[], []], [ |
||
121 | 'SELECT t1, t2 FROM Tfboe\FmLib\Entity\TournamentInterface t1 LEFT JOIN t1.competitions t2 WHERE t1.id IN(\'t\')', |
||
122 | 'SELECT t1, t2 FROM Tfboe\FmLib\Entity\CompetitionInterface t1 LEFT JOIN t1.phases t2 WHERE t1.id IN(\'c1\')' |
||
123 | ]); |
||
124 | |||
125 | $service = new LoadingService($entityManager); |
||
0 ignored issues
–
show
$entityManager 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);
![]() |
|||
126 | $service->loadEntities([$tournament], [ |
||
127 | TournamentInterface::class => [["competitions"]], |
||
128 | CompetitionInterface::class => [["phases"]] |
||
129 | ]); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @covers \Tfboe\FmLib\Service\LoadingService::loadEntities |
||
134 | * @covers \Tfboe\FmLib\Service\LoadingService::loadProperties |
||
135 | * @covers \Tfboe\FmLib\Service\LoadingService::keyOfPropertyMap |
||
136 | * @uses \Tfboe\FmLib\Service\LoadingService::__construct |
||
137 | */ |
||
138 | View Code Duplication | public function testLoadEntitiesNullProperty() |
|
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. ![]() |
|||
139 | { |
||
140 | $service = new LoadingService($this->getEntityManagerMockForQuery([], |
||
0 ignored issues
–
show
$this->getEntityManagerM...WHERE t1.id IN(\'t\')') 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);
![]() |
|||
141 | 'SELECT t1, t2 FROM Tfboe\FmLib\Entity\TournamentInterface t1 LEFT JOIN t1.competitions t2 WHERE t1.id IN(\'t\')' |
||
142 | )); |
||
143 | $tournament = $this->createMock(TournamentInterface::class); |
||
144 | $tournament->method('getEntityId')->willReturn('t'); |
||
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. ![]() |
|||
145 | $tournament->method('getCompetitions')->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. ![]() |
|||
146 | $service->loadEntities([$tournament], [TournamentInterface::class => [["competitions"]]]); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * @covers \Tfboe\FmLib\Service\LoadingService::loadEntities |
||
151 | * @covers \Tfboe\FmLib\Service\LoadingService::loadProperties |
||
152 | * @covers \Tfboe\FmLib\Service\LoadingService::keyOfPropertyMap |
||
153 | * @uses \Tfboe\FmLib\Service\LoadingService::__construct |
||
154 | */ |
||
155 | View Code Duplication | public function testLoadEntitiesSimpleProperty() |
|
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. ![]() |
|||
156 | { |
||
157 | $service = new LoadingService($this->getEntityManagerMockForQuery([], |
||
0 ignored issues
–
show
$this->getEntityManagerM...WHERE t1.id IN(\'c\')') 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);
![]() |
|||
158 | 'SELECT t1, t2 FROM Tfboe\FmLib\Entity\CompetitionInterface t1 LEFT JOIN t1.tournament t2 WHERE t1.id IN(\'c\')' |
||
159 | )); |
||
160 | $competition = $this->createMock(CompetitionInterface::class); |
||
161 | $competition->method('getEntityId')->willReturn('c'); |
||
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. ![]() |
|||
162 | $service->loadEntities([$competition], [CompetitionInterface::class => [["tournament"]]]); |
||
163 | } |
||
164 | //</editor-fold desc="Public Methods"> |
||
165 | } |
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.