|
1
|
|
|
<?php |
|
2
|
|
|
namespace Tarioch\EveapiFetcherBundle\Tests\Unit\Command; |
|
3
|
|
|
|
|
4
|
|
|
use Symfony\Component\Console\Application; |
|
5
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
6
|
|
|
use Tarioch\EveapiFetcherBundle\Command\ScheduleApiJobsCommand; |
|
7
|
|
|
use Mockery as m; |
|
8
|
|
|
|
|
9
|
|
|
class ScheduleApiJobsCommandTest extends \PHPUnit_Framework_TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
private $container; |
|
12
|
|
|
private $gearman; |
|
13
|
|
|
private $entityManager; |
|
14
|
|
|
private $apiCallRepository; |
|
15
|
|
|
private $apiKeyRepository; |
|
16
|
|
|
private $apiRepository; |
|
17
|
|
|
private $apiCall1; |
|
18
|
|
|
private $api1; |
|
19
|
|
|
private $newKey; |
|
20
|
|
|
private $keyInfoApi; |
|
21
|
|
|
|
|
22
|
|
|
private $command; |
|
23
|
|
|
|
|
24
|
|
|
public function testExecute() |
|
25
|
|
|
{ |
|
26
|
|
|
$worker = 'worker'; |
|
27
|
|
|
$apiCallId1 = 'apiCallId1'; |
|
28
|
|
|
$section1 = 'section1'; |
|
29
|
|
|
$name1 = 'name1'; |
|
30
|
|
|
|
|
31
|
|
|
$this->container->shouldReceive('get') |
|
32
|
|
|
->with('gearman') |
|
33
|
|
|
->andReturn($this->gearman); |
|
34
|
|
|
$this->container->shouldReceive('get') |
|
35
|
|
|
->with('doctrine.orm.eveapi_entity_manager') |
|
36
|
|
|
->andReturn($this->entityManager); |
|
37
|
|
|
|
|
38
|
|
|
$this->entityManager->shouldReceive('getRepository') |
|
39
|
|
|
->with('TariochEveapiFetcherBundle:ApiKey') |
|
40
|
|
|
->andReturn($this->apiKeyRepository); |
|
41
|
|
|
$this->apiKeyRepository->shouldReceive('loadKeysWithoutApiCall')->andReturn(array($this->newKey)); |
|
42
|
|
|
$this->entityManager->shouldReceive('getRepository') |
|
43
|
|
|
->with('TariochEveapiFetcherBundle:Api') |
|
44
|
|
|
->andReturn($this->apiRepository); |
|
45
|
|
|
$this->apiRepository->shouldReceive('loadApiKeyInfoApi')->andReturn($this->keyInfoApi); |
|
46
|
|
|
$this->newKey->shouldReceive('getKeyId')->andReturn('newKeyId'); |
|
47
|
|
|
$this->entityManager->shouldReceive('persist')->once(); |
|
48
|
|
|
$this->entityManager->shouldReceive('flush')->once(); |
|
49
|
|
|
|
|
50
|
|
|
$this->entityManager->shouldReceive('getRepository') |
|
51
|
|
|
->with('TariochEveapiFetcherBundle:ApiCall') |
|
52
|
|
|
->andReturn($this->apiCallRepository); |
|
53
|
|
|
$this->apiCallRepository->shouldReceive('loadReadyCalls') |
|
54
|
|
|
->andReturn(array($this->apiCall1)); |
|
55
|
|
|
$this->apiCall1->shouldReceive('getApi')->andReturn($this->api1); |
|
56
|
|
|
$this->api1->shouldReceive('getWorker')->andReturn($worker); |
|
57
|
|
|
$this->apiCall1->shouldReceive('getApiCallId')->andReturn($apiCallId1); |
|
58
|
|
|
$this->gearman->shouldReceive('doBackgroundJob')->with($worker . '~apiUpdate', $apiCallId1, $apiCallId1); |
|
59
|
|
|
$this->api1->shouldReceive('getSection')->andReturn($section1); |
|
60
|
|
|
$this->api1->shouldReceive('getName')->andReturn($name1); |
|
61
|
|
|
|
|
62
|
|
|
$commandTester = new CommandTester($this->command); |
|
63
|
|
|
$commandTester->execute(array('command' => $this->command->getName())); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function setUp() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->container = m::mock('Symfony\Component\DependencyInjection\Container'); |
|
69
|
|
|
$this->gearman = m::mock('Mmoreram\GearmanBundle\Service\GearmanClient'); |
|
70
|
|
|
$this->entityManager = m::mock('Doctrine\ORM\EntityManager'); |
|
71
|
|
|
$this->apiCallRepository = m::mock('Tarioch\EveapiFetcherBundle\Entity\ApiCallRepository'); |
|
72
|
|
|
$this->apiKeyRepository = m::mock('Tarioch\EveapiFetcherBundle\Entity\ApiKeyRepository'); |
|
73
|
|
|
$this->apiRepository = m::mock('Tarioch\EveapiFetcherBundle\Entity\ApiRepository'); |
|
74
|
|
|
$this->apiCall1 = m::mock('Tarioch\EveapiFetcherBundle\Entity\ApiCall'); |
|
75
|
|
|
$this->api1 = m::mock('Tarioch\EveapiFetcherBundle\Entity\Api'); |
|
76
|
|
|
$this->newKey = m::mock('Tarioch\EveapiFetcherBundle\Entity\ApiKey'); |
|
77
|
|
|
$this->keyInfoApi = m::mock('Tarioch\EveapiFetcherBundle\Entity\Api'); |
|
78
|
|
|
|
|
79
|
|
|
$application = new Application(); |
|
80
|
|
|
$application->add(new ScheduleApiJobsCommand()); |
|
81
|
|
|
|
|
82
|
|
|
$this->command = $application->find('eve:api:schedule'); |
|
83
|
|
|
$this->command->setContainer($this->container); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|