| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace Gelf\Test\Transport; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Gelf\Message; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Gelf\Transport\HttpTransport; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Gelf\Transport\KeepAliveRetryTransportWrapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use PHPUnit\Framework\MockObject\MockObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use RuntimeException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class KeepAliveRetryTransportWrapperTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     private const FAILURE_MESSAGE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         = "Graylog-Server didn't answer properly, expected 'HTTP/1.x 202 Accepted', response is ''"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     private Message $message; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     private HttpTransport|MockObject $transport; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     private KeepAliveRetryTransportWrapper $wrapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public function setUp(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $this->message = new Message(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $this->transport = $this->createMock(HttpTransport::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->wrapper   = new KeepAliveRetryTransportWrapper($this->transport); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public function testSendSuccess(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $this->transport->expects($this->once()) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             ->method('send') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             ->with($this->message) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             ->will($this->returnValue(42)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $bytes = $this->wrapper->send($this->message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         self::assertEquals(42, $bytes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public function testSendSuccessAfterRetry(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $expectedException = new RuntimeException(self::FAILURE_MESSAGE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->transport->expects($this->exactly(2)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             ->method('send') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             ->with($this->message) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             ->will($this->onConsecutiveCalls( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                 $this->throwException($expectedException), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                 42 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $bytes = $this->wrapper->send($this->message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         self::assertEquals(42, $bytes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     public function testSendFailTwiceWithoutResponse(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         self::expectException(RuntimeException::class); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         self::expectExceptionMessage("response is ''"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $expectedException1 = new RuntimeException(self::FAILURE_MESSAGE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $expectedException2 = new RuntimeException(self::FAILURE_MESSAGE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $this->transport->expects($this->exactly(2)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             ->method('send') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             ->with($this->message) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             ->will($this->onConsecutiveCalls( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 $this->throwException($expectedException1), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 $this->throwException($expectedException2) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->wrapper->send($this->message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |     public function testSendFailWithUnmanagedException(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |         $this->expectException(RuntimeException::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |         $this->expectExceptionMessage("foo"); | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |         $expectedException = new RuntimeException('foo'); | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |         $this->transport->expects($this->once()) | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |             ->method('send') | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |             ->with($this->message) | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |             ->willThrowException($expectedException); | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |         $this->wrapper->send($this->message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 91 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |  | 
            
                        
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.