Skip to content

Commit c37cd8f

Browse files
committed
chubbyphp-mock-v2
1 parent 5d095ab commit c37cd8f

File tree

6 files changed

+287
-248
lines changed

6 files changed

+287
-248
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
"workerman/workerman": "^4.2.1"
2626
},
2727
"require-dev": {
28-
"blackfire/php-sdk": "^2.5.4",
28+
"blackfire/php-sdk": "^2.5.7",
2929
"chubbyphp/chubbyphp-dev-helper": "dev-master",
30-
"chubbyphp/chubbyphp-mock": "^1.8",
31-
"infection/infection": "^0.29.8",
30+
"chubbyphp/chubbyphp-mock": "^2.0@dev",
31+
"infection/infection": "^0.29.12",
3232
"php-coveralls/php-coveralls": "^2.7",
3333
"phpstan/extension-installer": "^1.4.3",
34-
"phpstan/phpstan": "^2.0.3",
35-
"phpunit/phpunit": "^11.5.0"
34+
"phpstan/phpstan": "^2.1.6",
35+
"phpunit/phpunit": "^11.5.9"
3636
},
3737
"autoload": {
3838
"psr-4": { "Chubbyphp\\WorkermanRequestHandler\\": "src/" }

tests/Unit/Adapter/BlackfireOnMessageAdapterTest.php

Lines changed: 112 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
use Blackfire\Exception\LogicException;
99
use Blackfire\Probe;
1010
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;
1416
use Chubbyphp\WorkermanRequestHandler\Adapter\BlackfireOnMessageAdapter;
1517
use Chubbyphp\WorkermanRequestHandler\OnMessageInterface;
16-
use PHPUnit\Framework\MockObject\MockObject;
18+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
1719
use PHPUnit\Framework\TestCase;
1820
use Psr\Log\LoggerInterface;
1921
use Workerman\Connection\TcpConnection as WorkermanTcpConnection;
@@ -26,158 +28,185 @@
2628
*/
2729
final class BlackfireOnMessageAdapterTest extends TestCase
2830
{
29-
use MockByCallsTrait;
30-
31+
#[DoesNotPerformAssertions]
3132
public function testInvokeWithoutHeaderWithoutConfigAndWithoutLogger(): void
3233
{
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+
]);
3540

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', []),
3945
]);
4046

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]),
4450
]);
4551

46-
/** @var Client|MockObject $client */
47-
$client = $this->getMockByCalls(Client::class);
52+
/** @var Client $client */
53+
$client = $builder->create(Client::class, []);
4854

4955
$adapter = new BlackfireOnMessageAdapter($onMessage, $client);
5056
$adapter($workermanTcpConnection, $workermanRequest);
5157
}
5258

59+
#[DoesNotPerformAssertions]
5360
public function testInvokeWithoutConfigAndWithoutLogger(): void
5461
{
55-
/** @var MockObject|WorkermanTcpConnection $workermanTcpConnection */
56-
$workermanTcpConnection = $this->getMockByCalls(WorkermanTcpConnection::class);
62+
$builder = new MockObjectBuilder();
5763

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', []),
6167
]);
6268

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', []),
6673
]);
6774

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, []);
7082

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]),
7587
]);
7688

7789
$adapter = new BlackfireOnMessageAdapter($onMessage, $client);
7890
$adapter($workermanTcpConnection, $workermanRequest);
7991
}
8092

93+
#[DoesNotPerformAssertions]
8194
public function testInvokeWithConfigAndWithLogger(): void
8295
{
83-
/** @var MockObject|WorkermanTcpConnection $workermanTcpConnection */
84-
$workermanTcpConnection = $this->getMockByCalls(WorkermanTcpConnection::class);
96+
$builder = new MockObjectBuilder();
8597

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', []),
89101
]);
90102

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', []),
94107
]);
95108

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+
]);
98113

99-
/** @var MockObject|Probe $probe */
100-
$probe = $this->getMockByCalls(Probe::class);
114+
/** @var Configuration $config */
115+
$config = $builder->create(Configuration::class, []);
101116

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]),
106124
]);
107125

108-
/** @var LoggerInterface|MockObject $logger */
109-
$logger = $this->getMockByCalls(LoggerInterface::class);
126+
/** @var LoggerInterface $logger */
127+
$logger = $builder->create(LoggerInterface::class, []);
110128

111129
$adapter = new BlackfireOnMessageAdapter($onMessage, $client, $config, $logger);
112130
$adapter($workermanTcpConnection, $workermanRequest);
113131
}
114132

