1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Gelf\Test\Transport; |
5
|
|
|
|
6
|
|
|
use Gelf\Message; |
7
|
|
|
use Gelf\Transport\RetryTransportWrapper; |
8
|
|
|
use Gelf\Transport\TransportInterface; |
9
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
use RuntimeException; |
12
|
|
|
|
13
|
|
|
class RetryTransportWrapperTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
private Message $message; |
16
|
|
|
private TransportInterface|MockObject $transport; |
17
|
|
|
|
18
|
|
|
public function setUp(): void |
19
|
|
|
{ |
20
|
|
|
$this->message = new Message(); |
21
|
|
|
$this->transport = $this->createMock(TransportInterface::class); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testGetTransport(): void |
25
|
|
|
{ |
26
|
|
|
$wrapper = new RetryTransportWrapper($this->transport, 1, null); |
27
|
|
|
self::assertEquals($this->transport, $wrapper->getTransport()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testWithoutMatcher(): void |
31
|
|
|
{ |
32
|
|
|
$this->expectException(RuntimeException::class); |
33
|
|
|
$this->expectExceptionMessage("bar"); |
34
|
|
|
|
35
|
|
|
$wrapper = new RetryTransportWrapper($this->transport, 1, null); |
36
|
|
|
|
37
|
|
|
$expectedException1 = new RuntimeException('foo'); |
38
|
|
|
$expectedException2 = new RuntimeException('bar'); |
39
|
|
|
|
40
|
|
|
$this->transport->expects($this->exactly(2)) |
|
|
|
|
41
|
|
|
->method('send') |
42
|
|
|
->with($this->message) |
43
|
|
|
->will($this->onConsecutiveCalls( |
44
|
|
|
$this->throwException($expectedException1), |
45
|
|
|
$this->throwException($expectedException2) |
46
|
|
|
)); |
47
|
|
|
|
48
|
|
|
$bytes = $wrapper->send($this->message); |
49
|
|
|
|
50
|
|
|
self::assertEquals('', $bytes); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testWithMatcher(): void |
54
|
|
|
{ |
55
|
|
|
$this->expectException(RuntimeException::class); |
56
|
|
|
$this->expectExceptionMessage("bar"); |
57
|
|
|
|
58
|
|
|
$wrapper = new RetryTransportWrapper($this->transport, 1); |
59
|
|
|
|
60
|
|
|
$expectedException1 = new RuntimeException('foo'); |
61
|
|
|
$expectedException2 = new RuntimeException('bar'); |
62
|
|
|
|
63
|
|
|
$this->transport->expects($this->exactly(2)) |
64
|
|
|
->method('send') |
65
|
|
|
->with($this->message) |
66
|
|
|
->will($this->onConsecutiveCalls( |
67
|
|
|
$this->throwException($expectedException1), |
68
|
|
|
$this->throwException($expectedException2) |
69
|
|
|
)); |
70
|
|
|
|
71
|
|
|
$bytes = $wrapper->send($this->message); |
72
|
|
|
|
73
|
|
|
self::assertEquals('', $bytes); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testWithFalseMatcher(): void |
77
|
|
|
{ |
78
|
|
|
$this->expectException(RuntimeException::class); |
79
|
|
|
$this->expectExceptionMessage("foo"); |
80
|
|
|
$wrapper = new RetryTransportWrapper($this->transport, 1, fn () => false); |
81
|
|
|
|
82
|
|
|
$expectedException1 = new RuntimeException('foo'); |
83
|
|
|
|
84
|
|
|
$this->transport->expects($this->once()) |
85
|
|
|
->method('send') |
86
|
|
|
->with($this->message) |
87
|
|
|
->willThrowException($expectedException1); |
88
|
|
|
|
89
|
|
|
$bytes = $wrapper->send($this->message); |
90
|
|
|
|
91
|
|
|
self::assertEquals('', $bytes); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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.