| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Aimeos\MW\MQueue\Queue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | class AMQPTest extends \PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 	private $mock; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 	private $object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 	protected function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 		if( class_exists( '\PhpAmqpLib\Channel\AMQPChannel' ) === false ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 			$this->markTestSkipped( 'Please install the "php-amqplib" library via composer first' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 		$this->mock = $this->getMockBuilder( '\PhpAmqpLib\Channel\AMQPChannel' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 			->setMethods( array( 'queue_declare', 'basic_qos', 'basic_publish', 'basic_get', 'basic_ack' ) ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		$this->object = new \Aimeos\MW\MQueue\Queue\AMQP( $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( 'queue_declare' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 			->will( $this->throwException( new \Exception() ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 		$this->setExpectedException( '\Aimeos\MW\MQueue\Exception' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 		new \Aimeos\MW\MQueue\Queue\AMQP( $this->mock, 'test' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	public function testAdd() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		$this->mock->expects( $this->once() )->method( 'basic_publish' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		$this->object->add( 'test' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 51 |  | View Code Duplication | 	public function testAddException() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		$this->mock->expects( $this->once() )->method( 'basic_publish' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			->will( $this->throwException( new \Exception() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		$this->setExpectedException( '\Aimeos\MW\MQueue\Exception' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		$this->object->add( 'test' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	public function testDel() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		$msg = new \PhpAmqpLib\Message\AMQPMessage( 'test' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$msg->delivery_info = array( 'channel' => $this->mock, 'delivery_tag' => 'test' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		$message = new \Aimeos\MW\MQueue\Message\AMQP( $msg ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		$this->mock->expects( $this->once() )->method( 'basic_ack' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		$this->object->del( $message ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	public function testDelException() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		$msg = new \PhpAmqpLib\Message\AMQPMessage( 'test' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		$msg->delivery_info = array( 'channel' => $this->mock, 'delivery_tag' => 'test' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		$message = new \Aimeos\MW\MQueue\Message\AMQP( $msg ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		$this->mock->expects( $this->once() )->method( 'basic_ack' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 			->will( $this->throwException( new \Exception() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		$this->setExpectedException( '\Aimeos\MW\MQueue\Exception' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		$this->object->del( $message ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 89 |  | View Code Duplication | 	public function testGet() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		$msg = new \PhpAmqpLib\Message\AMQPMessage( 'test' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 		$this->mock->expects( $this->once() )->method( 'basic_get' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 			->will( $this->returnValue( $msg ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		$this->assertInstanceOf( '\Aimeos\MW\MQueue\Message\Iface', $this->object->get() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 	public function testGetNone() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		$this->mock->expects( $this->once() )->method( 'basic_get' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 			->will( $this->returnValue( null ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		$this->assertNull( $this->object->get() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 109 |  | View Code Duplication | 	public function testGetException() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 		$this->mock->expects( $this->once() )->method( 'basic_get' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 			->will( $this->throwException( new \Exception() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 		$this->setExpectedException( '\Aimeos\MW\MQueue\Exception' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 		$this->object->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 117 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 118 |  |  |  | 
            
                        
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.