|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Aimeos\MW\MQueue\Queue; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
class BeanstalkTest extends \PHPUnit_Framework_TestCase |
|
7
|
|
|
{ |
|
8
|
|
|
private $mock; |
|
9
|
|
|
private $object; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
protected function setUp() |
|
13
|
|
|
{ |
|
14
|
|
|
if( class_exists( '\Pheanstalk\Pheanstalk' ) === false ) { |
|
15
|
|
|
$this->markTestSkipped( 'Please install the "pheanstalk" library via composer first' ); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
$this->mock = $this->getMockBuilder( '\Pheanstalk\Pheanstalk' ) |
|
19
|
|
|
->setMethods( array( 'useTube', 'watch', 'put', 'delete', 'reserve' ) ) |
|
20
|
|
|
->disableOriginalConstructor() |
|
21
|
|
|
->getMock(); |
|
22
|
|
|
|
|
23
|
|
|
$this->mock->expects( $this->any() )->method( 'useTube' ) |
|
24
|
|
|
->will( $this->returnValue( $this->mock ) ); |
|
25
|
|
|
|
|
26
|
|
|
$this->object = new \Aimeos\MW\MQueue\Queue\Beanstalk( $this->mock, 'test' ); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
protected function tearDown() |
|
31
|
|
|
{ |
|
32
|
|
|
unset( $this->object ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
public function testConstructorException() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->mock->expects( $this->once() )->method( 'watch' ) |
|
39
|
|
|
->will( $this->throwException( new \Pheanstalk\Exception() ) ); |
|
40
|
|
|
|
|
41
|
|
|
$this->setExpectedException( '\Aimeos\MW\MQueue\Exception' ); |
|
42
|
|
|
new \Aimeos\MW\MQueue\Queue\Beanstalk( $this->mock, 'test' ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
public function testAdd() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->mock->expects( $this->once() )->method( 'put' ); |
|
49
|
|
|
|
|
50
|
|
|
$this->object->add( 'test' ); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
public function testAddException() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->mock->expects( $this->once() )->method( 'put' ) |
|
57
|
|
|
->will( $this->throwException( new \Pheanstalk\Exception() ) ); |
|
58
|
|
|
|
|
59
|
|
|
$this->setExpectedException( '\Aimeos\MW\MQueue\Exception' ); |
|
60
|
|
|
$this->object->add( 'test' ); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
public function testDel() |
|
65
|
|
|
{ |
|
66
|
|
|
$msg = new \Pheanstalk\Job( 1, 'test' ); |
|
67
|
|
|
$message = new \Aimeos\MW\MQueue\Message\Beanstalk( $msg ); |
|
68
|
|
|
|
|
69
|
|
|
$this->mock->expects( $this->once() )->method( 'delete' ); |
|
70
|
|
|
|
|
71
|
|
|
$this->object->del( $message ); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
public function testDelException() |
|
76
|
|
|
{ |
|
77
|
|
|
$msg = new \Pheanstalk\Job( 1, 'test' ); |
|
78
|
|
|
$message = new \Aimeos\MW\MQueue\Message\Beanstalk( $msg ); |
|
79
|
|
|
|
|
80
|
|
|
$this->mock->expects( $this->once() )->method( 'delete' ) |
|
81
|
|
|
->will( $this->throwException( new \Pheanstalk\Exception() ) ); |
|
82
|
|
|
|
|
83
|
|
|
$this->setExpectedException( '\Aimeos\MW\MQueue\Exception' ); |
|
84
|
|
|
$this->object->del( $message ); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
View Code Duplication |
public function testGet() |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
|
|
$msg = new \Pheanstalk\Job( 1, 'test' ); |
|
91
|
|
|
|
|
92
|
|
|
$this->mock->expects( $this->once() )->method( 'reserve' ) |
|
93
|
|
|
->will( $this->returnValue( $msg ) ); |
|
94
|
|
|
|
|
95
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\MQueue\Message\Iface', $this->object->get() ); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
public function testGetNone() |
|
100
|
|
|
{ |
|
101
|
|
|
$this->mock->expects( $this->once() )->method( 'reserve' ) |
|
102
|
|
|
->will( $this->returnValue( false ) ); |
|
103
|
|
|
|
|
104
|
|
|
$this->assertNull( $this->object->get() ); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.