|
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, []); |
35 | 38 |
|
36 | | - /** @var MockObject|WorkermanRequest $workermanRequest */ |
37 | | - $workermanRequest = $this->getMockByCalls(WorkermanRequest::class, [ |
38 | | - Call::create('header')->with('x-blackfire-query', null)->willReturn(null), |
| 39 | + /** @var WorkermanRequest $workermanRequest */ |
| 40 | + $workermanRequest = $builder->create(WorkermanRequest::class, [ |
| 41 | + new WithReturn('header', ['x-blackfire-query', null], null), |
39 | 42 | ]); |
40 | 43 |
|
41 | | - /** @var MockObject|OnMessageInterface $onMessage */ |
42 | | - $onMessage = $this->getMockByCalls(OnMessageInterface::class, [ |
43 | | - Call::create('__invoke')->with($workermanTcpConnection, $workermanRequest), |
| 44 | + /** @var OnMessageInterface $onMessage */ |
| 45 | + $onMessage = $builder->create(OnMessageInterface::class, [ |
| 46 | + new WithoutReturn('__invoke', [$workermanTcpConnection, $workermanRequest]), |
44 | 47 | ]); |
45 | 48 |
|
46 | | - /** @var Client|MockObject $client */ |
47 | | - $client = $this->getMockByCalls(Client::class); |
| 49 | + /** @var Client $client */ |
| 50 | + $client = $builder->create(Client::class, []); |
48 | 51 |
|
49 | 52 | $adapter = new BlackfireOnMessageAdapter($onMessage, $client); |
50 | 53 | $adapter($workermanTcpConnection, $workermanRequest); |
51 | 54 | } |
52 | 55 |
|
| 56 | + #[DoesNotPerformAssertions] |
53 | 57 | public function testInvokeWithoutConfigAndWithoutLogger(): void |
54 | 58 | { |
55 | | - /** @var MockObject|WorkermanTcpConnection $workermanTcpConnection */ |
56 | | - $workermanTcpConnection = $this->getMockByCalls(WorkermanTcpConnection::class); |
| 59 | + $builder = new MockObjectBuilder(); |
| 60 | + |
| 61 | + /** @var WorkermanTcpConnection $workermanTcpConnection */ |
| 62 | + $workermanTcpConnection = $builder->create(WorkermanTcpConnection::class, []); |
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 WorkermanRequest $workermanRequest */ |
| 65 | + $workermanRequest = $builder->create(WorkermanRequest::class, [ |
| 66 | + new WithReturn('header', ['x-blackfire-query', null], 'workerman'), |
61 | 67 | ]); |
62 | 68 |
|
63 | | - /** @var MockObject|OnMessageInterface $onMessage */ |
64 | | - $onMessage = $this->getMockByCalls(OnMessageInterface::class, [ |
65 | | - Call::create('__invoke')->with($workermanTcpConnection, $workermanRequest), |
| 69 | + /** @var OnMessageInterface $onMessage */ |
| 70 | + $onMessage = $builder->create(OnMessageInterface::class, [ |
| 71 | + new WithoutReturn('__invoke', [$workermanTcpConnection, $workermanRequest]), |
66 | 72 | ]); |
67 | 73 |
|
68 | | - /** @var MockObject|Probe $probe */ |
69 | | - $probe = $this->getMockByCalls(Probe::class); |
| 74 | + /** @var Probe $probe */ |
| 75 | + $probe = $builder->create(Probe::class, []); |
70 | 76 |
|
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), |
| 77 | + /** @var Client $client */ |
| 78 | + $client = $builder->create(Client::class, [ |
| 79 | + new WithCallback('createProbe', static fn (Configuration $configuration): Probe => $probe), |
| 80 | + new WithoutReturn('endProbe', [$probe]), |
75 | 81 | ]); |
76 | 82 |
|
77 | 83 | $adapter = new BlackfireOnMessageAdapter($onMessage, $client); |
78 | 84 | $adapter($workermanTcpConnection, $workermanRequest); |
79 | 85 | } |
80 | 86 |
|
| 87 | + #[DoesNotPerformAssertions] |
81 | 88 | public function testInvokeWithConfigAndWithLogger(): void |
82 | 89 | { |
83 | | - /** @var MockObject|WorkermanTcpConnection $workermanTcpConnection */ |
84 | | - $workermanTcpConnection = $this->getMockByCalls(WorkermanTcpConnection::class); |
| 90 | + $builder = new MockObjectBuilder(); |
85 | 91 |
|
86 | | - /** @var MockObject|WorkermanRequest $workermanRequest */ |
87 | | - $workermanRequest = $this->getMockByCalls(WorkermanRequest::class, [ |
88 | | - Call::create('header')->with('x-blackfire-query', null)->willReturn('workerman'), |
| 92 | + /** @var WorkermanTcpConnection $workermanTcpConnection */ |
| 93 | + $workermanTcpConnection = $builder->create(WorkermanTcpConnection::class, []); |
| 94 | + |
| 95 | + /** @var WorkermanRequest $workermanRequest */ |
| 96 | + $workermanRequest = $builder->create(WorkermanRequest::class, [ |
| 97 | + new WithReturn('header', ['x-blackfire-query', null], 'workerman'), |
89 | 98 | ]); |
90 | 99 |
|
91 | | - /** @var MockObject|OnMessageInterface $onMessage */ |
92 | | - $onMessage = $this->getMockByCalls(OnMessageInterface::class, [ |
93 | | - Call::create('__invoke')->with($workermanTcpConnection, $workermanRequest), |
| 100 | + /** @var OnMessageInterface $onMessage */ |
| 101 | + $onMessage = $builder->create(OnMessageInterface::class, [ |
| 102 | + new WithoutReturn('__invoke', [$workermanTcpConnection, $workermanRequest]), |
94 | 103 | ]); |
95 | 104 |
|
96 | | - /** @var Configuration|MockObject $config */ |
97 | | - $config = $this->getMockByCalls(Configuration::class); |
| 105 | + /** @var Configuration $config */ |
| 106 | + $config = $builder->create(Configuration::class, []); |
98 | 107 |
|
99 | | - /** @var MockObject|Probe $probe */ |
100 | | - $probe = $this->getMockByCalls(Probe::class); |
| 108 | + /** @var Probe $probe */ |
| 109 | + $probe = $builder->create(Probe::class, []); |
101 | 110 |
|
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), |
| 111 | + /** @var Client $client */ |
| 112 | + $client = $builder->create(Client::class, [ |
| 113 | + new WithReturn('createProbe', [$config, true], $probe), |
| 114 | + new WithoutReturn('endProbe', [$probe]), |
106 | 115 | ]); |
107 | 116 |
|
108 | | - /** @var LoggerInterface|MockObject $logger */ |
109 | | - $logger = $this->getMockByCalls(LoggerInterface::class); |
| 117 | + /** @var LoggerInterface $logger */ |
| 118 | + $logger = $builder->create(LoggerInterface::class, []); |
110 | 119 |
|
111 | 120 | $adapter = new BlackfireOnMessageAdapter($onMessage, $client, $config, $logger); |
112 | 121 | $adapter($workermanTcpConnection, $workermanRequest); |
113 | 122 | } |
114 | 123 |
|
| 124 | + #[DoesNotPerformAssertions] |
115 | 125 | public function testInvokeWithExceptionOnCreateProbe(): void |
116 | 126 | { |
117 | | - /** @var MockObject|WorkermanTcpConnection $workermanTcpConnection */ |
118 | | - $workermanTcpConnection = $this->getMockByCalls(WorkermanTcpConnection::class); |
| 127 | + $builder = new MockObjectBuilder(); |
| 128 | + |
| 129 | + /** @var WorkermanTcpConnection $workermanTcpConnection */ |
| 130 | + $workermanTcpConnection = $builder->create(WorkermanTcpConnection::class, []); |
119 | 131 |
|
120 | | - /** @var MockObject|WorkermanRequest $workermanRequest */ |
121 | | - $workermanRequest = $this->getMockByCalls(WorkermanRequest::class, [ |
122 | | - Call::create('header')->with('x-blackfire-query', null)->willReturn('workerman'), |
| 132 | + /** @var WorkermanRequest $workermanRequest */ |
| 133 | + $workermanRequest = $builder->create(WorkermanRequest::class, [ |
| 134 | + new WithReturn('header', ['x-blackfire-query', null], 'workerman'), |
123 | 135 | ]); |
124 | 136 |
|
125 | | - /** @var MockObject|OnMessageInterface $onMessage */ |
126 | | - $onMessage = $this->getMockByCalls(OnMessageInterface::class, [ |
127 | | - Call::create('__invoke')->with($workermanTcpConnection, $workermanRequest), |
| 137 | + /** @var OnMessageInterface $onMessage */ |
| 138 | + $onMessage = $builder->create(OnMessageInterface::class, [ |
| 139 | + new WithoutReturn('__invoke', [$workermanTcpConnection, $workermanRequest]), |
128 | 140 | ]); |
129 | 141 |
|
130 | | - /** @var Configuration|MockObject $config */ |
131 | | - $config = $this->getMockByCalls(Configuration::class); |
| 142 | + /** @var Configuration $config */ |
| 143 | + $config = $builder->create(Configuration::class, []); |
132 | 144 |
|
133 | 145 | $exception = new LogicException('Something went wrong'); |
134 | 146 |
|
135 | | - /** @var Client|MockObject $client */ |
136 | | - $client = $this->getMockByCalls(Client::class, [ |
137 | | - Call::create('createProbe')->with($config, true)->willThrowException($exception), |
| 147 | + /** @var Client $client */ |
| 148 | + $client = $builder->create(Client::class, [ |
| 149 | + new WithException('createProbe', [$config, true], $exception), |
138 | 150 | ]); |
139 | 151 |
|
140 | | - /** @var LoggerInterface|MockObject $logger */ |
141 | | - $logger = $this->getMockByCalls(LoggerInterface::class, [ |
142 | | - Call::create('error')->with('Blackfire exception: Something went wrong', []), |
| 152 | + /** @var LoggerInterface $logger */ |
| 153 | + $logger = $builder->create(LoggerInterface::class, [ |
| 154 | + new WithoutReturn('error', ['Blackfire exception: Something went wrong', []]), |
143 | 155 | ]); |
144 | 156 |
|
145 | 157 | $adapter = new BlackfireOnMessageAdapter($onMessage, $client, $config, $logger); |
146 | 158 | $adapter($workermanTcpConnection, $workermanRequest); |
147 | 159 | } |
148 | 160 |
|
| 161 | + #[DoesNotPerformAssertions] |
149 | 162 | public function testInvokeWithExceptionOnProbeEnd(): void |
150 | 163 | { |
151 | | - /** @var MockObject|WorkermanTcpConnection $workermanTcpConnection */ |
152 | | - $workermanTcpConnection = $this->getMockByCalls(WorkermanTcpConnection::class); |
| 164 | + $builder = new MockObjectBuilder(); |
| 165 | + |
| 166 | + /** @var WorkermanTcpConnection $workermanTcpConnection */ |
| 167 | + $workermanTcpConnection = $builder->create(WorkermanTcpConnection::class, []); |
153 | 168 |
|
154 | | - /** @var MockObject|WorkermanRequest $workermanRequest */ |
155 | | - $workermanRequest = $this->getMockByCalls(WorkermanRequest::class, [ |
156 | | - Call::create('header')->with('x-blackfire-query', null)->willReturn('workerman'), |
| 169 | + /** @var WorkermanRequest $workermanRequest */ |
| 170 | + $workermanRequest = $builder->create(WorkermanRequest::class, [ |
| 171 | + new WithReturn('header', ['x-blackfire-query', null], 'workerman'), |
157 | 172 | ]); |
158 | 173 |
|
159 | | - /** @var MockObject|OnMessageInterface $onMessage */ |
160 | | - $onMessage = $this->getMockByCalls(OnMessageInterface::class, [ |
161 | | - Call::create('__invoke')->with($workermanTcpConnection, $workermanRequest), |
| 174 | + /** @var OnMessageInterface $onMessage */ |
| 175 | + $onMessage = $builder->create(OnMessageInterface::class, [ |
| 176 | + new WithoutReturn('__invoke', [$workermanTcpConnection, $workermanRequest]), |
162 | 177 | ]); |
163 | 178 |
|
164 | | - /** @var Configuration|MockObject $config */ |
165 | | - $config = $this->getMockByCalls(Configuration::class); |
| 179 | + /** @var Configuration $config */ |
| 180 | + $config = $builder->create(Configuration::class, []); |
166 | 181 |
|
167 | | - /** @var MockObject|Probe $probe */ |
168 | | - $probe = $this->getMockByCalls(Probe::class); |
| 182 | + /** @var Probe $probe */ |
| 183 | + $probe = $builder->create(Probe::class, []); |
169 | 184 |
|
170 | 185 | $exception = new LogicException('Something went wrong'); |
171 | 186 |
|
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), |
| 187 | + /** @var Client $client */ |
| 188 | + $client = $builder->create(Client::class, [ |
| 189 | + new WithReturn('createProbe', [$config, true], $probe), |
| 190 | + new WithException('endProbe', [$probe], $exception), |
176 | 191 | ]); |
177 | 192 |
|
178 | | - /** @var LoggerInterface|MockObject $logger */ |
179 | | - $logger = $this->getMockByCalls(LoggerInterface::class, [ |
180 | | - Call::create('error')->with('Blackfire exception: Something went wrong', []), |
| 193 | + /** @var LoggerInterface $logger */ |
| 194 | + $logger = $builder->create(LoggerInterface::class, [ |
| 195 | + new WithoutReturn('error', ['Blackfire exception: Something went wrong', []]), |
181 | 196 | ]); |
182 | 197 |
|
183 | 198 | $adapter = new BlackfireOnMessageAdapter($onMessage, $client, $config, $logger); |
|
0 commit comments