RankingSystemServiceTest::testGetEntityManager()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 1/3/18
7
 * Time: 3:54 PM
8
 */
9
10
namespace Tfboe\FmLib\Tests\Unit\Service\RankingSystem;
11
12
use Doctrine\Common\Collections\ArrayCollection;
13
use Doctrine\Common\Collections\Collection;
14
use Doctrine\ORM\AbstractQuery;
15
use Doctrine\ORM\EntityManager;
16
use Doctrine\ORM\EntityManagerInterface;
17
use Doctrine\ORM\QueryBuilder;
18
use PHPUnit\Framework\MockObject\MockObject;
19
use Tfboe\FmLib\Entity\Helpers\AutomaticInstanceGeneration;
20
use Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity;
21
use Tfboe\FmLib\Entity\Helpers\TournamentHierarchyInterface;
22
use Tfboe\FmLib\Entity\RankingSystemChangeInterface;
23
use Tfboe\FmLib\Entity\RankingSystemInterface;
24
use Tfboe\FmLib\Entity\RankingSystemListEntryInterface;
25
use Tfboe\FmLib\Entity\RankingSystemListInterface;
26
use Tfboe\FmLib\Exceptions\PreconditionFailedException;
27
use Tfboe\FmLib\Helpers\Level;
28
use Tfboe\FmLib\Service\ObjectCreatorServiceInterface;
29
use Tfboe\FmLib\Service\RankingSystem\EntityComparerInterface;
30
use Tfboe\FmLib\Service\RankingSystem\RankingSystemService;
31
use Tfboe\FmLib\Service\RankingSystem\TimeServiceInterface;
32
use Tfboe\FmLib\Tests\Entity\Competition;
33
use Tfboe\FmLib\Tests\Entity\Game;
34
use Tfboe\FmLib\Tests\Entity\Match;
35
use Tfboe\FmLib\Tests\Entity\Phase;
36
use Tfboe\FmLib\Tests\Entity\Player;
37
use Tfboe\FmLib\Tests\Entity\RankingSystem;
38
use Tfboe\FmLib\Tests\Entity\RankingSystemChange;
39
use Tfboe\FmLib\Tests\Entity\RankingSystemList;
40
use Tfboe\FmLib\Tests\Entity\RankingSystemListEntry;
41
use Tfboe\FmLib\Tests\Entity\Tournament;
42
use Tfboe\FmLib\Tests\Helpers\UnitTestCase;
43
44
45
/**
46
 * Class RankingSystemServiceTest
47
 * @packageTfboe\FmLib\Tests\Unit\Service\RankingSystemService
48
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
49
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
50
 * @SuppressWarnings(PHPMD.TooManyMethods)
51
 * @SuppressWarnings(PHPMD.ExcessiveClassLength)
52
 */
