This repository was archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApiLogQueryTest.php
More file actions
105 lines (88 loc) · 3.5 KB
/
ApiLogQueryTest.php
File metadata and controls
105 lines (88 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Tests\Chaplean\Bundle\ApiClientBundle\Query;
use Chaplean\Bundle\ApiClientBundle\Entity\ApiLog;;
use Chaplean\Bundle\ApiClientBundle\Query\ApiLogQuery;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\QueryBuilder;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Symfony\Bridge\Doctrine\RegistryInterface;
/**
* Class ApiLogQueryTest.
*
* @namespace Tests\Chaplean\Bundle\ApiClientBundle\Query
* @author Hugo - Chaplean <hugo@chaplean.coop>
* @copyright 2014 - 2018 Chaplean (http://www.chaplean.coop)
*/
class ApiLogQueryTest extends MockeryTestCase
{
/**
* @var RegistryInterface|\Mockery\MockInterface
*/
private $doctrine;
/**
* @var EntityManager|\Mockery\MockInterface
*/
private $manager;
/**
* @var ApiLogQuery
*/
private $apiLogQuery;
/**
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->manager = \Mockery::mock(EntityManager::class);
$this->doctrine = \Mockery::mock(RegistryInterface::class);
$this->doctrine->shouldReceive('getManager')->once()->andReturn($this->manager);
$this->apiLogQuery = new ApiLogQuery($this->doctrine);
}
/**
* @covers \Chaplean\Bundle\ApiClientBundle\Query\ApiLogQuery::__construct()
*
* @return void
*/
public function testConstruct()
{
$this->assertInstanceOf(ApiLogQuery::class, $this->apiLogQuery);
}
/**
* @covers \Chaplean\Bundle\ApiClientBundle\Query\ApiLogQuery::createFindIdsMostRecentThan()
*
* @return void
*/
public function testCreateFindIdsMostRecentThan()
{
$date = \Mockery::mock(\DateTime::class);
$query = \Mockery::mock(AbstractQuery::class);
$queryBuilder = \Mockery::mock(QueryBuilder::class);
$this->manager->shouldReceive('createQueryBuilder')->once()->andReturn($queryBuilder);
$queryBuilder->shouldReceive('select')->once()->with('log.id')->andReturnSelf();
$queryBuilder->shouldReceive('from')->once()->withArgs([ApiLog::class, 'log'])->andReturnSelf();
$queryBuilder->shouldReceive('where')->once()->with('log.dateAdd < :dateLimit')->andReturnSelf();
$date->shouldReceive('format')->once()->with('Y-m-d')->andReturn('2000-01-01');
$queryBuilder->shouldReceive('setParameter')->once()->withArgs(['dateLimit', '2000-01-01'])->andReturnSelf();
$queryBuilder->shouldReceive('getQuery')->once()->andReturn($query);
$queryResult = $this->apiLogQuery->createFindIdsMostRecentThan($date);
$this->assertEquals($queryResult, $query);
}
/**
* @covers \Chaplean\Bundle\ApiClientBundle\Query\ApiLogQuery::createDeleteById()
*
* @return void
*/
public function testCreateDeleteById()
{
$query = \Mockery::mock(AbstractQuery::class);
$queryBuilder = \Mockery::mock(QueryBuilder::class);
$this->manager->shouldReceive('createQueryBuilder')->once()->andReturn($queryBuilder);
$queryBuilder->shouldReceive('delete')->once()->withArgs([ApiLog::class, 'log'])->andReturnSelf();
$queryBuilder->shouldReceive('where')->once()->with('log.id = :id')->andReturnSelf();
$queryBuilder->shouldReceive('setParameter')->once()->withArgs(['id', 125])->andReturnSelf();
$queryBuilder->shouldReceive('getQuery')->once()->andReturn($query);
$queryResult = $this->apiLogQuery->createDeleteById(125);
$this->assertEquals($queryResult, $query);
}
}