1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Phive Queue package. |
5
|
|
|
* |
6
|
|
|
* (c) Eugene Leonovich <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Phive\Queue\Tests\Queue; |
13
|
|
|
|
14
|
|
|
use Phive\Queue\ExceptionalQueue; |
15
|
|
|
use Phive\Queue\QueueException; |
16
|
|
|
|
17
|
|
|
class ExceptionalQueueTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
use Util; |
20
|
|
|
|
21
|
|
|
protected $innerQueue; |
22
|
|
|
protected $queue; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
protected function setUp() |
28
|
|
|
{ |
29
|
|
|
$this->innerQueue = $this->getQueueMock(); |
30
|
|
|
$this->queue = new ExceptionalQueue($this->innerQueue); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testPush() |
34
|
|
|
{ |
35
|
|
|
$item = 'foo'; |
36
|
|
|
|
37
|
|
|
$this->innerQueue->expects($this->once())->method('push') |
38
|
|
|
->with($this->equalTo($item)); |
39
|
|
|
|
40
|
|
|
$this->queue->push($item); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testPop() |
44
|
|
|
{ |
45
|
|
|
$this->innerQueue->expects($this->once())->method('pop'); |
46
|
|
|
$this->queue->pop(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testCount() |
50
|
|
|
{ |
51
|
|
|
$this->innerQueue->expects($this->once())->method('count') |
52
|
|
|
->will($this->returnValue(42)); |
53
|
|
|
|
54
|
|
|
$this->assertSame(42, $this->queue->count()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testClear() |
58
|
|
|
{ |
59
|
|
|
$this->innerQueue->expects($this->once())->method('clear'); |
60
|
|
|
$this->queue->clear(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @dataProvider provideQueueInterfaceMethods |
65
|
|
|
* @expectedException \Phive\Queue\QueueException |
66
|
|
|
*/ |
67
|
|
|
public function testThrowOriginalQueueException($method) |
68
|
|
|
{ |
69
|
|
|
$this->innerQueue->expects($this->once())->method($method) |
70
|
|
|
->will($this->throwException(new QueueException($this->innerQueue))); |
71
|
|
|
|
72
|
|
|
$this->callQueueMethod($this->queue, $method); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @dataProvider provideQueueInterfaceMethods |
77
|
|
|
* @expectedException \Phive\Queue\QueueException |
78
|
|
|
*/ |
79
|
|
|
public function testThrowWrappedQueueException($method) |
80
|
|
|
{ |
81
|
|
|
$this->innerQueue->expects($this->once())->method($method) |
82
|
|
|
->will($this->throwException(new \Exception())); |
83
|
|
|
|
84
|
|
|
$this->callQueueMethod($this->queue, $method); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|