|
8 | 8 | use Blackfire\Exception\LogicException; |
9 | 9 | use Blackfire\Probe; |
10 | 10 | use Blackfire\Profile\Configuration; |
11 | | -use Chubbyphp\Mock\Argument\ArgumentInstanceOf; |
12 | | -use Chubbyphp\Mock\Call; |
13 | | -use Chubbyphp\Mock\MockByCallsTrait; |
| 11 | +use Chubbyphp\Mock\MockMethod\WithCallback; |
| 12 | +use Chubbyphp\Mock\MockMethod\WithException; |
| 13 | +use Chubbyphp\Mock\MockMethod\WithoutReturn; |
| 14 | +use Chubbyphp\Mock\MockMethod\WithReturn; |
| 15 | +use Chubbyphp\Mock\MockObjectBuilder; |
14 | 16 | use Chubbyphp\WorkermanRequestHandler\Adapter\BlackfireOnMessageAdapter; |
15 | 17 | use Chubbyphp\WorkermanRequestHandler\OnMessageInterface; |
16 | | -use PHPUnit\Framework\MockObject\MockObject; |
| 18 | +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; |
17 | 19 | use PHPUnit\Framework\TestCase; |
18 | 20 | use Psr\Log\LoggerInterface; |
19 | 21 | use Workerman\Connection\TcpConnection as WorkermanTcpConnection; |
|
26 | 28 | */ |
27 | 29 | final class BlackfireOnMessageAdapterTest extends TestCase |
28 | 30 | { |
29 | | - use MockByCallsTrait; |
30 | | - |
| 31 | + #[DoesNotPerformAssertions] |
31 | 32 | public function testInvokeWithoutHeaderWithoutConfigAndWithoutLogger(): void |
32 | 33 | { |
33 | | - /** @var MockObject|WorkermanTcpConnection $workermanTcpConnection */ |
34 | | - $workermanTcpConnection = $this->getMockByCalls(WorkermanTcpConnection::class); |
| 34 | + $builder = new MockObjectBuilder(); |
| 35 | + |
| 36 | + /** @var WorkermanTcpConnection $workermanTcpConnection */ |
| 37 | + $workermanTcpConnection = $builder->create(WorkermanTcpConnection::class, [ |
| 38 | + new WithoutReturn('__destruct', []), |
| 39 | + ]); |
35 | 40 |
|
36 | | - /** @var MockObject|WorkermanRequest $workermanRequest */ |
37 | | - $workermanRequest = $this->getMockByCalls(WorkermanRequest::class, [ |
38 | | - Call::create('header')->with('x-blackfire-query', null)->willReturn(null), |
| 41 | + /** @var WorkermanRequest $workermanRequest */ |
| 42 | + $workermanRequest = $builder->create(WorkermanRequest::class, [ |
| 43 | + new WithReturn('header', ['x-blackfire-query', null], null), |
| 44 | + new WithoutReturn('__destruct', []), |
39 | 45 | ]); |
40 | 46 |
|
41 | | - /** @var MockObject|OnMessageInterface $onMessage */ |
42 | | - $onMessage = $this->getMockByCalls(OnMessageInterface::class, [ |
43 | | - Call::create('__invoke')->with($workermanTcpConnection, $workermanRequest), |
| 47 | + /** @var OnMessageInterface $onMessage */ |
| 48 | + $onMessage = $builder->create(OnMessageInterface::class, [ |
| 49 | + new WithoutReturn('__invoke', [$workermanTcpConnection, $workermanRequest]), |
44 | 50 | ]); |
45 | 51 |
|
46 | | - /** @var Client|MockObject $client */ |
47 | | - $client = $this->getMockByCalls(Client::class); |
| 52 | + /** @var Client $client */ |
| 53 | + $client = $builder->create(Client::class, []); |
48 | 54 |
|
49 | 55 | $adapter = new BlackfireOnMessageAdapter($onMessage, $client); |
50 | 56 | $adapter($workermanTcpConnection, $workermanRequest); |
51 | 57 | } |
52 | 58 |
|
| 59 | + #[DoesNotPerformAssertions] |
53 | 60 | public function testInvokeWithoutConfigAndWithoutLogger(): void |
54 | 61 | { |
55 | | - /** @var MockObject|WorkermanTcpConnection $workermanTcpConnection */ |
56 | | - $workermanTcpConnection = $this->getMockByCalls(WorkermanTcpConnection::class); |
| 62 | + $builder = new MockObjectBuilder(); |
57 | 63 |
|
58 | | - /** @var MockObject|WorkermanRequest $workermanRequest */ |
59 | | - $workermanRequest = $this->getMockByCalls(WorkermanRequest::class, [ |
60 | | - Call::create('header')->with('x-blackfire-query', null)->willReturn('workerman'), |
| 64 | + /** @var WorkermanTcpConnection $workermanTcpConnection */ |
| 65 | + $workermanTcpConnection = $builder->create(WorkermanTcpConnection::class, [ |
| 66 | + new WithoutReturn('__destruct', []), |
61 | 67 | ]); |
62 | 68 |
|
63 | | - /** @var MockObject|OnMessageInterface $onMessage */ |
64 | | - $onMessage = $this->getMockByCalls(OnMessageInterface::class, [ |
65 | | - Call::create('__invoke')->with($workermanTcpConnection, $workermanRequest), |
| 69 | + /** @var WorkermanRequest $workermanRequest */ |
| 70 | + $workermanRequest = $builder->create(WorkermanRequest::class, [ |
| 71 | + new WithReturn('header', ['x-blackfire-query', null], 'workerman'), |
| 72 | + new WithoutReturn('__destruct', []), |
66 | 73 | ]); |
67 | 74 |
|
68 | | - /** @var MockObject|Probe $probe */ |
69 | | - $probe = $this->getMockByCalls(Probe::class); |
| 75 | + /** @var OnMessageInterface $onMessage */ |
| 76 | + $onMessage = $builder->create(OnMessageInterface::class, [ |
| 77 | + new WithoutReturn('__invoke', [$workermanTcpConnection, $workermanRequest]), |
| 78 | + ]); |
| 79 | + |
| 80 | + /** @var Probe $probe */ |
| 81 | + $probe = $builder->create(Probe::class, []); |
70 | 82 |
|
71 | | - /** @var Client|MockObject $client */ |
72 | | - $client = $this->getMockByCalls(Client::class, [ |
73 | | - Call::create('createProbe')->with(new ArgumentInstanceOf(Configuration::class), true)->willReturn($probe), |
74 | | - Call::create('endProbe')->with($probe), |
| 83 | + /** @var Client $client */ |
| 84 | + $client = $builder->create(Client::class, [ |
| 85 | + new WithCallback('createProbe', static fn (Configuration $configuration): Probe => $probe), |
| 86 | + new WithoutReturn('endProbe', [$probe]), |
75 | 87 | ]); |
76 | 88 |
|
77 | 89 | $adapter = new BlackfireOnMessageAdapter($onMessage, $client); |
78 | 90 | $adapter($workermanTcpConnection, $workermanRequest); |
79 | 91 | } |
80 | 92 |
|
| 93 | + #[DoesNotPerformAssertions] |
81 | 94 | public function testInvokeWithConfigAndWithLogger(): void |
82 | 95 | { |
83 | | - /** @var MockObject|WorkermanTcpConnection $workermanTcpConnection */ |
84 | | - $workermanTcpConnection = $this->getMockByCalls(WorkermanTcpConnection::class); |
| 96 | + $builder = new MockObjectBuilder(); |
85 | 97 |
|
86 | | - /** @var MockObject|WorkermanRequest $workermanRequest */ |
87 | | - $workermanRequest = $this->getMockByCalls(WorkermanRequest::class, [ |
88 | | - Call::create('header')->with('x-blackfire-query', null)->willReturn('workerman'), |
| 98 | + /** @var WorkermanTcpConnection $workermanTcpConnection */ |
| 99 | + $workermanTcpConnection = $builder->create(WorkermanTcpConnection::class, [ |
| 100 | + new WithoutReturn('__destruct', []), |
89 | 101 | ]); |
90 | 102 |
|
91 | | - /** @var MockObject|OnMessageInterface $onMessage */ |
92 | | - $onMessage = $this->getMockByCalls(OnMessageInterface::class, [ |
93 | | - Call::create('__invoke')->with($workermanTcpConnection, $workermanRequest), |
| 103 | + /** @var WorkermanRequest $workermanRequest */ |
| 104 | + $workermanRequest = $builder->create(WorkermanRequest::class, [ |
| 105 | + new WithReturn('header', ['x-blackfire-query', null], 'workerman'), |
| 106 | + new WithoutReturn('__destruct', []), |
94 | 107 | ]); |
95 | 108 |
|
96 | | - /** @var Configuration|MockObject $config */ |
97 | | - $config = $this->getMockByCalls(Configuration::class); |
| 109 | + /** @var OnMessageInterface $onMessage */ |
| 110 | + $onMessage = $builder->create(OnMessageInterface::class, [ |
| 111 | + new WithoutReturn('__invoke', [$workermanTcpConnection, $workermanRequest]), |
| 112 | + ]); |
98 | 113 |
|
99 | | - /** @var MockObject|Probe $probe */ |
100 | | - $probe = $this->getMockByCalls(Probe::class); |
| 114 | + /** @var Configuration $config */ |
| 115 | + $config = $builder->create(Configuration::class, []); |
101 | 116 |
|
102 | | - /** @var Client|MockObject $client */ |
103 | | - $client = $this->getMockByCalls(Client::class, [ |
104 | | - Call::create('createProbe')->with($config, true)->willReturn($probe), |
105 | | - Call::create('endProbe')->with($probe), |
| 117 | + /** @var Probe $probe */ |
| 118 | + $probe = $builder->create(Probe::class, []); |
| 119 | + |
| 120 | + /** @var Client $client */ |
| 121 | + $client = $builder->create(Client::class, [ |
| 122 | + new WithReturn('createProbe', [$config, true], $probe), |
| 123 | + new WithoutReturn('endProbe', [$probe]), |
106 | 124 | ]); |
107 | 125 |
|
108 | | - /** @var LoggerInterface|MockObject $logger */ |
109 | | - $logger = $this->getMockByCalls(LoggerInterface::class); |
| 126 | + /** @var LoggerInterface $logger */ |
| 127 | + $logger = $builder->create(LoggerInterface::class, []); |
110 | 128 |
|
111 | 129 | $adapter = new BlackfireOnMessageAdapter($onMessage, $client, $config, $logger); |
112 | 130 | $adapter($workermanTcpConnection, $workermanRequest); |
113 | 131 | } |
114 | 132 |
|
| 133 | + #[DoesNotPerformAssertions] |
115 | 134 | public function testInvokeWithExceptionOnCreateProbe(): void |
116 | 135 | { |
117 | | - /** @var MockObject|WorkermanTcpConnection $workermanTcpConnection */ |
118 | | - $workermanTcpConnection = $this->getMockByCalls(WorkermanTcpConnection::class); |
| 136 | + $builder = new MockObjectBuilder(); |
| 137 | + |
| 138 | + /** @var WorkermanTcpConnection $workermanTcpConnection */ |
| 139 | + $workermanTcpConnection = $builder->create(WorkermanTcpConnection::class, [ |
| 140 | + new WithoutReturn('__destruct', []), |
| 141 | + ]); |
119 | 142 |
|
120 | | - /** @var MockObject|WorkermanRequest $workermanRequest */ |
121 | | - $workermanRequest = $this->getMockByCalls(WorkermanRequest::class, [ |
122 | | - Call::create('header')->with('x-blackfire-query', null)->willReturn('workerman'), |
| 143 | + /** @var WorkermanRequest $workermanRequest */ |
| 144 | + $workermanRequest = $builder->create(WorkermanRequest::class, [ |
| 145 | + new WithReturn('header', ['x-blackfire-query', null], 'workerman'), |
123 | 146 | ]); |
124 | 147 |
|
125 | | - /** @var MockObject|OnMessageInterface $onMessage */ |
126 | | - $onMessage = $this->getMockByCalls(OnMessageInterface::class, [ |
127 | | - Call::create('__invoke')->with($workermanTcpConnection, $workermanRequest), |
| 148 | + /** @var OnMessageInterface $onMessage */ |
| 149 | + $onMessage = $builder->create(OnMessageInterface::class, [ |
| 150 | + new WithoutReturn('__invoke', [$workermanTcpConnection, $workermanRequest]), |
128 | 151 | ]); |
129 | 152 |
|
130 | | - /** @var Configuration|MockObject $config */ |
131 | | - $config = $this->getMockByCalls(Configuration::class); |
| 153 | + /** @var Configuration $config */ |
| 154 | + $config = $builder->create(Configuration::class, []); |
132 | 155 |
|
133 | 156 | $exception = new LogicException('Something went wrong'); |
134 | 157 |
|
135 | | - /** @var Client|MockObject $client */ |
136 | | - $client = $this->getMockByCalls(Client::class, [ |
137 | | - Call::create('createProbe')->with($config, true)->willThrowException($exception), |
| 158 | + /** @var Client $client */ |
| 159 | + $client = $builder->create(Client::class, [ |
| 160 | + new WithException('createProbe', [$config, true], $exception), |
138 | 161 | ]); |
139 | 162 |
|
140 | | - /** @var LoggerInterface|MockObject $logger */ |
141 | | - $logger = $this->getMockByCalls(LoggerInterface::class, [ |
142 | | - Call::create('error')->with('Blackfire exception: Something went wrong', []), |
| 163 | + /** @var LoggerInterface $logger */ |
| 164 | + $logger = $builder->create(LoggerInterface::class, [ |
| 165 | + new WithoutReturn('error', ['Blackfire exception: Something went wrong', []]), |
143 | 166 | ]); |
144 | 167 |
|
145 | 168 | $adapter = new BlackfireOnMessageAdapter($onMessage, $client, $config, $logger); |
146 | 169 | $adapter($workermanTcpConnection, $workermanRequest); |
147 | 170 | } |
148 | 171 |
|
| 172 | + #[DoesNotPerformAssertions] |
149 | 173 | public function testInvokeWithExceptionOnProbeEnd(): void |
150 | 174 | { |
151 | | - /** @var MockObject|WorkermanTcpConnection $workermanTcpConnection */ |
152 | | - $workermanTcpConnection = $this->getMockByCalls(WorkermanTcpConnection::class); |
| 175 | + $builder = new MockObjectBuilder(); |
| 176 | + |
| 177 | + /** @var WorkermanTcpConnection $workermanTcpConnection */ |
| 178 | + $workermanTcpConnection = $builder->create(WorkermanTcpConnection::class, [ |
| 179 | + new WithoutReturn('__destruct', []), |
| 180 | + ]); |
153 | 181 |
|
154 | | - /** @var MockObject|WorkermanRequest $workermanRequest */ |
155 | | - $workermanRequest = $this->getMockByCalls(WorkermanRequest::class, [ |
156 | | - Call::create('header')->with('x-blackfire-query', null)->willReturn('workerman'), |
| 182 | + /** @var WorkermanRequest $workermanRequest */ |
| 183 | + $workermanRequest = $builder->create(WorkermanRequest::class, [ |
| 184 | + new WithReturn('header', ['x-blackfire-query', null], 'workerman'), |
| 185 | + new WithoutReturn('__destruct', []), |
157 | 186 | ]); |
158 | 187 |
|
159 | | - /** @var MockObject|OnMessageInterface $onMessage */ |
160 | | - $onMessage = $this->getMockByCalls(OnMessageInterface::class, [ |
161 | | - Call::create('__invoke')->with($workermanTcpConnection, $workermanRequest), |
| 188 | + /** @var OnMessageInterface $onMessage */ |
| 189 | + $onMessage = $builder->create(OnMessageInterface::class, [ |
| 190 | + new WithoutReturn('__invoke', [$workermanTcpConnection, $workermanRequest]), |
162 | 191 | ]); |
163 | 192 |
|
164 | | - /** @var Configuration|MockObject $config */ |
165 | | - $config = $this->getMockByCalls(Configuration::class); |
| 193 | + /** @var Configuration $config */ |
| 194 | + $config = $builder->create(Configuration::class, []); |
166 | 195 |
|
167 | | - /** @var MockObject|Probe $probe */ |
168 | | - $probe = $this->getMockByCalls(Probe::class); |
| 196 | + /** @var Probe $probe */ |
| 197 | + $probe = $builder->create(Probe::class, []); |
169 | 198 |
|
170 | 199 | $exception = new LogicException('Something went wrong'); |
171 | 200 |
|
172 | | - /** @var Client|MockObject $client */ |
173 | | - $client = $this->getMockByCalls(Client::class, [ |
174 | | - Call::create('createProbe')->with($config, true)->willReturn($probe), |
175 | | - Call::create('endProbe')->with($probe)->willThrowException($exception), |
| 201 | + /** @var Client $client */ |
| 202 | + $client = $builder->create(Client::class, [ |
| 203 | + new WithReturn('createProbe', [$config, true], $probe), |
| 204 | + new WithException('endProbe', [$probe], $exception), |
176 | 205 | ]); |
177 | 206 |
|
178 | | - /** @var LoggerInterface|MockObject $logger */ |
179 | | - $logger = $this->getMockByCalls(LoggerInterface::class, [ |
180 | | - Call::create('error')->with('Blackfire exception: Something went wrong', []), |
| 207 | + /** @var LoggerInterface $logger */ |
| 208 | + $logger = $builder->create(LoggerInterface::class, [ |
| 209 | + new WithoutReturn('error', ['Blackfire exception: Something went wrong', []]), |
181 | 210 | ]); |
182 | 211 |
|
183 | 212 | $adapter = new BlackfireOnMessageAdapter($onMessage, $client, $config, $logger); |
|
0 commit comments