StompTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 120
Duplicated Lines 18.33 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 11
c 1
b 0
f 1
lcom 1
cbo 2
dl 22
loc 120
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 13 2
A tearDown() 0 4 1
A testConstructorException() 0 11 1
A testAdd() 0 6 1
A testAddException() 11 11 1
A testDel() 0 9 1
A testDelException() 0 11 1
A testGet() 0 12 1
A testGetNone() 0 7 1
A testGetException() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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