53
class RankingSystemServiceTest extends UnitTestCase
54
{
55
//<editor-fold desc="Public Methods">
56
57
  /**
58
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
59
   */
60
  public function testConstruct()
61
  {
62
    $entityManager = $this->createMock(EntityManagerInterface::class);
63
    $timeService = $this->createMock(TimeServiceInterface::class);
64
    $entityComparer = $this->createMock(EntityComparerInterface::class);
65
    $objectCreator = $this->createMock(ObjectCreatorServiceInterface::class);
66
    $system = $this->getMockForAbstractClass(RankingSystemService::class,
67
      [$entityManager, $timeService, $entityComparer, $objectCreator]);
68
    self::assertInstanceOf(RankingSystemService::class, $system);
69
    /** @noinspection PhpUnhandledExceptionInspection */
70
    self::assertEquals($entityManager, self::getProperty(get_class($system), 'entityManager')->getValue($system));
71
    /** @noinspection PhpUnhandledExceptionInspection */
72
    self::assertEquals($timeService, self::getProperty(get_class($system), 'timeService')->getValue($system));
73
    /** @noinspection PhpUnhandledExceptionInspection */
74
    self::assertEquals($entityComparer, self::getProperty(get_class($system), 'entityComparer')->getValue($system));
75
    /** @noinspection PhpUnhandledExceptionInspection */
76
    self::assertEquals($objectCreator, self::getProperty(get_class($system), 'objectCreatorService')
77
      ->getValue($system));
78
  }
79
80
  /**
81
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getAverage
82
   */
83
  public function testGetAverage()
84
  {
85
    /** @var $service RankingSystemService */
86
    $service = $this->getMockForAbstractClass(RankingSystemService::class, [], '', false);
87
88
    $entry1 = $this->createMock(RankingSystemListEntry::class);
89
    $entry1->method('getPoints')->willReturn(1.0);
0 ignored issues
show
Bug introduced by
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.

Loading history...
90
    $entry2 = $this->createMock(RankingSystemListEntry::class);
91
    $entry2->method('getPoints')->willReturn(2.0);
0 ignored issues
show
Bug introduced by
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.

Loading history...
92
93
    self::assertEquals(1.5, static::callProtectedMethod($service, 'getAverage', [[$entry1, $entry2]]));
94
  }
95
96
  /**
97
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestInfluence
98
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestEntityInfluence
99
   * @uses   \Tfboe\FmLib\Entity\Traits\Competition
100
   * @uses   \Tfboe\FmLib\Entity\Traits\Competition
101
   * @uses   \Tfboe\FmLib\Entity\Traits\Game
102
   * @uses   \Tfboe\FmLib\Entity\Traits\Game
103
   * @uses   \Tfboe\FmLib\Entity\Helpers\NameEntity
104
   * @uses   \Tfboe\FmLib\Entity\Helpers\TimeEntity
105
   * @uses   \Tfboe\FmLib\Entity\Traits\Match
106
   * @uses   \Tfboe\FmLib\Entity\Traits\Match
107
   * @uses   \Tfboe\FmLib\Entity\Traits\Phase
108
   * @uses   \Tfboe\FmLib\Entity\Traits\Phase
109
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
110
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
111
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
112
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
113
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::getRankingSystems
114
   */
115
  public function testGetEarliestInfluenceGameLevel()
116
  {
117
    $ranking = $this->createStubWithId(RankingSystem::class);
118
    $timeService = $this->createMock(TimeServiceInterface::class);
119
    $timeService->expects(self::atLeastOnce())->method('clearTimes')->id('clearTimes');
120
    $timeService->method('getTime')->willReturnCallback(function (TournamentHierarchyInterface $entity) {
0 ignored issues
show
Bug introduced by
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.

Loading history...
121
      return $entity->getEndTime();
122
    })->after('clearTimes');
123
    /** @var RankingSystemInterface $ranking */
124
    $service = $this->getMockForAbstractClass(RankingSystemService::class,
125
      [$this->createMock(EntityManagerInterface::class),
126
        $timeService,
127
        $this->createMock(EntityComparerInterface::class),
128
        $this->createMock(ObjectCreatorServiceInterface::class)]);
129
    $service->method("getLevel")->willReturn(Level::GAME);
0 ignored issues
show
Bug introduced by
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.

Loading history...
130
    /** @var RankingSystemService $service */
131
    $tournament = new Tournament();
132
    $competition = new Competition();
133
    $competition->setName("TestCompetition")->setTournament($tournament);
0 ignored issues
show
Bug introduced by
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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
134
    $phase = new Phase();
135
    $phase->setPhaseNumber(1);
136
    $phase->setCompetition($competition);
137
    $match = new Match();
138
    $match->setMatchNumber(1);
139
    $match->setPhase($phase);
140
    self::assertNull($service->getEarliestInfluence($ranking, $tournament));
141
142
    $tournament->getRankingSystems()->set($ranking->getId(), $ranking);
143
    self::assertNull($service->getEarliestInfluence($ranking, $tournament));
144
145
    $game = new Game();
146
    $game->setGameNumber(1);
147
    $game->setMatch($match);
148
    $gameEndTime = new \DateTime("2017-06-01 00:00:00");
149
    $game->setEndTime($gameEndTime);
150
    self::assertEquals($gameEndTime, $service->getEarliestInfluence($ranking, $tournament));
151
152
    $game2 = new Game();
153
    $game2->setGameNumber(2);
154
    $game2->setMatch($match);
155
    $game2EndTime = new \DateTime("2017-05-01 00:00:00");
156
    $game2->setEndTime($game2EndTime);
157
    self::assertEquals($game2EndTime, $service->getEarliestInfluence($ranking, $tournament));
158
159
    $game3 = new Game();
160
    $game3->setGameNumber(3);
161
    $game3->setMatch($match);
162
    $game3EndTime = new \DateTime("2017-07-01 00:00:00");
163
    $game3->setEndTime($game3EndTime);
164
    self::assertEquals($game2EndTime, $service->getEarliestInfluence($ranking, $tournament));
165
  }
166
167
  /**
168
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestInfluence
169
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestEntityInfluence
170
   * @uses   \Tfboe\FmLib\Entity\Traits\Competition
171
   * @uses   \Tfboe\FmLib\Entity\Traits\Competition
172
   * @uses   \Tfboe\FmLib\Entity\Traits\Game
173
   * @uses   \Tfboe\FmLib\Entity\Traits\Game
174
   * @uses   \Tfboe\FmLib\Entity\Helpers\NameEntity
175
   * @uses   \Tfboe\FmLib\Entity\Helpers\TimeEntity
176
   * @uses   \Tfboe\FmLib\Entity\Traits\Match
177
   * @uses   \Tfboe\FmLib\Entity\Traits\Match
178
   * @uses   \Tfboe\FmLib\Entity\Traits\Phase
179
   * @uses   \Tfboe\FmLib\Entity\Traits\Phase
180
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
181
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
182
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
183
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
184
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::getRankingSystems
185
   * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
186
   */
187
  public function testGetEarliestInfluenceGameLevelWithDifferentImpactLevels()
188
  {
189
    $ranking = $this->createStubWithId(RankingSystem::class);
190
    $timeService = $this->createMock(TimeServiceInterface::class);
191
    $timeService->expects(self::atLeastOnce())->method('clearTimes')->id('clearTimes');
192
    $timeService->method('getTime')->willReturnCallback(function (TournamentHierarchyInterface $entity) {
0 ignored issues
show
Bug introduced by
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.

Loading history...
193
      return $entity->getEndTime();
194
    })->after('clearTimes');
195
    /** @var RankingSystemInterface $ranking */
196
    $service = $this->getMockForAbstractClass(RankingSystemService::class,
197
      [$this->createMock(EntityManagerInterface::class),
198
        $timeService,
199
        $this->createMock(EntityComparerInterface::class),
200
        $this->createMock(ObjectCreatorServiceInterface::class)]);
201
    $service->method("getLevel")->willReturn(Level::GAME);
0 ignored issues
show
Bug introduced by
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.

Loading history...
202
    /** @var RankingSystemService $service */
203
    $tournament = new Tournament();
204
    $competition = new Competition();
205
    $competition->setName("TestCompetition")->setTournament($tournament);
0 ignored issues
show
Bug introduced by
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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
206
    $phase = new Phase();
207
    $phase->setPhaseNumber(1);
208
    $phase->setCompetition($competition);
209
    $match = new Match();
210
    $match->setMatchNumber(1);
211
    $match->setPhase($phase);
212
    $game = new Game();
213
    $game->setGameNumber(1);
214
    $game->setMatch($match);
215
    $endTime1 = new \DateTime("2017-12-01 00:00:00");
216
    $game->setEndTime($endTime1);
217
    $game->getRankingSystems()->set($ranking->getId(), $ranking);
218
    self::assertEquals($endTime1, $service->getEarliestInfluence($ranking, $tournament));
219
220
    $game2 = new Game();
221
    $game2->setGameNumber(2);
222
    $game2->setMatch($match);
223
    $endTime2 = new \DateTime("2017-11-01 00:00:00");
224
    $game2->setEndTime($endTime2);
225
    self::assertEquals($endTime1, $service->getEarliestInfluence($ranking, $tournament));
226
227
    $match->getRankingSystems()->set($ranking->getId(), $ranking);
228
    self::assertEquals($endTime2, $service->getEarliestInfluence($ranking, $tournament));
229
230
    $match2 = new Match();
231
    $match2->setMatchNumber(2);
232
    $match2->setPhase($phase);
233
    $game3 = new Game();
234
    $game3->setGameNumber(1);
235
    $game3->setMatch($match2);
236
    $endTime3 = new \DateTime("2017-10-01 00:00:00");
237
    $game3->setEndTime($endTime3);
238
    self::assertEquals($endTime2, $service->getEarliestInfluence($ranking, $tournament));
239
240
    $phase->getRankingSystems()->set($ranking->getId(), $ranking);
241
    self::assertEquals($endTime3, $service->getEarliestInfluence($ranking, $tournament));
242
243
    $phase2 = new Phase();
244
    $phase2->setPhaseNumber(2);
245
    $phase2->setCompetition($competition);
246
    $match3 = new Match();
247
    $match3->setMatchNumber(1);
248
    $match3->setPhase($phase2);
249
    $game4 = new Game();
250
    $game4->setGameNumber(1);
251
    $game4->setMatch($match3);
252
    $endTime4 = new \DateTime("2017-09-01 00:00:00");
253
    $game4->setEndTime($endTime4);
254
    self::assertEquals($endTime3, $service->getEarliestInfluence($ranking, $tournament));
255
256
    $competition->getRankingSystems()->set($ranking->getId(), $ranking);
257
    self::assertEquals($endTime4, $service->getEarliestInfluence($ranking, $tournament));
258
259
    $competition2 = new Competition();
260
    $competition2->setName("TestCompetition2")->setTournament($tournament);
0 ignored issues
show
Bug introduced by
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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
261
    $phase3 = new Phase();
262
    $phase3->setPhaseNumber(1);
263
    $phase3->setCompetition($competition2);
264
    $match4 = new Match();
265
    $match4->setMatchNumber(1);
266
    $match4->setPhase($phase3);
267
    $game5 = new Game();
268
    $game5->setGameNumber(1);
269
    $game5->setMatch($match4);
270
    $endTime5 = new \DateTime("2017-01-01 00:00:00");
271
    $game5->setEndTime($endTime5);
272
    self::assertEquals($endTime4, $service->getEarliestInfluence($ranking, $tournament));
273
274
    $game6 = new Game();
275
    $game6->setGameNumber(2);
276
    $game6->setMatch($match4);
277
    $endTime6 = new \DateTime("2017-10-01 00:00:00");
278
    $game6->setEndTime($endTime6);
279
    $game6->getRankingSystems()->set($ranking->getId(), $ranking);
280
    self::assertEquals($endTime4, $service->getEarliestInfluence($ranking, $tournament));
281
282
    $game7 = new Game();
283
    $game7->setGameNumber(3);
284
    $game7->setMatch($match4);
285
    $endTime7 = new \DateTime("2017-08-01 00:00:00");
286
    $game7->setEndTime($endTime7);
287
    $game7->getRankingSystems()->set($ranking->getId(), $ranking);
288
    self::assertEquals($endTime7, $service->getEarliestInfluence($ranking, $tournament));
289
  }
290
291
  /**
292
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestInfluence
293
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestEntityInfluence
294
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
295
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
296
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
297
   * @uses   \Tfboe\FmLib\Entity\Helpers\TimeEntity
298
   * @uses   \Tfboe\FmLib\Entity\Helpers\TimestampableEntity
299
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
300
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::getRankingSystems
301
   */
302
  public function testGetEarliestInfluenceTournamentLevel()
303
  {
304
    $ranking = $this->createStubWithId(RankingSystem::class);
305
    $timeService = $this->createMock(TimeServiceInterface::class);
306
    $timeService->expects(self::atLeastOnce())->method('clearTimes')->id('clearTimes');
307
    $timeService->method('getTime')->willReturnCallback(function (TournamentHierarchyInterface $entity) {
0 ignored issues
show
Bug introduced by
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.

Loading history...
308
      return $entity->getEndTime();
309
    })->after('clearTimes');
310
    /** @var RankingSystemInterface $ranking */
311
    $service = $this->getMockForAbstractClass(RankingSystemService::class,
312
      [$this->createMock(EntityManagerInterface::class),
313
        $timeService,
314
        $this->createMock(EntityComparerInterface::class),
315
        $this->createMock(ObjectCreatorServiceInterface::class)]);
316
    $service->method("getLevel")->willReturn(Level::TOURNAMENT);
0 ignored issues
show
Bug introduced by
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.

Loading history...
317
    /** @var RankingSystemService $service */
318
    $tournament = new Tournament();
319
    $tournament->getRankingSystems()->set($ranking->getId(), $ranking);
320
    $endTime = new \DateTime("2017-03-01 00:00:00");
321
    $tournament->setEndTime($endTime);
322
    self::assertEquals($endTime, $service->getEarliestInfluence($ranking, $tournament));
323
  }
324
325
  /**
326
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getAverage
327
   */
328
  public function testGetEmptyAverage()
329
  {
330
    /** @var $service RankingSystemService */
331
    $service = $this->getMockForAbstractClass(RankingSystemService::class, [], '', false);
332
333
    self::assertEquals(0.0, static::callProtectedMethod($service, 'getAverage', [[]]));
334
  }
335
336
  /**
337
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEntities
338
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
339
   */
340
  public function testGetEntities()
341
  {
342
    //create mock for input
343
    $ranking = $this->createMock(RankingSystem::class);
344
345
    //create service mock
346
    $service = $this->getMockForAbstractClass(RankingSystemService::class,
347
      [$this->createMock(EntityManagerInterface::class), $this->createMock(TimeServiceInterface::class),
348
        $this->createMock(EntityComparerInterface::class),
349
        $this->createMock(ObjectCreatorServiceInterface::class)]);
350
351
    //create mock for queryBuilder
352
    $entityList = ['e1', 'e2'];
353
    $query = $this->createMock(AbstractQuery::class);
354
    $query->expects(static::once())->method('getResult')->willReturn($entityList);
355
    //create query builder mock for getEntities
356
    $queryBuilder = $this->createMock(QueryBuilder::class);
357
    $queryBuilder->expects(static::once())->method('getQuery')->willReturn($query);
358
    $service->expects(static::once())->method('getEntitiesQueryBuilder')
359
      ->with($ranking, new \DateTime("2017-01-01"))->willReturn($queryBuilder);
360
361
    /** @var $service RankingSystemService */
362
    /** @noinspection PhpUnhandledExceptionInspection */
363
    self::assertEquals($entityList, static::getMethod(get_class($service), 'getEntities')
364
      ->invokeArgs($service, [$ranking, new \DateTime("2017-01-01"), new \DateTime("2018-01-01")]));
365
  }
366
367
  /**
368
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEntityManager
369
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
370
   */
371
  public function testGetEntityManager()
372
  {
373
    $entityManager = $this->createMock(EntityManagerInterface::class);
374
    $service = $this->getMockForAbstractClass(RankingSystemService::class, [$entityManager,
375
      $this->createMock(TimeServiceInterface::class), $this->createMock(EntityComparerInterface::class),
376
      $this->createMock(ObjectCreatorServiceInterface::class)]);
377
    $em = static::callProtectedMethod($service, 'getEntityManager');
378
    self::assertEquals($entityManager, $em);
379
  }
380
381
  /**
382
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEntriesOfPlayers
383
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getOrCreateRankingSystemListEntry
384
   */
385
  public function testGetEntriesOfPlayers()
386
  {
387
388
    /** @var $service RankingSystemService */
389
    $service = $this->getMockForAbstractClass(RankingSystemService::class, [], '', false);
390
391
    $entry1 = $this->createMock(RankingSystemListEntry::class);
392
    $entry2 = $this->createMock(RankingSystemListEntry::class);
393
    $entry3 = $this->createMock(RankingSystemListEntry::class);
394
395
    $entries = new ArrayCollection([1 => $entry1, 2 => $entry2, 3 => $entry3]);
396
    $list = $this->createStub(RankingSystemList::class, ['getEntries' => $entries]);
397
398
    $player1 = $this->createStub(Player::class, ['getId' => 1]);
399
    $player3 = $this->createStub(Player::class, ['getId' => 3]);
400
401
    $returnedEntries = static::callProtectedMethod($service, 'getEntriesOfPlayers',
402
      [new ArrayCollection([$player1, $player3]), $list]);
403
    self::assertEquals([$entry1, $entry3], $returnedEntries);
404
  }
405
406
  /**
407
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getOrCreateChange
408
   * @uses   \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData
409
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemChange
410
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
411
   * @uses   \Tfboe\FmLib\Entity\Helpers\SubClassData::setProperty
412
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getAdditionalChangeFields()
413
   */
414
  public function testGetOrCreateChangeCreateNewOne()
415
  {
416
    $persisted = null;
417
418
    [$entity, $ranking, $player] = $this->createEntities();
0 ignored issues
show
Bug introduced by
The variable $entity does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $ranking does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $player does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
419
    [$service, $entityManager] = $this->prepareCreateChange();
0 ignored issues
show
Bug introduced by
The variable $service does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $entityManager does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
420
    $entityManager->expects(self::once())->method('persist')->willReturnCallback(
421
      function (RankingSystemChangeInterface $change) use (&$persisted, $entity, $ranking, $player) {
422
        $persisted = $change;
423
        self::assertInstanceOf(RankingSystemChange::class, $change);
424
        self::assertEquals($entity, $change->getHierarchyEntity());
425
        self::assertEquals($ranking, $change->getRankingSystem());
426
        self::assertEquals($player, $change->getPlayer());
427
      });
428
    $service->method('getAdditionalFields')->willReturn(['additional' => 0.0]);
429
430
    $change = static::callProtectedMethod($service, 'getOrCreateChange', [$entity, $ranking, $player]);
431
    self::assertEquals($persisted, $change);
432
  }
433
434
  /**
435
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getOrCreateChange
436
   * @uses   \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData
437
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemChange
438
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
439
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getAdditionalChangeFields()
440
   */
441
  public function testGetOrCreateChangeCreateTwice()
442
  {
443
    [$entity, $ranking, $player] = $this->createEntities();
0 ignored issues
show
Bug introduced by
The variable $entity does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $ranking does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $player does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
444
    [$service, $entityManager] = $this->prepareCreateChange();
0 ignored issues
show
Bug introduced by
The variable $service does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $entityManager does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
445
    $entityManager->expects(self::once())->method('persist');
446
447
    $change = static::callProtectedMethod($service, 'getOrCreateChange', [$entity, $ranking, $player]);
448
    $change2 = static::callProtectedMethod($service, 'getOrCreateChange', [$entity, $ranking, $player]);
449
    self::assertEquals($change, $change2);
450
  }
451
452
  /**
453
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getOrCreateChange
454
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::deleteOldChanges
455
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::markOldChangesAsDeleted
456
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::flushAndForgetEntities
457
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getMaxDate
458
   * @uses   \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData
459
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemChange::init
460
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemChange
461
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemList
462
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
463
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::cloneInto
464
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEntities
465
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::recomputeBasedOn
466
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingFrom
467
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextGenerationTime
468
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextEntities
469
   */
470
  public function testGetOrCreateGetDeletedChange()
471
  {
472
    [$entity, $ranking, $player] = $this->createEntities();
0 ignored issues
show
Bug introduced by
The variable $entity does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $ranking does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $player does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
473
    $change = $this->createStub(RankingSystemChange::class,
474
      ['getRankingSystem' => $ranking, 'getPlayer' => $player, 'getHierarchyEntity' => $entity, 'getId' => "c1"]);
475
476
    $entityManager = $this->getEntityManagerMockForQuery([$change], null, ['persist', 'flush', 'detach', 'remove',
477
      'getRepository']);
478
    $entityManager->expects(self::once())->method('flush');
479
    $service = $this->prepareUpdateRankingFrom($ranking, $entityManager, null, 1, ['getChanges'], [$entity]);
0 ignored issues
show
Documentation introduced by
$entityManager is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>|null.

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...
480
    $service->expects(self::once())->method('getChanges')->willReturnCallback(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Tfboe\FmLib\Servi...m\RankingSystemService>.

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.

Loading history...
481
      function ($e) use ($service, $ranking, $player, $change) {
482
        $foundChange = static::callProtectedMethod($service, 'getOrCreateChange', [$e, $ranking, $player]);
483
        self::assertEquals($foundChange->getId(), $change->getId());
0 ignored issues
show
Bug introduced by
The method getId() 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.

Loading history...
484
        return [];
485
      });
486
    /** @noinspection PhpUnhandledExceptionInspection */
487
    $service->updateRankingFrom($ranking, new \DateTime('2017-02-28'));
488
  }
489
490
  /**
491
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getOrCreateChange
492
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::deleteOldChanges
493
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::markOldChangesAsDeleted
494
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::flushAndForgetEntities
495
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getMaxDate
496
   * @uses   \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData
497
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemChange::init
498
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemChange
499
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemList
500
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
501
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::cloneInto
502
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEntities
503
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::recomputeBasedOn
504
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingFrom
505
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextGenerationTime
506
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextEntities
507
   */
508
  public function testDontUseDeletedChange()
509
  {
510
    [$entity, $ranking, $player] = $this->createEntities();
0 ignored issues
show
Bug introduced by
The variable $entity does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $ranking does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $player does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
511
    $change = $this->createStub(RankingSystemChange::class,
512
      ['getRankingSystem' => $ranking, 'getPlayer' => $player, 'getHierarchyEntity' => $entity, 'getId' => "c1"]);
513
514
    $entityManager = $this->getEntityManagerMockForQuery([$change], null, ['persist', 'flush', 'detach', 'remove',
515
      'getRepository']);
516
    $entityManager->expects(self::once())->method('flush');
517
    $entityManager->expects(self::once())->method('remove')->with($change);
518
    $service = $this->prepareUpdateRankingFrom($ranking, $entityManager, null, 1, [], [$entity]);
0 ignored issues
show
Documentation introduced by
$entityManager is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>|null.

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...
519
    /** @noinspection PhpUnhandledExceptionInspection */
520
    $service->updateRankingFrom($ranking, new \DateTime('2017-02-28'));
521
  }
522
523
  /**
524
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getOrCreateChange
525
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::markOldChangesAsDeleted
526
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::deleteOldChanges
527
   * @uses   \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData
528
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemChange::init
529
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemChange
530
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemList
531
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
532
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::cloneInto
533
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEntities
534
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::recomputeBasedOn
535
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingFrom
536
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextGenerationTime
537
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::flushAndForgetEntities
538
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getMaxDate
539
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextEntities
540
   */
541
  public function testDoubleOldChange()
542
  {
543
    [$entity, $ranking, $player] = $this->createEntities();
0 ignored issues
show
Bug introduced by
The variable $entity does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $ranking does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $player does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
544
    $change1 = $this->createStub(RankingSystemChange::class,
545
      ['getRankingSystem' => $ranking, 'getPlayer' => $player, 'getHierarchyEntity' => $entity, 'getId' => "c1"]);
546
    $change2 = $this->createStub(RankingSystemChange::class,
547
      ['getRankingSystem' => $ranking, 'getPlayer' => $player, 'getHierarchyEntity' => $entity, 'getId' => "c2"]);
548
    self::assertNotEquals($change1->getId(), $change2->getId());
0 ignored issues
show
Bug introduced by
The method getId() 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.

Loading history...
549
550
    $entityManager = $this->getEntityManagerMockForQuery([$change1, $change2], null, ['persist', 'flush', 'remove',
551
      'getRepository']);
552
    $entityManager->expects(self::once())->method('flush');
553
    $entityManager->expects(self::exactly(2))->method('remove')->withConsecutive($change2, $change1);
554
    $service = $this->prepareUpdateRankingFrom($ranking, $entityManager, null, 1, ['deleteOldChanges']);
0 ignored issues
show
Documentation introduced by
$entityManager is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>|null.

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...
555
    /** @noinspection PhpUnhandledExceptionInspection */
556
    $service->updateRankingFrom($ranking, new \DateTime('2017-02-28'));
557
  }
558
559
  /**
560
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getOrCreateRankingSystemListEntry
561
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::startPoints
562
   * @uses   \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData
563
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemListEntry
564
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
565
   */
566
  public function testGetOrCreateRankingSystemListEntryExistingEntry()
567
  {
568
    $player = $this->createStubWithId(Player::class, 1, 'getId');
569
    $entries = new ArrayCollection([]);
570
    $list = $this->createStub(RankingSystemList::class, ['getEntries' => $entries]);
571
    $entry = $this->createStub(RankingSystemListEntry::class,
572
      ['getPlayer' => $player, 'getRankingSystemList' => $list]);
573
    $entries->set(1, $entry);
574
575
    /** @var RankingSystemService $service */
576
    $service = $this->getMockForAbstractClass(RankingSystemService::class, [], '', false);
577
    $foundEntry = static::callProtectedMethod($service, 'getOrCreateRankingSystemListEntry', [$list, $player]);
578
    self::assertEquals($entry, $foundEntry);
579
  }
580
581
  /**
582
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getOrCreateRankingSystemListEntry
583
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::startPoints
584
   * @covers   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::resetListEntry
585
   * @uses   \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData
586
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemListEntry
587
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
588
   * @uses   \Tfboe\FmLib\Entity\Helpers\SubClassData::setProperty
589
   */
590
  public function testGetOrCreateRankingSystemListEntryNewEntry()
591
  {
592
    $player = $this->createStubWithId(Player::class, 1, 'getId');
593
    $entries = new ArrayCollection([]);
594
    $list = $this->createStub(RankingSystemList::class, ['getEntries' => $entries]);
595
596
    /** @var RankingSystemListEntryInterface $createdEntry */
597
    $createdEntry = null;
598
    $entityManager = $this->createMock(EntityManager::class);
599
    $entityManager->expects(self::once())->method('persist')->willReturnCallback(
600
      function (RankingSystemListEntryInterface $entry) use (&$createdEntry, $player, $list) {
601
        $createdEntry = $entry;
602
      });
603
604
605
    $service = $this->getMockForAbstractClass(RankingSystemService::class, [$entityManager,
606
      $this->createMock(TimeServiceInterface::class), $this->createMock(EntityComparerInterface::class),
607
      $this->getObjectCreator()]);
608
    $service->method('getAdditionalFields')->willReturn(['additional' => 0.0]);
0 ignored issues
show
Bug introduced by
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.

Loading history...
609
    /** @var RankingSystemService $service */
610
611
    $entry = static::callProtectedMethod($service, 'getOrCreateRankingSystemListEntry', [$list, $player]);
612
    self::assertEquals($createdEntry, $entry);
613
    self::assertInstanceOf(RankingSystemListEntry::class, $entry);
614
    self::assertEquals($player, $entry->getPlayer());
615
    self::assertEquals($list, $entry->getRankingSystemList());
616
    self::assertEquals(1, $entries->count());
617
    self::assertEquals($entry, $entries[1]);
618
  }
619
620
  /**
621
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingForTournament
622
   * @uses   \Tfboe\FmLib\Entity\Helpers\TimeEntity
623
   * @uses   \Tfboe\FmLib\Entity\Helpers\TimestampableEntity
624
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
625
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
626
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
627
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestEntityInfluence
628
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestInfluence
629
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
630
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::getRankingSystems
631
   */
632
  public function testUpdateRankingForTournamentOldEarliestIsEarlier()
633
  {
634
    $ranking = $this->createStubWithId(RankingSystem::class);
635
    $timeService = $this->createMock(TimeServiceInterface::class);
636
    $timeService->expects(self::atLeastOnce())->method('clearTimes')->id('clearTimes');
637
    $timeService->method('getTime')->willReturnCallback(function (TournamentHierarchyInterface $entity) {
0 ignored issues
show
Bug introduced by
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.

Loading history...
638
      return $entity->getEndTime();
639
    })->after('clearTimes');
640
    $service = $this->getMockWithMockedArguments(RankingSystemService::class,
641
      [$this->createMock(EntityManagerInterface::class),
642
        $timeService], ['updateRankingFrom']);
643
    $service->method("getLevel")->willReturn(Level::TOURNAMENT);
0 ignored issues
show
Bug introduced by
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.

Loading history...
644
    /** @var RankingSystemInterface $ranking */
645
    $tournament = new Tournament();
646
    $endedAt = new \DateTime("2017-02-01 00:00:00");
647
    $tournament->setUpdatedAt($endedAt);
648
    $tournament->getRankingSystems()->set($ranking->getId(), $ranking);
649
    $oldInfluence = new \DateTime("2017-01-01 00:00:00");
650
    $service->expects(static::once())
651
      ->method('updateRankingFrom')
652
      ->with($ranking, new \DateTime("2017-01-01 00:00:00"));
653
654
    /** @var RankingSystemService $service */
655
    $service->updateRankingForTournament($ranking, $tournament, $oldInfluence);
656
  }
657
658
  /**
659
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingForTournament
660
   * @uses   \Tfboe\FmLib\Entity\Helpers\TimestampableEntity
661
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
662
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
663
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
664
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestEntityInfluence
665
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestInfluence
666
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
667
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::getRankingSystems
668
   */
669
  public function testUpdateRankingForTournamentOldEarliestIsNotNullAndTournamentNotRanked()
670
  {
671
    $ranking = $this->createStubWithId(RankingSystem::class);
672
    /** @var RankingSystemInterface $ranking */
673
    $tournament = new Tournament();
674
    $endedAt = new \DateTime("2017-01-01 00:00:00");
675
    $tournament->setUpdatedAt($endedAt);
676
    $service = $this->getMockWithMockedArguments(RankingSystemService::class, [], ['updateRankingFrom']);
677
    $service->method("getLevel")->willReturn(Level::TOURNAMENT);
0 ignored issues
show
Bug introduced by
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.

Loading history...
678
    $oldInfluence = new \DateTime("2017-02-01 00:00:00");
679
    $service->expects(static::once())
680
      ->method('updateRankingFrom')
681
      ->with($ranking, new \DateTime("2017-02-01 00:00:00"));
682
683
    /** @var RankingSystemService $service */
684
    $service->updateRankingForTournament($ranking, $tournament, $oldInfluence);
685
  }
686
687
  /**
688
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingForTournament
689
   * @uses   \Tfboe\FmLib\Entity\Helpers\TimeEntity
690
   * @uses   \Tfboe\FmLib\Entity\Helpers\TimestampableEntity
691
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
692
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
693
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
694
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestEntityInfluence
695
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestInfluence
696
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
697
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::getRankingSystems
698
   */
699
  public function testUpdateRankingForTournamentOldEarliestIsNull()
700
  {
701
    $ranking = $this->createStubWithId(RankingSystem::class);
702
    /** @var RankingSystemInterface $ranking */
703
    $tournament = new Tournament();
704
    $endedAt = new \DateTime("2017-01-01 00:00:00");
705
    $tournament->setEndTime($endedAt);
706
    $tournament->getRankingSystems()->set($ranking->getId(), $ranking);
707
    $timeService = $this->createMock(TimeServiceInterface::class);
708
    $timeService->expects(self::atLeastOnce())->method('clearTimes')->id('clearTimes');
709
    $timeService->method('getTime')->willReturnCallback(function (TournamentHierarchyInterface $entity) {
0 ignored issues
show
Bug introduced by
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.

Loading history...
710
      return $entity->getEndTime();
711
    })->after('clearTimes');
712
    $service = $this->getMockWithMockedArguments(RankingSystemService::class,
713
      [$this->createMock(EntityManagerInterface::class),
714
        $timeService], ['updateRankingFrom']);
715
    $service->method("getLevel")->willReturn(Level::TOURNAMENT);
0 ignored issues
show
Bug introduced by
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.

Loading history...
716
    $service->expects(static::once())
717
      ->method('updateRankingFrom')
718
      ->with($ranking, new \DateTime("2017-01-01 00:00:00"));
719
720
    /** @var RankingSystemService $service */
721
    $service->updateRankingForTournament($ranking, $tournament, null);
722
  }
723
724
  /**
725
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingForTournament
726
   * @uses   \Tfboe\FmLib\Entity\Helpers\TimestampableEntity
727
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
728
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
729
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
730
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestEntityInfluence
731
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestInfluence
732
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
733
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::getRankingSystems
734
   */
735
  public function testUpdateRankingForTournamentOldEarliestIsNullAndTournamentNotRanked()
736
  {
737
    $ranking = $this->createStubWithId(RankingSystem::class);
738
    /** @var RankingSystemInterface $ranking */
739
    $tournament = new Tournament();
740
    $endedAt = new \DateTime("2017-01-01 00:00:00");
741
    $tournament->setUpdatedAt($endedAt);
742
    $service = $this->getMockWithMockedArguments(RankingSystemService::class,
743
      [], ['updateRankingFrom']);
744
    $service->method("getLevel")->willReturn(Level::TOURNAMENT);
0 ignored issues
show
Bug introduced by
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.

Loading history...
745
    $service->expects(self::never())
746
      ->method('updateRankingFrom');
747
748
    /** @var RankingSystemService $service */
749
    $service->updateRankingForTournament($ranking, $tournament, null);
750
  }
751
752
  //TODO split this up in multiple unit tests!!!
753
754
  /**
755
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingForTournament
756
   * @uses   \Tfboe\FmLib\Entity\Helpers\TimeEntity
757
   * @uses   \Tfboe\FmLib\Entity\Helpers\TimestampableEntity
758
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
759
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament
760
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
761
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestEntityInfluence
762
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEarliestInfluence
763
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
764
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::getRankingSystems
765
   */
766
  public function testUpdateRankingForTournamentTournamentIsEarlier()
767
  {
768
    $ranking = $this->createStubWithId(RankingSystem::class);
769
    /** @var RankingSystemInterface $ranking */
770
    $tournament = new Tournament();
771
    $endedAt = new \DateTime("2017-01-01");
772
    $tournament->setEndTime($endedAt);
773
    $tournament->getRankingSystems()->set($ranking->getId(), $ranking);
774
    $timeService = $this->createMock(TimeServiceInterface::class);
775
    $timeService->expects(self::atLeastOnce())->method('clearTimes')->id('clearTimes');
776
    $timeService->method('getTime')->willReturnCallback(function (TournamentHierarchyInterface $entity) {
0 ignored issues
show
Bug introduced by
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.

Loading history...
777
      return $entity->getEndTime();
778
    })->after('clearTimes');
779
    $service = $this->getMockWithMockedArguments(RankingSystemService::class,
780
      [$this->createMock(EntityManagerInterface::class), $timeService], ['updateRankingFrom']);
781
    $service->method("getLevel")->willReturn(Level::TOURNAMENT);
0 ignored issues
show
Bug introduced by
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.

Loading history...
782
    $oldInfluence = new \DateTime("2017-02-01");
783
    $service->expects(static::once())
784
      ->method('updateRankingFrom')
785
      ->with($ranking, new \DateTime("2017-01-01"));
786
787
    /** @var RankingSystemService $service */
788
    $service->updateRankingForTournament($ranking, $tournament, $oldInfluence);
789
  }
790
791
  /**
792
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingFrom
793
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::recomputeBasedOn
794
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::cloneInto
795
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextGenerationTime
796
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextEntities
797
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::resetListEntry
798
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getMaxDate
799
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::flushAndForgetEntities
800
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::markOldChangesAsDeleted
801
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
802
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEntities
803
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::deleteOldChanges
804
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemListEntry
805
   * @uses   \Tfboe\FmLib\Entity\Helpers\SubClassData::cloneSubClassDataFrom
806
   * @uses   \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData
807
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getOrCreateRankingSystemListEntry
808
   * @uses   \Tfboe\FmLib\Entity\Helpers\SubClassData::getProperty
809
   * @uses   \Tfboe\FmLib\Entity\Helpers\SubClassData::setProperty
810
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemChange
811
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::startPoints
812
   */
813
  public function testUpdateRankingFrom()
814
  {
815
    //create mock for input
816
    $ranking = $this->createStubWithId(RankingSystem::class);
817
    $ranking->method('getGenerationInterval')->willReturn(-1);
0 ignored issues
show
Bug introduced by
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.

Loading history...
818
819
    //create mocks for ranking lists
820
    $list1 = $this->createMock(RankingSystemList::class);
821
    $list1->method('isCurrent')->willReturn(false);
0 ignored issues
show
Bug introduced by
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.

Loading history...
822
    $list1->method('getLastEntryTime')->willReturn(new \DateTime("2017-01-01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
823
    $list1->method('getRankingSystem')->willReturn($ranking);
0 ignored issues
show
Bug introduced by
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.

Loading history...
824
825
    $entry1 = $this->createEmptyEntry();
826
    $entry2 = $this->createEmptyEntry();
827
    $entry3 = $this->createEmptyEntry();
828
829
    $list2 = $this->createMock(RankingSystemList::class);
830
    $list2->method('isCurrent')->willReturn(false);
0 ignored issues
show
Bug introduced by
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.

Loading history...
831
    $list2->method('getLastEntryTime')->willReturn(new \DateTime("2017-02-01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
832
    $list2->method('getEntries')->willReturn(new ArrayCollection([1 => $entry1, 3 => $entry3]));
0 ignored issues
show
Bug introduced by
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.

Loading history...
833
    $list2->method('getRankingSystem')->willReturn($ranking);
0 ignored issues
show
Bug introduced by
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.

Loading history...
834
835
    $list3 = $this->createMock(RankingSystemList::class);
836
    $list3->method('isCurrent')->willReturn(false);
0 ignored issues
show
Bug introduced by
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.

Loading history...
837
    $list3->method('getLastEntryTime')->willReturn(new \DateTime("2017-03-01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
838
    $list3->method('getEntries')->willReturn(new ArrayCollection([1 => $entry1, 2 => $entry2]));
0 ignored issues
show
Bug introduced by
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.

Loading history...
839
    $list3->method('getRankingSystem')->willReturn($ranking);
0 ignored issues
show
Bug introduced by
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.

Loading history...
840
841
    $list4 = $this->createMock(RankingSystemList::class);
842
    $list4->method('isCurrent')->willReturn(false);
0 ignored issues
show
Bug introduced by
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.

Loading history...
843
    $list4->method('getLastEntryTime')->willReturn(new \DateTime("2017-04-01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
844
    $list4->method('getEntries')->willReturn(new ArrayCollection());
0 ignored issues
show
Bug introduced by
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.

Loading history...
845
    $list4->method('getRankingSystem')->willReturn($ranking);
0 ignored issues
show
Bug introduced by
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.

Loading history...
846
847
    $list5 = $this->createMock(RankingSystemList::class);
848
    $list5->method('isCurrent')->willReturn(true);
0 ignored issues
show
Bug introduced by
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.

Loading history...
849
    $list5->method('getLastEntryTime')->willReturn(new \DateTime("2017-05-01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
850
    $list5->method('getEntries')->willReturn(new ArrayCollection());
0 ignored issues
show
Bug introduced by
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.

Loading history...
851
    $list5->method('getRankingSystem')->willReturn($ranking);
0 ignored issues
show
Bug introduced by
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.

Loading history...
852
853
    $lists = $this->createMock(Collection::class);
854
    $lists->expects(static::once())->method('toArray')->willReturn([$list1, $list2, $list3, $list4, $list5]);
855
856
    //finish mock for input
857
    $ranking->expects(static::once())->method('getLists')->willReturn($lists);
858
859
    //create time service, entity comparer and ranking service mock
860
    $timeService = $this->createMock(TimeServiceInterface::class);
861
    $timeService->expects(self::atLeastOnce())->method('clearTimes')->id('clearTimes');
862
    $timeService->method('getTime')->willReturnCallback(function (TournamentHierarchyInterface $entity) {
0 ignored issues
show
Bug introduced by
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.

Loading history...
863
      return $entity->getEndTime();
864
    })->after('clearTimes');
865
    $entityComparer = $this->createMock(EntityComparerInterface::class);
866
    $entityComparer->method('compareEntities')->willReturnCallback(
0 ignored issues
show
Bug introduced by
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.

Loading history...
867
      function (TournamentHierarchyInterface $entity1, TournamentHierarchyInterface $entity2) {
868
        return $entity1->getEndTime() <=> $entity2->getEndTime();
869
      });
870
    $entityManager = $this->getEntityManagerMockForQuery([],
871
      'SELECT c FROM Tfboe\FmLib\Entity\RankingSystemChangeInterface c WHERE c.rankingSystem = :ranking' .
872
      ' AND c.hierarchyEntity IN(:entities)', ['persist', 'remove', 'flush', 'detach'], 3);
873
    $service = $this->getMockWithMockedArguments(RankingSystemService::class,
874
      [$entityManager,
875
        $timeService,
876
        $this->createMock(EntityComparerInterface::class),
877
        $this->getObjectCreator()]);
878
879
    //create entities mocks
880
    $entity1 = $this->createStubWithId(TournamentHierarchyEntity::class, "e1");
881
    $entity1->method('getEndTime')->willReturn(new \DateTime("2017-03-01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
882
883
    $entity2 = $this->createStubWithId(TournamentHierarchyEntity::class, "e2");
884
    $entity2->method('getEndTime')->willReturn(new \DateTime("2017-02-01 00:00:01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
885
886
    $entity3 = $this->createStubWithId(TournamentHierarchyEntity::class, "e3");
887
    $entity3->method('getEndTime')->willReturn(new \DateTime("2017-05-02"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
888
889
    $entity4 = $this->createStubWithId(TournamentHierarchyEntity::class, "e4");
890
    $entity4->method('getEndTime')->willReturn(new \DateTime("2017-03-02"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
891
892
    $parent = $this->createStubWithId(TournamentHierarchyEntity::class, "e4");
893
    $parent->method('getEndTime')->willReturn(new \DateTime("2017-12-02"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
894
    $entity4->method('getParent')->willReturn($parent);
0 ignored issues
show
Bug introduced by
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.

Loading history...
895
896
    //create query mock for getEntities
897
    $query3 = $this->createMock(AbstractQuery::class);
898
    $query3->expects(static::once())->method('getResult')->willReturn([$entity1, $entity2, $entity3, $entity4]);
899
    $queryBuilder3 = $this->createMock(QueryBuilder::class);
900
    $queryBuilder3->expects(static::once())->method('getQuery')->willReturn($query3);
901
902
    $query4 = $this->createMock(AbstractQuery::class);
903
    $query4->expects(static::once())->method('getResult')->willReturn([$entity1, $entity2, $entity3, $entity4]);
904
    $queryBuilder4 = $this->createMock(QueryBuilder::class);
905
    $queryBuilder4->expects(static::once())->method('getQuery')->willReturn($query4);
906
907
    $query5 = $this->createMock(AbstractQuery::class);
908
    $query5->expects(static::once())->method('getResult')->willReturn([$entity1, $entity2, $entity3, $entity4]);
909
    $queryBuilder5 = $this->createMock(QueryBuilder::class);
910
    $queryBuilder5->expects(static::once())->method('getQuery')->willReturn($query5);
911
912
    $service->method('getEntitiesQueryBuilder')
0 ignored issues
show
Bug introduced by
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.

Loading history...
913
      ->withConsecutive([$ranking, new \DateTime("2017-02-01"), new \DateTime("2017-03-01")],
914
        [$ranking, new \DateTime("2017-03-01"), new \DateTime("2017-04-01")],
915
        [$ranking, new \DateTime("2017-04-01")])
916
      ->willReturnOnConsecutiveCalls($queryBuilder3, $queryBuilder4, $queryBuilder5);
917
    $changes = [
918
      $this->createEmptyChange(),
919
      $this->createEmptyChange(),
920
    ];
921
    $service->method('getChanges')->willReturn($changes);
0 ignored issues
show
Bug introduced by
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.

Loading history...
922
    $service->method('getAdditionalFields')->willReturn(['additional' => 0.0]);
0 ignored issues
show
Bug introduced by
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.

Loading history...
923
924
    /** @var RankingSystemService $service */
925
    /** @var RankingSystemInterface $ranking */
926
    /** @noinspection PhpUnhandledExceptionInspection */
927
    $service->updateRankingFrom($ranking, new \DateTime('2017-02-28'));
0 ignored issues
show
Bug introduced by
The method updateRankingFrom() 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.

Loading history...
928
  }
929
930
  /**
931
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingFrom
932
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::recomputeBasedOn
933
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::cloneInto
934
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextGenerationTime
935
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextEntities
936
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::flushAndForgetEntities
937
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::markOldChangesAsDeleted
938
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemList
939
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
940
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEntities
941
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::deleteOldChanges
942
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getMaxDate
943
   */
944
  public function testUpdateRankingFromCalledTwice()
945
  {
946
    $ranking = $this->createStubWithId(RankingSystem::class);
947
    $service = $this->prepareUpdateRankingFrom($ranking, $this->getEntityManagerMockForQuery([], null, ['flush']));
0 ignored issues
show
Documentation introduced by
$this->getEntityManagerM..., null, array('flush')) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>|null.

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...
948
949
    /** @var RankingSystemInterface $ranking */
950
951
    /** @noinspection PhpUnhandledExceptionInspection */
952
    $service->updateRankingFrom($ranking, new \DateTime('2017-02-28'));
0 ignored issues
show
Documentation introduced by
$ranking is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Tfboe\FmLib\Entity\RankingSystemInterface>.

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...
953
954
    $this->expectException(PreconditionFailedException::class);
955
956
    /** @noinspection PhpUnhandledExceptionInspection */
957
    $service->updateRankingFrom($ranking, new \DateTime('2017-02-28'));
0 ignored issues
show
Documentation introduced by
$ranking is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Tfboe\FmLib\Entity\RankingSystemInterface>.

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...
958
  }
959
960
  /**
961
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingFrom
962
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::recomputeBasedOn
963
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::cloneInto
964
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextGenerationTime
965
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextEntities
966
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::flushAndForgetEntities
967
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::markOldChangesAsDeleted
968
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemList
969
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
970
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEntities
971
   * @uses   \Tfboe\FmLib\Entity\Helpers\UUIDEntity::getId
972
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::deleteOldChanges
973
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getMaxDate
974
   */
975
  public function testUpdateRankingFromNoCurrent()
976
  {
977
    //create mock for input
978
    $ranking = $this->createStubWithId(RankingSystem::class, 'r1');
979
    $ranking->method('getGenerationInterval')->willReturn(AutomaticInstanceGeneration::MONTHLY);
0 ignored issues
show
Bug introduced by
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.

Loading history...
980
981
    //create mocks for ranking lists
982
    $list = $this->createMock(RankingSystemList::class);
983
    $list->method('isCurrent')->willReturn(false);
0 ignored issues
show
Bug introduced by
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.

Loading history...
984
    $list->method('getLastEntryTime')->willReturn(new \DateTime("2017-12-01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
985
    $list->method('getEntries')->willReturn(new ArrayCollection());
0 ignored issues
show
Bug introduced by
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.

Loading history...
986
    $list->method('getRankingSystem')->willReturn($ranking);
0 ignored issues
show
Bug introduced by
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.

Loading history...
987
988
    $lists = $this->createMock(Collection::class);
989
    $lists->expects(static::once())->method('toArray')->willReturn([$list]);
990
    $lists->expects(static::once())->method('set')->with('new')->willReturnSelf();
991
992
    //finish mock for input
993
    $ranking->expects(static::exactly(2))->method('getLists')->willReturn($lists);
994
995
    //create service mock
996
    $entityManager = $this->getEntityManagerMockForQuery([],
997
      'SELECT c FROM Tfboe\FmLib\Entity\RankingSystemChangeInterface c WHERE c.rankingSystem = :ranking' .
998
      ' AND c.hierarchyEntity IN(:entities)', ['persist', 'flush']);
999
    $entityManager->expects(static::once())->method('persist')->willReturnCallback(
1000
      function (RankingSystemListInterface $entity) {
1001
        self::assertInstanceOf(RankingSystemList::class, $entity);
1002
        self::assertTrue($entity->isCurrent());
1003
        static::getProperty(get_class($entity), 'id')->setValue($entity, 'new');
1004
      });
1005
    $service = $this->getMockWithMockedArguments(RankingSystemService::class, [$entityManager,
1006
      $this->createMock(TimeServiceInterface::class), $this->createMock(EntityComparerInterface::class),
1007
      $this->getObjectCreator()]);
1008
1009
    //create query mock for getEntities
1010
    $query = $this->createMock(AbstractQuery::class);
1011
    $query->expects(static::once())->method('getResult')->willReturn([]);
1012
    //create query builder mock for getEntities
1013
    $queryBuilder = $this->createMock(QueryBuilder::class);
1014
    $queryBuilder->expects(static::once())->method('getQuery')->willReturn($query);
1015
    $service->expects(static::once())->method('getEntitiesQueryBuilder')
1016
      ->with($ranking, new \DateTime("2017-12-01"))->willReturn($queryBuilder);
1017
1018
    /** @var RankingSystemService $service */
1019
    /** @var RankingSystemInterface $ranking */
1020
    /** @noinspection PhpUnhandledExceptionInspection */
1021
    /** @noinspection PhpUnhandledExceptionInspection */
1022
    /** @noinspection PhpUnhandledExceptionInspection */
1023
    /** @noinspection PhpUnhandledExceptionInspection */
1024
    $service->updateRankingFrom($ranking, new \DateTime('2018-02-28'));
0 ignored issues
show
Bug introduced by
The method updateRankingFrom() 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.

Loading history...
1025
  }
1026
1027
  /**
1028
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingFrom
1029
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::recomputeBasedOn
1030
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::cloneInto
1031
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextGenerationTime
1032
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextEntities
1033
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::flushAndForgetEntities
1034
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::markOldChangesAsDeleted
1035
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemList
1036
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
1037
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEntities
1038
   * @uses   \Tfboe\FmLib\Entity\Helpers\UUIDEntity::getId
1039
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::deleteOldChanges
1040
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getMaxDate
1041
   */
1042
  public function testUpdateRankingCreateMonthlyLists()
1043
  {
1044
    //create mock for input
1045
    $ranking = $this->createStubWithId(RankingSystem::class, 'r1');
1046
    $ranking->method('getGenerationInterval')->willReturn(AutomaticInstanceGeneration::MONTHLY);
0 ignored issues
show
Bug introduced by
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.

Loading history...
1047
1048
    //create mocks for ranking lists
1049
    $list = $this->createMock(RankingSystemList::class);
1050
    $list->method('isCurrent')->willReturn(true);
0 ignored issues
show
Bug introduced by
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.

Loading history...
1051
    $list->method('getLastEntryTime')->willReturn(new \DateTime("2017-12-01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
1052
    $list->method('getEntries')->willReturn(new ArrayCollection());
0 ignored issues
show
Bug introduced by
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.

Loading history...
1053
    $list->method('getRankingSystem')->willReturn($ranking);
0 ignored issues
show
Bug introduced by
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.

Loading history...
1054
1055
    $lists = $this->createMock(Collection::class);
1056
    $lists->expects(static::once())->method('toArray')->willReturn([$list]);
1057
    $lists->expects(static::once())->method('set')->with('new')->willReturnSelf();
1058
1059
    //create entities mocks
1060
    $entity1 = $this->createStubWithId(TournamentHierarchyEntity::class, "e1");
1061
    $entity1->method('getEndTime')->willReturn(new \DateTime("2018-03-01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
1062
1063
    $entity2 = $this->createStubWithId(TournamentHierarchyEntity::class, "e2");
1064
    $entity2->method('getEndTime')->willReturn(new \DateTime("2018-04-01 00:00:01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
1065
1066
    //finish mock for input
1067
    $ranking->expects(static::exactly(2))->method('getLists')->willReturn($lists);
1068
1069
    //create service mock
1070
    $entityManager = $this->getEntityManagerMockForQuery([],
1071
      'SELECT c FROM Tfboe\FmLib\Entity\RankingSystemChangeInterface c WHERE c.rankingSystem = :ranking' .
1072
      ' AND c.hierarchyEntity IN(:entities)', ['persist', 'flush', 'detach']);
1073
    $entityManager->expects(static::once())->method('persist')->willReturnCallback(
1074
      function (RankingSystemListInterface $entity) {
1075
        self::assertInstanceOf(RankingSystemList::class, $entity);
1076
        static::getProperty(get_class($entity), 'id')->setValue($entity, 'new');
1077
      });
1078
    $timeService = $this->createMock(TimeServiceInterface::class);
1079
    $timeService->method('getTime')->willReturnCallback(function (TournamentHierarchyInterface $entity) {
0 ignored issues
show
Bug introduced by
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.

Loading history...
1080
      return $entity->getEndTime();
1081
    });
1082
    $service = $this->getMockWithMockedArguments(RankingSystemService::class, [$entityManager,
1083
      $timeService, $this->createMock(EntityComparerInterface::class),
1084
      $this->getObjectCreator()]);
1085
1086
    //create query mock for getEntities
1087
    $query = $this->createMock(AbstractQuery::class);
1088
    $query->expects(static::once())->method('getResult')->willReturn([$entity1, $entity2]);
1089
    //create query builder mock for getEntities
1090
    $queryBuilder = $this->createMock(QueryBuilder::class);
1091
    $queryBuilder->expects(static::once())->method('getQuery')->willReturn($query);
1092
    $service->expects(static::once())->method('getEntitiesQueryBuilder')
1093
      ->with($ranking, new \DateTime("2017-12-01"))->willReturn($queryBuilder);
1094
1095
    /** @var RankingSystemService $service */
1096
    /** @var RankingSystemInterface $ranking */
1097
    /** @noinspection PhpUnhandledExceptionInspection */
1098
    /** @noinspection PhpUnhandledExceptionInspection */
1099
    /** @noinspection PhpUnhandledExceptionInspection */
1100
    /** @noinspection PhpUnhandledExceptionInspection */
1101
    $service->updateRankingFrom($ranking, new \DateTime('2018-02-28'));
0 ignored issues
show
Bug introduced by
The method updateRankingFrom() 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.

Loading history...
1102
  }
1103
1104
  /**
1105
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingFrom
1106
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::recomputeBasedOn
1107
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::cloneInto
1108
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextGenerationTime
1109
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextEntities
1110
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::flushAndForgetEntities
1111
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::markOldChangesAsDeleted
1112
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemList
1113
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
1114
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEntities
1115
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::deleteOldChanges
1116
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getMaxDate
1117
   */
1118
  public function testUpdateRankingFromNoReusable()
1119
  {
1120
    $ranking = $this->createStubWithId(RankingSystem::class);
1121
    $service = $this->prepareUpdateRankingFrom($ranking, $this->getEntityManagerMockForQuery([], null, ['flush']));
0 ignored issues
show
Documentation introduced by
$this->getEntityManagerM..., null, array('flush')) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>|null.

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...
1122
1123
    /** @var RankingSystemInterface $ranking */
1124
1125
    /** @var RankingSystemService $service */
1126
    /** @var RankingSystemInterface $ranking */
1127
    /** @noinspection PhpUnhandledExceptionInspection */
1128
    $service->updateRankingFrom($ranking, new \DateTime('2017-02-28'));
0 ignored issues
show
Documentation introduced by
$ranking is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Tfboe\FmLib\Entity\RankingSystemInterface>.

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...
1129
  }
1130
1131
  /**
1132
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::updateRankingFrom
1133
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::recomputeBasedOn
1134
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::cloneInto
1135
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextGenerationTime
1136
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getNextEntities
1137
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::flushAndForgetEntities
1138
   * @covers \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::markOldChangesAsDeleted
1139
   * @uses   \Tfboe\FmLib\Entity\Traits\RankingSystemList
1140
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct
1141
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEntities
1142
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::deleteOldChanges
1143
   * @uses   \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getMaxDate
1144
   */
1145
  public function testUpdateRankingFromNoEntities()
1146
  {
1147
    $ranking = $this->createStubWithId(RankingSystem::class);
1148
1149
    //create mocks for ranking lists
1150
    $list = $this->createMock(RankingSystemList::class);
1151
    $list->method('isCurrent')->willReturn(false);
0 ignored issues
show
Bug introduced by
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.

Loading history...
1152
    $list->method('getLastEntryTime')->willReturn(new \DateTime("2017-12-01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
1153
    $list->method('getEntries')->willReturn(new ArrayCollection());
0 ignored issues
show
Bug introduced by
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.

Loading history...
1154
    $list->method('getRankingSystem')->willReturn($ranking);
0 ignored issues
show
Bug introduced by
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.

Loading history...
1155
1156
    $current = $this->createMock(RankingSystemList::class);
1157
    $current->method('isCurrent')->willReturn(true);
0 ignored issues
show
Bug introduced by
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.

Loading history...
1158
    $current->method('getLastEntryTime')->willReturn(new \DateTime("2017-12-01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
1159
    $current->method('getEntries')->willReturn(new ArrayCollection());
0 ignored issues
show
Bug introduced by
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.

Loading history...
1160
    $current->method('getRankingSystem')->willReturn($ranking);
0 ignored issues
show
Bug introduced by
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.

Loading history...
1161
1162
    $service = $this->prepareUpdateRankingFrom($ranking, $this->getEntityManagerMockForQuery([], null,
0 ignored issues
show
Documentation introduced by
$this->getEntityManagerM...'flush', 'persist'), 2) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>|null.

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...
1163
      ['flush', 'persist'], 2), [$list, $current], 2);
1164
    /** @var RankingSystemInterface $ranking */
1165
1166
    /** @var RankingSystemService $service */
1167
    /** @var RankingSystemInterface $ranking */
1168
    /** @noinspection PhpUnhandledExceptionInspection */
1169
    $service->updateRankingFrom($ranking, new \DateTime('2017-02-28'));
0 ignored issues
show
Documentation introduced by
$ranking is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Tfboe\FmLib\Entity\RankingSystemInterface>.

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...
1170
  }
1171
//</editor-fold desc="Public Methods">
1172
1173
//<editor-fold desc="Private Methods">
1174
  /**
1175
   * Creates an empty RankingSystemChange
1176
   * @return MockObject|RankingSystemChangeInterface
1177
   */
1178
  private function createEmptyChange(): MockObject
1179
  {
1180
    $change = $this->getMockForAbstractClass(RankingSystemChange::class, [['additional']], '', true, true, true,
1181
      ['getPlayer', 'getPointsChange']);
1182
    return $change;
1183
  }
1184
1185
  /**
1186
   * Creates an empty RankingSystemListEntry
1187
   * @return MockObject|RankingSystemListEntryInterface
1188
   */
1189
  private function createEmptyEntry(): MockObject
1190
  {
1191
    $entry = $this->getMockForAbstractClass(RankingSystemListEntry::class, [['additional']], '', true, true, true,
1192
      ['getPlayer', 'getPoints']);
1193
    return $entry;
1194
  }
1195
1196
  /**
1197
   * Creates different entities used for create change
1198
   * @return array, a hierarchy entity, a ranking system and a player
0 ignored issues
show
Documentation introduced by
The doc-type array, could not be parsed: Expected "|" or "end of type", but got "," at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1199
   */
1200
  private function createEntities()
1201
  {
1202
    $entity = $this->createStubWithId(TournamentHierarchyEntity::class, 'h1');
1203
    $ranking = $this->createStubWithId(RankingSystem::class, 'r1');
1204
    $player = $this->createStubWithId(Player::class, 1, 'getId');
1205
    return [$entity, $ranking, $player];
1206
  }
1207
1208
  /**
1209
   * Prepares a ranking system service for creating a change
1210
   * @return array, the service entity and its corresponding entity manager
0 ignored issues
show
Documentation introduced by
The doc-type array, could not be parsed: Expected "|" or "end of type", but got "," at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1211
   */
1212
  private function prepareCreateChange()
1213
  {
1214
    $entityManager = $this->createStub(EntityManager::class, []);
1215
    /** @var $service RankingSystemService */
1216
    $service = $this->getMockForAbstractClass(RankingSystemService::class, [
1217
      $entityManager, $this->createMock(TimeServiceInterface::class),
1218
      $this->createMock(EntityComparerInterface::class),
1219
      $this->getObjectCreator()
1220
    ]);
1221
    return [$service, $entityManager];
1222
  }
1223
1224
  /**
1225
   * prepares a new ranking system service for update ranking from
1226
   * @param MockObject $ranking the ranking entity
1227
   * @param EntityManagerInterface|null $entityManager the entity manager or null if a mock should be used
1228
   * @return RankingSystemService
1229
   */
1230
  private function prepareUpdateRankingFrom(MockObject $ranking, ?EntityManagerInterface $entityManager = null,
1231
                                            $listsArray = null, $numListsToUpdate = 1, $mockedMethods = [],
1232
                                            $entities = [])
1233
  {
1234
    if ($entityManager === null) {
1235
      $entityManager = $this->getEntityManagerMockForQuery([]);
1236
    }
1237
    $service = $this->getMockForAbstractClass(RankingSystemService::class,
1238
      [$entityManager, $this->createMock(TimeServiceInterface::class),
1239
        $this->createMock(EntityComparerInterface::class),
1240
        $this->getObjectCreator()], '', true, true, true, $mockedMethods);
1241
1242
    if ($listsArray == null) {
1243
      //create mocks for current lists
1244
      $list = $this->createMock(RankingSystemList::class);
1245
      $list->method('isCurrent')->willReturn(true);
0 ignored issues
show
Bug introduced by
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.

Loading history...
1246
      $list->method('getLastEntryTime')->willReturn(new \DateTime("2017-06-01"));
0 ignored issues
show
Bug introduced by
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.

Loading history...
1247
      $list->method('getEntries')->willReturn(new ArrayCollection());
0 ignored issues
show
Bug introduced by
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.

Loading history...
1248
      $listsArray = [$list];
1249
    }
1250
1251
    $lists = $this->createMock(Collection::class);
1252
    $lists->expects(static::once())->method('toArray')->willReturn($listsArray);
1253
1254
    //finish mock for input
1255
    $ranking->method('getLists')->willReturn($lists);
0 ignored issues
show
Bug introduced by
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.

Loading history...
1256
1257
    //create query mock for getEntities
1258
    $query = $this->createMock(AbstractQuery::class);
1259
    $query->expects(static::exactly($numListsToUpdate))->method('getResult')->willReturn($entities);
1260
    //create query builder mock for getEntities
1261
    $queryBuilder = $this->createMock(QueryBuilder::class);
1262
    $queryBuilder->expects(static::exactly($numListsToUpdate))->method('getQuery')->willReturn($query);
1263
    $service->expects(static::exactly($numListsToUpdate))->method('getEntitiesQueryBuilder')
1264
      ->with($ranking)->willReturn($queryBuilder);
1265
    /** @var $service RankingSystemService */
1266
1267
    return $service;
1268
  }
1269
//</editor-fold desc="Private Methods">
1270
}