1
|
|
|
<?php |
2
|
|
|
namespace Tavii\SQSJobQueueBundle\Tests\Command; |
3
|
|
|
|
4
|
|
|
use Phake; |
5
|
|
|
use Symfony\Component\Console\Application; |
6
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
7
|
|
|
use Tavii\SQSJobQueue\Queue\QueueName; |
8
|
|
|
use Tavii\SQSJobQueue\Storage\EntityInterface; |
9
|
|
|
use Tavii\SQSJobQueue\Storage\EntityJobNameTrait; |
10
|
|
|
use Tavii\SQSJobQueueBundle\Command\WorkerStatusCommand; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class WorkerStatusCommandTest extends \PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @test |
17
|
|
|
*/ |
18
|
|
|
public function コマンドを実行することができる() |
19
|
|
|
{ |
20
|
|
|
$storage = Phake::mock('Tavii\SQSJobQueueBundle\Storage\DoctrineStorage'); |
21
|
|
|
$container = Phake::mock('Symfony\Component\DependencyInjection\Container'); |
22
|
|
|
|
23
|
|
|
$entity = new TestEntity('test','test.com', 12345); |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
Phake::when($storage)->all()->thenReturn(array( |
27
|
|
|
$entity |
28
|
|
|
)); |
29
|
|
|
Phake::when($container)->get('sqs_job_queue.storage.doctrine')->thenReturn($storage); |
30
|
|
|
|
31
|
|
|
$application = new Application(); |
32
|
|
|
$application->add(new WorkerStatusCommand()); |
33
|
|
|
|
34
|
|
|
$command = $application->get('sqs_job_queue:worker-status'); |
35
|
|
|
|
36
|
|
|
$command->setContainer($container); |
37
|
|
|
|
38
|
|
|
$tester = new CommandTester($command); |
39
|
|
|
$tester->execute(array( |
40
|
|
|
'command' => $command->getName() |
41
|
|
|
)); |
42
|
|
|
|
43
|
|
|
Phake::verify($container)->get('sqs_job_queue.storage.doctrine'); |
44
|
|
|
Phake::verify($storage)->all(); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
class TestEntity implements EntityInterface |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
use EntityJobNameTrait; |
52
|
|
|
|
53
|
|
|
private $queue; |
54
|
|
|
|
55
|
|
|
private $server; |
56
|
|
|
|
57
|
|
|
private $procId; |
58
|
|
|
|
59
|
|
|
private $prefix; |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function __construct($queue, $server, $procId) |
63
|
|
|
{ |
64
|
|
|
$this->queue = $queue; |
65
|
|
|
$this->server = $server; |
66
|
|
|
$this->procId = $procId; |
67
|
|
|
$this->prefix = "test"; |
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function getQueue() |
76
|
|
|
{ |
77
|
|
|
return $this->queue; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function getServer() |
84
|
|
|
{ |
85
|
|
|
return $this->server; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return int |
90
|
|
|
*/ |
91
|
|
|
public function getProcId() |
92
|
|
|
{ |
93
|
|
|
return $this->procId; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getPrefix() |
97
|
|
|
{ |
98
|
|
|
return $this->prefix; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
} |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.