1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aimeos\MW\MQueue\Queue; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class StompTest extends \PHPUnit_Framework_TestCase |
7
|
|
|
{ |
8
|
|
|
private $mock; |
9
|
|
|
private $object; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
protected function setUp() |
13
|
|
|
{ |
14
|
|
|
if( class_exists( '\Stomp' ) === false ) { |
15
|
|
|
$this->markTestSkipped( 'Please install the "Stomp" PHP extension first' ); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
$this->mock = $this->getMockBuilder( '\Stomp' ) |
19
|
|
|
->setMethods( array( 'subscribe', 'unsubscribe', 'send', 'ack', 'hasFrame', 'readFrame', 'error', '__destruct' ) ) |
20
|
|
|
->disableOriginalConstructor() |
21
|
|
|
->getMock(); |
22
|
|
|
|
23
|
|
|
$this->object = new \Aimeos\MW\MQueue\Queue\Stomp( $this->mock, 'test' ); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
protected function tearDown() |
28
|
|
|
{ |
29
|
|
|
unset( $this->object ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
public function testConstructorException() |
34
|
|
|
{ |
35
|
|
|
$this->mock->expects( $this->once() )->method( 'subscribe' ) |
36
|
|
|
->will( $this->returnValue( false ) ); |
37
|
|
|
|
38
|
|
|
$this->mock->expects( $this->once() )->method( 'error' ) |
39
|
|
|
->will( $this->returnValue( 'exception' ) ); |
40
|
|
|
|
41
|
|
|
$this->setExpectedException( '\Aimeos\MW\MQueue\Exception' ); |
42
|
|
|
new \Aimeos\MW\MQueue\Queue\Stomp( $this->mock, 'test' ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testAdd() |
47
|
|
|
{ |
48
|
|
|
$this->mock->expects( $this->once() )->method( 'send' ); |
49
|
|
|
|
50
|
|
|
$this->object->add( 'test' ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
View Code Duplication |
public function testAddException() |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$this->mock->expects( $this->once() )->method( 'send' ) |
57
|
|
|
->will( $this->returnValue( false ) ); |
58
|
|
|
|
59
|
|
|
$this->mock->expects( $this->once() )->method( 'error' ) |
60
|
|
|
->will( $this->returnValue( 'exception' ) ); |
61
|
|
|
|
62
|
|
|
$this->setExpectedException( '\Aimeos\MW\MQueue\Exception' ); |
63
|
|
|
$this->object->add( 'test' ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
public function testDel() |
68
|
|
|
{ |
69
|
|
|
$msg = new \StompFrame( 'COMMAND', array(), 'test' ); |
70
|
|
|
$message = new \Aimeos\MW\MQueue\Message\Stomp( $msg ); |
71
|
|
|
|
72
|
|
|
$this->mock->expects( $this->once() )->method( 'ack' ); |
73
|
|
|
|
74
|
|
|
$this->object->del( $message ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testDelException() |
79
|
|
|
{ |
80
|
|
|
$msg = new \StompFrame( 'COMMAND', array(), 'test' ); |
81
|
|
|
$message = new \Aimeos\MW\MQueue\Message\Stomp( $msg ); |
82
|
|
|
|
83
|
|
|
$this->mock->expects( $this->once() )->method( 'ack' ) |
84
|
|
|
->will( $this->returnValue( false ) ); |
85
|
|
|
|
86
|
|
|
$this->setExpectedException( '\Aimeos\MW\MQueue\Exception' ); |
87
|
|
|
$this->object->del( $message ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
public function testGet() |
92
|
|
|
{ |
93
|
|
|
$msg = new \StompFrame( 'test' ); |
94
|
|
|
|
95
|
|
|
$this->mock->expects( $this->once() )->method( 'hasFrame' ) |
96
|
|
|
->will( $this->returnValue( true ) ); |
97
|
|
|
|
98
|
|
|
$this->mock->expects( $this->once() )->method( 'readFrame' ) |
99
|
|
|
->will( $this->returnValue( $msg ) ); |
100
|
|
|
|
101
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\MQueue\Message\Iface', $this->object->get() ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
public function testGetNone() |
106
|
|
|
{ |
107
|
|
|
$this->mock->expects( $this->once() )->method( 'hasFrame' ) |
108
|
|
|
->will( $this->returnValue( false ) ); |
109
|
|
|
|
110
|
|
|
$this->assertNull( $this->object->get() ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
View Code Duplication |
public function testGetException() |
|
|
|
|
115
|
|
|
{ |
116
|
|
|
$this->mock->expects( $this->once() )->method( 'hasFrame' ) |
117
|
|
|
->will( $this->returnValue( true ) ); |
118
|
|
|
|
119
|
|
|
$this->mock->expects( $this->once() )->method( 'readFrame' ) |
120
|
|
|
->will( $this->throwException( new \StompException() ) ); |
121
|
|
|
|
122
|
|
|
$this->setExpectedException( '\Aimeos\MW\MQueue\Exception' ); |
123
|
|
|
$this->object->get(); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
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.