| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace OldSound\RabbitMqBundle\Tests\RabbitMq; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use OldSound\RabbitMqBundle\RabbitMq\Binding; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use PHPUnit\Framework\Assert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use PHPUnit\Framework\MockObject\MockObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  | class BindingTest extends TestCase | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |     protected function getBinding($amqpConnection, $amqpChannel) | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |         return new Binding($amqpConnection, $amqpChannel); | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      * @return MockObject | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     protected function prepareAMQPConnection() | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         return $this->getMockBuilder('\PhpAmqpLib\Connection\AMQPStreamConnection') | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |             ->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |             ->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     protected function prepareAMQPChannel($channelId = null) | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $channelMock = $this->getMockBuilder('\PhpAmqpLib\Channel\AMQPChannel') | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |             ->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |             ->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $channelMock->expects($this->any()) | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |             ->method('getChannelId') | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |             ->willReturn($channelId); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         return $channelMock; | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     public function testQueueBind() | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         $ch = $this->prepareAMQPChannel('channel_id'); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         $con = $this->prepareAMQPConnection(); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         $source = 'example_source'; | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         $destination = 'example_destination'; | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         $key = 'example_key'; | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         $ch->expects($this->once()) | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |             ->method('queue_bind') | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |             ->will($this->returnCallback(function ($d, $s, $k, $n, $a) use ($destination, $source, $key) { | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |                 Assert::assertSame($destination, $d); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |                 Assert::assertSame($source, $s); | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |                 Assert::assertSame($key, $k); | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |                 Assert::assertFalse($n); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |                 Assert::assertNull($a); | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |             })); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         $binding = $this->getBinding($con, $ch); | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |         $binding->setExchange($source); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         $binding->setDestination($destination); | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |         $binding->setRoutingKey($key); | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         $binding->setupFabric(); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function testExhangeBind() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $ch = $this->prepareAMQPChannel('channel_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $con = $this->prepareAMQPConnection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $source = 'example_source'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $destination = 'example_destination'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $key = 'example_key'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $ch->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             ->method('exchange_bind') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             ->will($this->returnCallback(function ($d, $s, $k, $n, $a) use ($destination, $source, $key) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                 Assert::assertSame($destination, $d); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                 Assert::assertSame($source, $s); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                 Assert::assertSame($key, $k); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                 Assert::assertFalse($n); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                 Assert::assertNull($a); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             })); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $binding = $this->getBinding($con, $ch); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $binding->setExchange($source); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $binding->setDestination($destination); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $binding->setRoutingKey($key); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $binding->setDestinationIsExchange(true); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 88 |  |  |         $binding->setupFabric(); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 90 |  |  | } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 91 |  |  |  |