133+
#[DoesNotPerformAssertions]
115134
public function testInvokeWithExceptionOnCreateProbe(): void
116135
{
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+
]);
119142

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'),
123146
]);
124147

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]),
128151
]);
129152

130-
/** @var Configuration|MockObject $config */
131-
$config = $this->getMockByCalls(Configuration::class);
153+
/** @var Configuration $config */
154+
$config = $builder->create(Configuration::class, []);
132155

133156
$exception = new LogicException('Something went wrong');
134157

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),
138161
]);
139162

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', []]),
143166
]);
144167

145168
$adapter = new BlackfireOnMessageAdapter($onMessage, $client, $config, $logger);
146169
$adapter($workermanTcpConnection, $workermanRequest);
147170
}
148171

172+
#[DoesNotPerformAssertions]
149173
public function testInvokeWithExceptionOnProbeEnd(): void
150174
{
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+
]);
153181

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', []),
157186
]);
158187

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]),
162191
]);
163192

164-
/** @var Configuration|MockObject $config */
165-
$config = $this->getMockByCalls(Configuration::class);
193+
/** @var Configuration $config */
194+
$config = $builder->create(Configuration::class, []);
166195

167-
/** @var MockObject|Probe $probe */
168-
$probe = $this->getMockByCalls(Probe::class);
196+
/** @var Probe $probe */
197+
$probe = $builder->create(Probe::class, []);
169198

170199
$exception = new LogicException('Something went wrong');
171200

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),
176205
]);
177206

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', []]),
181210
]);
182211

183212
$adapter = new BlackfireOnMessageAdapter($onMessage, $client, $config, $logger);

tests/Unit/Adapter/NewRelicOnMessageAdapterTest.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,13 @@ function newrelic_end_transaction(bool $ignore = false): void
6969

7070
namespace Chubbyphp\Tests\WorkermanRequestHandler\Unit\Adapter
7171
{
72-
use Chubbyphp\Mock\Call;
73-
use Chubbyphp\Mock\MockByCallsTrait;
72+
use Chubbyphp\Mock\MockMethod\WithoutReturn;
73+
use Chubbyphp\Mock\MockObjectBuilder;
7474
use Chubbyphp\WorkermanRequestHandler\Adapter\NewRelicOnMessageAdapter;
7575
use Chubbyphp\WorkermanRequestHandler\Adapter\TestNewRelicEndTransaction;
7676
use Chubbyphp\WorkermanRequestHandler\Adapter\TestNewRelicStartTransaction;
7777
use Chubbyphp\WorkermanRequestHandler\OnMessageInterface;
7878
use PHPUnit\Framework\TestCase;
79-
use PHPUnit\WorkermanRequestHandler\MockObject\MockObject;
8079
use Workerman\Connection\TcpConnection as WorkermanTcpConnection;
8180
use Workerman\Protocols\Http\Request as WorkermanRequest;
8281

@@ -87,22 +86,22 @@ function newrelic_end_transaction(bool $ignore = false): void
8786
*/
8887
final class NewRelicOnMessageAdapterTest extends TestCase
8988
{
90-
use MockByCallsTrait;
91-
9289
public function testInvoke(): void
9390
{
9491
TestNewRelicStartTransaction::reset();
9592
TestNewRelicEndTransaction::reset();
9693

97-
/** @var MockObject|WorkermanTcpConnection $workermanTcpConnection */
98-
$workermanTcpConnection = $this->getMockByCalls(WorkermanTcpConnection::class);
94+
$builder = new MockObjectBuilder();
95+
96+
/** @var WorkermanTcpConnection $workermanTcpConnection */
97+
$workermanTcpConnection = $builder->create(WorkermanTcpConnection::class, []);
9998

100-
/** @var MockObject|WorkermanRequest $workermanRequest */
101-
$workermanRequest = $this->getMockByCalls(WorkermanRequest::class);
99+
/** @var WorkermanRequest $workermanRequest */
100+
$workermanRequest = $builder->create(WorkermanRequest::class, []);
102101

103-
/** @var MockObject|OnMessageInterface $onMessage */
104-
$onMessage = $this->getMockByCalls(OnMessageInterface::class, [
105-
Call::create('__invoke')->with($workermanTcpConnection, $workermanRequest),
102+
/** @var OnMessageInterface $onMessage */
103+
$onMessage = $builder->create(OnMessageInterface::class, [
104+
new WithoutReturn('__invoke', [$workermanTcpConnection, $workermanRequest]),
106105
]);
107106

108107
$adapter = new NewRelicOnMessageAdapter($onMessage, 'myapp');

0 commit comments

Comments
 (0)