1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Created by PhpStorm. |
5
|
|
|
* User: benedikt |
6
|
|
|
* Date: 1/3/18 |
7
|
|
|
* Time: 3:53 PM |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Tfboe\FmLib\Tests\Unit\Service\RankingSystem; |
11
|
|
|
|
12
|
|
|
use Doctrine\ORM\EntityManager; |
13
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
14
|
|
|
use Doctrine\ORM\QueryBuilder; |
15
|
|
|
use Tfboe\FmLib\Helpers\Level; |
16
|
|
|
use Tfboe\FmLib\Service\ObjectCreatorServiceInterface; |
17
|
|
|
use Tfboe\FmLib\Service\RankingSystem\EntityComparerInterface; |
18
|
|
|
use Tfboe\FmLib\Service\RankingSystem\GameRankingSystemService; |
19
|
|
|
use Tfboe\FmLib\Service\RankingSystem\TimeServiceInterface; |
20
|
|
|
use Tfboe\FmLib\Tests\Entity\RankingSystem; |
21
|
|
|
use Tfboe\FmLib\Tests\Helpers\UnitTestCase; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class GameRankingSystemTest |
25
|
|
|
* @packageTfboe\FmLib\Tests\Unit\Service\RankingSystemService |
26
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
27
|
|
|
*/ |
28
|
|
|
class GameRankingSystemTest extends UnitTestCase |
29
|
|
|
{ |
30
|
|
|
//<editor-fold desc="Public Methods"> |
31
|
|
|
/** |
32
|
|
|
* @covers \Tfboe\FmLib\Service\RankingSystem\GameRankingSystemService::getEntitiesQueryBuilder |
33
|
|
|
* @uses \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct |
34
|
|
|
* @uses \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::getEntityManager |
35
|
|
|
*/ |
36
|
|
|
public function testGetEntitiesQueryBuilder() |
37
|
|
|
{ |
38
|
|
|
$entityManager = $this->getMockForAbstractClass(EntityManager::class, [], '', false); |
39
|
|
|
$system = $this->getMockForAbstractClass(GameRankingSystemService::class, [$entityManager, |
40
|
|
|
$this->createMock(TimeServiceInterface::class), |
41
|
|
|
$this->createMock(EntityComparerInterface::class), $this->createMock(ObjectCreatorServiceInterface::class)]); |
42
|
|
|
$rankingSystem = $this->createMock(RankingSystem::class); |
43
|
|
|
$rankingSystem->method('getId')->willReturn('ranking-system-id'); |
|
|
|
|
44
|
|
|
/** @var QueryBuilder $builder */ |
45
|
|
|
$builder = self::callProtectedMethod($system, "getEntitiesQueryBuilder", |
46
|
|
|
[$rankingSystem, new \DateTime("2000-01-01"), new \DateTime("2001-01-01")]); |
47
|
|
|
self::assertEquals( |
48
|
|
|
'SELECT g FROM Tfboe\FmLib\Entity\GameInterface g LEFT JOIN g.rankingSystems grs WITH grs = :ranking ' . |
49
|
|
|
'INNER JOIN g.match m LEFT JOIN m.rankingSystems mrs WITH mrs = :ranking INNER JOIN m.phase p LEFT JOIN ' . |
50
|
|
|
'p.rankingSystems prs WITH prs = :ranking INNER JOIN p.competition c LEFT JOIN c.rankingSystems crs WITH ' . |
51
|
|
|
'crs = :ranking INNER JOIN c.tournament t LEFT JOIN t.rankingSystems trs WITH trs = :ranking WHERE ' . |
52
|
|
|
'COALESCE(g.endTime, g.startTime, m.endTime, m.startTime, p.endTime, p.startTime, c.endTime, c.startTime, ' . |
53
|
|
|
't.endTime, t.startTime, t.updatedAt) > :from AND COALESCE(g.endTime, g.startTime, m.endTime, m.startTime, ' . |
54
|
|
|
'p.endTime, p.startTime, c.endTime, c.startTime, t.endTime, t.startTime, t.updatedAt) <= :to AND (grs.id IS ' . |
55
|
|
|
'NOT NULL OR mrs.id IS NOT NULL OR prs.id IS NOT NULL OR crs.id IS NOT NULL OR trs.id IS NOT NULL)', |
56
|
|
|
$builder->getDQL()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @covers \Tfboe\FmLib\Service\RankingSystem\GameRankingSystemService::getLevel |
61
|
|
|
* @uses \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct |
62
|
|
|
*/ |
63
|
|
|
public function testLevel() |
64
|
|
|
{ |
65
|
|
|
$system = $this->getMockForAbstractClass(GameRankingSystemService::class, |
66
|
|
|
[$this->createMock(EntityManagerInterface::class), |
67
|
|
|
$this->createMock(TimeServiceInterface::class), |
68
|
|
|
$this->createMock(EntityComparerInterface::class), $this->createMock(ObjectCreatorServiceInterface::class)]); |
69
|
|
|
self::assertEquals(Level::GAME, self::callProtectedMethod($system, "getLevel")); |
70
|
|
|
} |
71
|
|
|
//</editor-fold desc="Public Methods"> |
72
|
|
|
|
73
|
|
|
//<editor-fold desc="Private Methods"> |
74
|
|
|
//</editor-fold desc="Private Methods"> |
75
|
|
|
} |
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.