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\ORM\EntityManagerInterface; |
||
13 | use Tfboe\FmLib\Entity\LastRecalculationInterface; |
||
14 | use Tfboe\FmLib\Service\DynamicServiceLoadingService; |
||
15 | use Tfboe\FmLib\Service\DynamicServiceLoadingServiceInterface; |
||
16 | use Tfboe\FmLib\Service\RankingSystem\RankingSystemInterface; |
||
17 | use Tfboe\FmLib\Service\RankingSystemService; |
||
18 | use Tfboe\FmLib\Tests\Entity\Competition; |
||
19 | use Tfboe\FmLib\Tests\Entity\Game; |
||
20 | use Tfboe\FmLib\Tests\Entity\Match; |
||
21 | use Tfboe\FmLib\Tests\Entity\Phase; |
||
22 | use Tfboe\FmLib\Tests\Entity\RankingSystem; |
||
23 | use Tfboe\FmLib\Tests\Entity\Tournament; |
||
24 | use Tfboe\FmLib\Tests\Helpers\UnitTestCase; |
||
25 | |||
26 | |||
27 | /** |
||
28 | * Class EloRankingTest |
||
29 | * @packageTfboe\FmLib\Tests\Unit\Service |
||
30 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
||
31 | */ |
||
32 | class RankingSystemServiceTest extends UnitTestCase |
||
33 | { |
||
34 | //<editor-fold desc="Public Methods"> |
||
35 | /** |
||
36 | * @covers \Tfboe\FmLib\Service\RankingSystemService::adaptOpenSyncFromValues |
||
37 | * @uses \Tfboe\FmLib\Service\RankingSystemService::__construct |
||
38 | * @uses \Tfboe\FmLib\Entity\Traits\Tournament |
||
39 | * @uses \Tfboe\FmLib\Entity\Traits\Tournament |
||
40 | * @uses \Tfboe\FmLib\Service\RankingSystemService::getRankingSystems |
||
41 | * @uses \Tfboe\FmLib\Service\RankingSystemService::getRankingSystemsEarliestInfluences |
||
42 | * @uses \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct |
||
43 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
||
44 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::getRankingSystems |
||
45 | */ |
||
46 | public function testAdaptOpenSyncFromValues() |
||
47 | { |
||
48 | $serviceLoader = $this->createMock(DynamicServiceLoadingService::class); |
||
49 | $serviceLoader->expects(self::exactly(2)) |
||
50 | ->method("loadRankingSystemService") |
||
51 | View Code Duplication | ->willReturnCallback(function ($earliestInfluence) { |
|
0 ignored issues
–
show
|
|||
52 | $mock = $this->createMock(\Tfboe\FmLib\Service\RankingSystem\RankingSystemService::class); |
||
53 | $mock->method("getEarliestInfluence")->willReturn(new \DateTime($earliestInfluence)); |
||
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. ![]() |
|||
54 | return $mock; |
||
55 | }); |
||
56 | /** @var DynamicServiceLoadingService $serviceLoader */ |
||
57 | /** @noinspection PhpParamsInspection */ |
||
58 | $service = new RankingSystemService($serviceLoader, |
||
0 ignored issues
–
show
$serviceLoader is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Tfboe\FmLib\Servi...oadingServiceInterface> .
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);
![]() |
|||
59 | $this->getMockForAbstractClass(EntityManagerInterface::class)); |
||
0 ignored issues
–
show
$this->getMockForAbstrac...anagerInterface::class) 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);
![]() |
|||
60 | |||
61 | |||
62 | $tournament = new Tournament(); |
||
63 | $ranking = $this->createStubWithId(RankingSystem::class, 'r1'); |
||
64 | $ranking->method('getServiceName')->willReturn("2017-01-01"); |
||
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. ![]() |
|||
65 | $ranking->method('getOpenSyncFrom')->willReturn(new \DateTime("2017-01-01 15:00:00")); |
||
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. ![]() |
|||
66 | $ranking->expects(self::once())->method('setOpenSyncFrom')->with(new \DateTime("2017-01-01")); |
||
67 | /** @var \Tfboe\FmLib\Entity\RankingSystemInterface $ranking */ |
||
68 | $tournament->getRankingSystems()->set($ranking->getId(), $ranking); |
||
69 | |||
70 | $ranking2 = $this->createStubWithId(RankingSystem::class, 'r2'); |
||
71 | $ranking2->method('getServiceName')->willReturn("2017-02-01"); |
||
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. ![]() |
|||
72 | $ranking2->method('getOpenSyncFrom')->willReturn(new \DateTime("2017-01-30 15:00:00")); |
||
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. ![]() |
|||
73 | $ranking2->expects(self::once())->method('setOpenSyncFrom')->with(new \DateTime("2017-01-30")); |
||
74 | /** @var \Tfboe\FmLib\Entity\RankingSystemInterface $ranking2 */ |
||
75 | $tournament->getRankingSystems()->set($ranking2->getId(), $ranking2); |
||
76 | |||
77 | $ranking3 = $this->createStubWithId(RankingSystem::class, 'r3'); |
||
78 | $ranking3->method('getOpenSyncFrom')->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. ![]() |
|||
79 | $ranking3->expects(self::once())->method('setOpenSyncFrom')->with(new \DateTime("2017-03-01")); |
||
80 | $ranking4 = $this->createStubWithId(RankingSystem::class, 'r4'); |
||
81 | $ranking4->method('getOpenSyncFrom')->willReturn(new \DateTime("2017-04-01")); |
||
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. ![]() |
|||
82 | $ranking4->expects(self::never())->method('setOpenSyncFrom'); |
||
83 | |||
84 | $service->adaptOpenSyncFromValues($tournament, [ |
||
85 | 'r1' => ["rankingSystem" => $ranking, "earliestInfluence" => new \DateTime("2017-01-02")], |
||
86 | 'r2' => ["rankingSystem" => $ranking2, "earliestInfluence" => new \DateTime("2017-01-30")], |
||
87 | 'r3' => ["rankingSystem" => $ranking3, "earliestInfluence" => new \DateTime("2017-03-01")], |
||
88 | 'r4' => ["rankingSystem" => $ranking4, "earliestInfluence" => new \DateTime("2017-06-01")], |
||
89 | ]); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @covers \Tfboe\FmLib\Service\RankingSystemService::applyRankingSystems |
||
94 | * @covers \Tfboe\FmLib\Service\RankingSystemService::getRankingSystems |
||
95 | * @uses \Tfboe\FmLib\Entity\Traits\Tournament |
||
96 | * @uses \Tfboe\FmLib\Entity\Traits\Tournament |
||
97 | * @uses \Tfboe\FmLib\Service\RankingSystemService::__construct |
||
98 | * @uses \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct |
||
99 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
||
100 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::getRankingSystems |
||
101 | */ |
||
102 | public function testApplyRankingSystems() |
||
103 | { |
||
104 | $tournament = new Tournament(); |
||
105 | /** @var \Tfboe\FmLib\Entity\RankingSystemInterface $ranking2 */ |
||
106 | $ranking2 = $this->createStubWithId(RankingSystem::class, 's2'); |
||
107 | $tournament->getRankingSystems()->set($ranking2->getId(), $ranking2); |
||
108 | /** @var \Tfboe\FmLib\Entity\RankingSystemInterface $ranking3 */ |
||
109 | $ranking3 = $this->createStubWithId(RankingSystem::class, 's3'); |
||
110 | |||
111 | $tournament->getRankingSystems()->set($ranking3->getId(), $ranking3); |
||
112 | |||
113 | /** @var \Tfboe\FmLib\Entity\RankingSystemInterface $ranking4 */ |
||
114 | $ranking4 = $this->createStubWithId(RankingSystem::class, 's4'); |
||
115 | |||
116 | $oldInfluences = [ |
||
117 | $ranking2->getId() => ["rankingSystem" => $ranking2, "earliestInfluence" => new \DateTime("2017-02-01")], |
||
118 | $ranking4->getId() => ["rankingSystem" => $ranking4, "earliestInfluence" => new \DateTime("2017-04-01")] |
||
119 | ]; |
||
120 | |||
121 | $serviceLoader = $this->createMock(DynamicServiceLoadingService::class); |
||
122 | $mock = $this->createMock(\Tfboe\FmLib\Service\RankingSystem\RankingSystemService::class); |
||
123 | $mock->expects(self::exactly(3))->method("updateRankingForTournament")->withConsecutive( |
||
124 | [$ranking2, $tournament, self::equalTo(new \DateTime("2017-02-01"))], |
||
125 | [$ranking4, $tournament, self::equalTo(new \DateTime("2017-04-01"))], |
||
126 | [$ranking3, $tournament, null] |
||
127 | ); |
||
128 | $serviceLoader->expects(self::exactly(3)) |
||
129 | ->method("loadRankingSystemService") |
||
130 | ->willReturn($mock); |
||
131 | |||
132 | /** @var DynamicServiceLoadingService $serviceLoader */ |
||
133 | /** @noinspection PhpParamsInspection */ |
||
134 | $service = new RankingSystemService($serviceLoader, |
||
0 ignored issues
–
show
$serviceLoader is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Tfboe\FmLib\Servi...oadingServiceInterface> .
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);
![]() |
|||
135 | $this->getMockForAbstractClass(EntityManagerInterface::class)); |
||
0 ignored issues
–
show
$this->getMockForAbstrac...anagerInterface::class) 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);
![]() |
|||
136 | $service->applyRankingSystems($tournament, $oldInfluences); |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * @covers \Tfboe\FmLib\Service\RankingSystemService::__construct |
||
141 | */ |
||
142 | public function testConstruct() |
||
143 | { |
||
144 | $dsls = $this->getMockForAbstractClass(DynamicServiceLoadingServiceInterface::class); |
||
145 | $entityManager = $this->getMockForAbstractClass(EntityManagerInterface::class); |
||
146 | /** @var DynamicServiceLoadingServiceInterface $dsls */ |
||
147 | /** @var EntityManagerInterface $entityManager */ |
||
148 | $system = new RankingSystemService($dsls, $entityManager); |
||
0 ignored issues
–
show
$dsls is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Tfboe\FmLib\Servi...oadingServiceInterface> .
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);
![]() |
|||
149 | self::assertInstanceOf(RankingSystemService::class, $system); |
||
150 | /** @noinspection PhpUnhandledExceptionInspection */ |
||
151 | self::assertEquals($entityManager, self::getProperty(get_class($system), 'entityManager')->getValue($system)); |
||
152 | /** @noinspection PhpUnhandledExceptionInspection */ |
||
153 | self::assertEquals($dsls, self::getProperty(get_class($system), 'dsls')->getValue($system)); |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @covers \Tfboe\FmLib\Service\RankingSystemService::getRankingSystemsEarliestInfluences |
||
158 | * @covers \Tfboe\FmLib\Service\RankingSystemService::getRankingSystems |
||
159 | * @uses \Tfboe\FmLib\Entity\Traits\Competition |
||
160 | * @uses \Tfboe\FmLib\Entity\Traits\Competition |
||
161 | * @uses \Tfboe\FmLib\Entity\Traits\Game |
||
162 | * @uses \Tfboe\FmLib\Entity\Traits\Game |
||
163 | * @uses \Tfboe\FmLib\Entity\Traits\Match |
||
164 | * @uses \Tfboe\FmLib\Entity\Traits\Match |
||
165 | * @uses \Tfboe\FmLib\Entity\Traits\Phase |
||
166 | * @uses \Tfboe\FmLib\Entity\Traits\Phase |
||
167 | * @uses \Tfboe\FmLib\Entity\Traits\Tournament |
||
168 | * @uses \Tfboe\FmLib\Entity\Traits\Tournament |
||
169 | * @uses \Tfboe\FmLib\Entity\Helpers\NameEntity |
||
170 | * @uses \Tfboe\FmLib\Service\RankingSystemService::__construct |
||
171 | * @uses \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct |
||
172 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
||
173 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::getRankingSystems |
||
174 | */ |
||
175 | public function testGetRankingSystemsEarliestInfluences() |
||
176 | { |
||
177 | $serviceLoader = $this->createMock(DynamicServiceLoadingService::class); |
||
178 | $serviceLoader->expects(self::exactly(3)) |
||
179 | ->method("loadRankingSystemService") |
||
180 | View Code Duplication | ->willReturnCallback(function ($earliestInfluence) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
181 | $mock = $this->createMock(\Tfboe\FmLib\Service\RankingSystem\RankingSystemService::class); |
||
182 | $mock->method("getEarliestInfluence")->willReturn(new \DateTime($earliestInfluence)); |
||
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. ![]() |
|||
183 | return $mock; |
||
184 | }); |
||
185 | /** @var DynamicServiceLoadingService $serviceLoader */ |
||
186 | /** @noinspection PhpParamsInspection */ |
||
187 | $service = new RankingSystemService($serviceLoader, |
||
0 ignored issues
–
show
$serviceLoader is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Tfboe\FmLib\Servi...oadingServiceInterface> .
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);
![]() |
|||
188 | $this->getMockForAbstractClass(EntityManagerInterface::class)); |
||
0 ignored issues
–
show
$this->getMockForAbstrac...anagerInterface::class) 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);
![]() |
|||
189 | $tournament = new Tournament(); |
||
190 | $ranking2 = $this->createStubWithId(RankingSystem::class, 'r2'); |
||
191 | $ranking2->method('getServiceName')->willReturn("2017-04-01"); |
||
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. ![]() |
|||
192 | /** @var \Tfboe\FmLib\Entity\RankingSystemInterface $ranking2 */ |
||
193 | $tournament->getRankingSystems()->set($ranking2->getId(), $ranking2); |
||
194 | |||
195 | $competition = new Competition(); |
||
196 | $competition->setName("TestCompetition")->setTournament($tournament); |
||
0 ignored issues
–
show
It seems like
setTournament() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
197 | $phase = new Phase(); |
||
198 | $phase->setPhaseNumber(1); |
||
199 | $phase->setCompetition($competition); |
||
200 | $ranking3 = $this->createStubWithId(RankingSystem::class, 'r3'); |
||
201 | $ranking3->method('getServiceName')->willReturn("2017-02-01"); |
||
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. ![]() |
|||
202 | /** @var \Tfboe\FmLib\Entity\RankingSystemInterface $ranking3 */ |
||
203 | |||
204 | $phase->getRankingSystems()->set($ranking3->getId(), $ranking3); |
||
205 | |||
206 | $match = new Match(); |
||
207 | $match->setMatchNumber(1); |
||
208 | $match->setPhase($phase); |
||
209 | $game = new Game(); |
||
210 | $game->setGameNumber(1); |
||
211 | $game->setMatch($match); |
||
212 | $ranking4 = $this->createStubWithId(RankingSystem::class, 'r4'); |
||
213 | $ranking4->method('getServiceName')->willReturn("2017-03-01"); |
||
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. ![]() |
|||
214 | /** @var \Tfboe\FmLib\Entity\RankingSystemInterface $ranking4 */ |
||
215 | $game->getRankingSystems()->set($ranking4->getId(), $ranking4); |
||
216 | |||
217 | |||
218 | self::assertEquals( |
||
219 | [ |
||
220 | $ranking2->getId() => ["rankingSystem" => $ranking2, "earliestInfluence" => new \DateTime("2017-04-01")], |
||
221 | $ranking3->getId() => ["rankingSystem" => $ranking3, "earliestInfluence" => new \DateTime("2017-02-01")], |
||
222 | $ranking4->getId() => ["rankingSystem" => $ranking4, "earliestInfluence" => new \DateTime("2017-03-01")], |
||
223 | ], |
||
224 | $service->getRankingSystemsEarliestInfluences($tournament)); |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * @covers \Tfboe\FmLib\Service\RankingSystemService::recalculateRankingSystems |
||
229 | * @uses \Tfboe\FmLib\Service\RankingSystemService::__construct |
||
230 | */ |
||
231 | public function testRecalculateRankingSystems() |
||
232 | { |
||
233 | $rs1 = $this->createMock(\Tfboe\FmLib\Entity\RankingSystemInterface::class); |
||
234 | $rs1->expects(self::once())->method('getServiceName')->willReturn('service'); |
||
235 | $rs1->expects(self::exactly(3))->method('getOpenSyncFrom')->willReturn(new \DateTime("2017-02-01")); |
||
236 | $rs1->expects(self::once())->method('setOpenSyncFrom')->with(null); |
||
237 | $rs1->expects(self::once())->method('setOpenSyncFromInProcess')->with(null); |
||
238 | $rs2 = $this->createMock(\Tfboe\FmLib\Entity\RankingSystemInterface::class); |
||
239 | $rs2->expects(self::once())->method('getServiceName')->willReturn('service'); |
||
240 | $rs2->expects(self::exactly(3))->method('getOpenSyncFrom')->willReturn(new \DateTime("2017-05-01")); |
||
241 | $rs2->expects(self::once())->method('setOpenSyncFrom')->with(null); |
||
242 | $rs2->expects(self::once())->method('setOpenSyncFromInProcess')->with(null); |
||
243 | $slash = '\\'; |
||
244 | $first = 'SELECT s'; |
||
245 | $second = ' FROM Tfboe'; |
||
246 | $third = 'FmLib'; |
||
247 | $rest = 'RankingSystemInterface s WHERE s.openSyncFrom IS NOT NULL OR s.openSyncFromInProcess IS NOT NULL'; |
||
248 | $entityManager = $this->getEntityManagerMockForQuery([$rs1, $rs2], |
||
249 | $first . $second . $slash . $third . $slash . 'Entity' . $slash . $rest, ['flush', 'clear', 'transactional', |
||
250 | 'find']); |
||
251 | $entityManager->method('transactional')->willReturnCallback(function ($f) use ($entityManager) { |
||
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. ![]() |
|||
252 | return $f($entityManager); |
||
253 | }); |
||
254 | $lastRecalculation = $this->createMock(LastRecalculationInterface::class); |
||
255 | $entityManager->method('find')->willReturn($lastRecalculation); |
||
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. ![]() |
|||
256 | $dsls = $this->getMockForAbstractClass(DynamicServiceLoadingServiceInterface::class); |
||
257 | $service = $this->getMockForAbstractClass(RankingSystemInterface::class); |
||
258 | $service->expects(self::exactly(2))->method('updateRankingFrom') |
||
259 | ->withConsecutive([$rs1, new \DateTime("2017-02-01")], [$rs2, new \DateTime("2017-05-01")]); |
||
260 | $dsls->expects(self::exactly(2))->method('loadRankingSystemService')->with('service')->willReturn($service); |
||
261 | /** @var DynamicServiceLoadingServiceInterface $dsls */ |
||
262 | /** @var EntityManagerInterface $entityManager */ |
||
263 | $system = new RankingSystemService($dsls, $entityManager); |
||
0 ignored issues
–
show
$dsls is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Tfboe\FmLib\Servi...oadingServiceInterface> .
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);
![]() |
|||
264 | $system->recalculateRankingSystems(); |
||
265 | } |
||
266 | //</editor-fold desc="Public Methods"> |
||
267 | } |
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.