DummyJob::getPrefix()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Tavii\SQSJobQueue\Queue;
3
4
use Phake;
5
use Aws\Sqs\SqsClient;
6
use Tavii\SQSJobQueue\Job\Job;
7
use Tavii\SQSJobQueue\Queue\QueueName;
8
9
class QueueTest extends \PHPUnit_Framework_TestCase
10
{
11
    private $client;
12
13
    public function setUp()
14
    {
15
        $this->client = Phake::mock('Aws\Sqs\SqsClient');
16
    }
17
18
    /**
19
     * @test
20
     */
21
    public function キューに保存に保存することができる()
22
    {
23
        $name = new QueueName('test');
24
        $job = Phake::mock('Tavii\SQSJobQueue\Job\Job');
25
        Phake::when($job)->getJobName()
26
            ->thenReturn($name);
27
        Phake::when($job)->getArgs()
28
            ->thenReturn(array('test','teset2'));
29
30
        Phake::when($this->client)->getQueueUrl(array('QueueName' => $name))
31
            ->thenReturn(array(
32
                'QueueUrl' => 'test'
33
            ));
34
35
36
        $queue = new Queue($this->client);
37
        $queue->send($job);
38
39
        Phake::verify($this->client)->getQueueUrl(array('QueueName' => $name->getQueueName()));
40
        Phake::verify($this->client)->sendMessage($this->isType('array'));
41
        Phake::verify($job)->getJobName();
42
        Phake::verify($job)->getArgs();
43
44
    }
45
46
    /**
47
     * @test
48
     */
49
    public function キューからジョブを取り出すことができる()
50
    {
51
        $name = "test_job";
52
        $args = array(
53
            'Body' => json_encode(array(
54
                'className' => 'Tavii\SQSJobQueue\Queue\DummyJob',
55
                'args' => array('a' => '1' , 'b' => 2)
56
            ))
57
        );
58
59
        $collection = Phake::mock('Guzzle\Common\Collection');
60
        Phake::when($collection)->getPath('Messages/*')
61
            ->thenReturn($args);
62
63
        Phake::when($this->client)->getQueueUrl(array('QueueName' => $name))
64
            ->thenReturn(array(
65
                'QueueUrl' => 'test'
66
            ));
67
68
        Phake::when($this->client)->receiveMessage(array(
69
            'QueueUrl' => 'test'
70
            ))->thenReturn($collection);
71
72
        $queue = new Queue($this->client);
73
        $job = $queue->receive(new QueueName($name));
74
75
        $this->assertInstanceOf('Tavii\SQSJobQueue\Message\MessageInterface', $job);
76
        Phake::verify($collection)->getPath('Messages/*');
77
        Phake::verify($this->client)->getQueueUrl(array('QueueName' => $name));
78
        Phake::verify($this->client)->receiveMessage(array('QueueUrl' => 'test'));
79
    }
80
81
    /**
82
     * @test
83
     */
84
    public function キューを削除する()
85
    {
86
        $message = Phake::mock('Tavii\SQSJobQueue\Message\Message');
87
        Phake::when($message)->getMessage()
88
            ->thenReturn(array(
89
                'QueueUrl' => '/hoge/fuga',
90
                'ReceiptHandle' => 'Receipt'
91
            ));
92
93
        Phake::when($this->client)->deleteMessage(array(
94
            'QueueUrl' => '/hoge/fuga',
95
            'ReceiptHandle' => 'Receipt',
96
        ));
97
98
        $queue = new Queue($this->client);
99
        $queue->delete($message);
100
101
    }
102
}
103
104
class DummyJob extends Job
105
{
106
    /**
107
     * @param array $args
108
     * @return booelan
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
109
     */
110
    protected function run()
111
    {
112
        return true;
113
    }
114
115
    public function getPrefix()
116
    {
117
        return 'queue_test';
118
    }
119
120
121
    /**
122
     * @return string
123
     */
124
    public function getName()
125
    {
126
        return 'test_job';
127
    }
128
129
}