-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNewRelicOnMessageAdapterTest.php
More file actions
114 lines (95 loc) · 3.35 KB
/
NewRelicOnMessageAdapterTest.php
File metadata and controls
114 lines (95 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
declare(strict_types=1);
namespace Chubbyphp\WorkermanRequestHandler\Adapter
{
final class TestNewRelicStartTransaction
{
/**
* @var array<int, array>
*/
private static array $calls = [];
public static function add(string $appname, ?string $license = null): void
{
self::$calls[] = ['appname' => $appname, 'license' => $license];
}
/**
* @return array<int, array>
*/
public static function all(): array
{
return self::$calls;
}
public static function reset(): void
{
self::$calls = [];
}
}
function newrelic_start_transaction(string $appname, ?string $license = null): void
{
TestNewRelicStartTransaction::add($appname, $license);
}
final class TestNewRelicEndTransaction
{
/**
* @var array<int, array>
*/
private static array $calls = [];
public static function add(bool $ignore): void
{
self::$calls[] = ['ignore' => $ignore];
}
/**
* @return array<int, array>
*/
public static function all(): array
{
return self::$calls;
}
public static function reset(): void
{
self::$calls = [];
}
}
function newrelic_end_transaction(bool $ignore = false): void
{
TestNewRelicEndTransaction::add($ignore);
}
}
namespace Chubbyphp\Tests\WorkermanRequestHandler\Unit\Adapter
{
use Chubbyphp\Mock\MockMethod\WithoutReturn;
use Chubbyphp\Mock\MockObjectBuilder;
use Chubbyphp\WorkermanRequestHandler\Adapter\NewRelicOnMessageAdapter;
use Chubbyphp\WorkermanRequestHandler\Adapter\TestNewRelicEndTransaction;
use Chubbyphp\WorkermanRequestHandler\Adapter\TestNewRelicStartTransaction;
use Chubbyphp\WorkermanRequestHandler\OnMessageInterface;
use PHPUnit\Framework\TestCase;
use Workerman\Connection\TcpConnection as WorkermanTcpConnection;
use Workerman\Protocols\Http\Request as WorkermanRequest;
/**
* @covers \Chubbyphp\WorkermanRequestHandler\Adapter\NewRelicOnMessageAdapter
*
* @internal
*/
final class NewRelicOnMessageAdapterTest extends TestCase
{
public function testInvoke(): void
{
TestNewRelicStartTransaction::reset();
TestNewRelicEndTransaction::reset();
$builder = new MockObjectBuilder();
/** @var WorkermanTcpConnection $workermanTcpConnection */
$workermanTcpConnection = $builder->create(WorkermanTcpConnection::class, []);
/** @var WorkermanRequest $workermanRequest */
$workermanRequest = $builder->create(WorkermanRequest::class, []);
/** @var OnMessageInterface $onMessage */
$onMessage = $builder->create(OnMessageInterface::class, [
new WithoutReturn('__invoke', [$workermanTcpConnection, $workermanRequest]),
]);
$adapter = new NewRelicOnMessageAdapter($onMessage, 'myapp');
$adapter($workermanTcpConnection, $workermanRequest);
self::assertSame([['appname' => 'myapp', 'license' => null]], TestNewRelicStartTransaction::all());
self::assertSame([['ignore' => false]], TestNewRelicEndTransaction::all());
}
}
}