|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use Nyholm\Psr7\ServerRequest; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use stdClass; |
|
10
|
|
|
use Yiisoft\Yii\Debug\Collector\CollectorInterface; |
|
11
|
|
|
use Yiisoft\Yii\Debug\Debugger; |
|
12
|
|
|
use Yiisoft\Yii\Debug\DebuggerIdGenerator; |
|
13
|
|
|
use Yiisoft\Yii\Debug\Storage\MemoryStorage; |
|
14
|
|
|
use Yiisoft\Yii\Debug\Storage\StorageInterface; |
|
15
|
|
|
use Yiisoft\Yii\Http\Event\BeforeRequest; |
|
16
|
|
|
|
|
17
|
|
|
final class DebuggerTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
public function testStartup(): void |
|
20
|
|
|
{ |
|
21
|
|
|
$idGenerator = new DebuggerIdGenerator(); |
|
22
|
|
|
$collector = $this->getMockBuilder(CollectorInterface::class)->getMock(); |
|
23
|
|
|
$collector->expects($this->once())->method('startup'); |
|
24
|
|
|
|
|
25
|
|
|
$debugger = new Debugger($idGenerator, new MemoryStorage($idGenerator), [$collector]); |
|
26
|
|
|
$debugger->startup(new stdClass()); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testStartupWithSkipCollect(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$idGenerator = new DebuggerIdGenerator(); |
|
32
|
|
|
$collector = $this->getMockBuilder(CollectorInterface::class)->getMock(); |
|
33
|
|
|
$collector->expects($this->once())->method('startup'); |
|
34
|
|
|
|
|
35
|
|
|
$debugger = new Debugger($idGenerator, new MemoryStorage($idGenerator), [$collector], ['/test']); |
|
36
|
|
|
$debugger->startup(new BeforeRequest(new ServerRequest('GET', '/debug'))); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testGetId(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$idGenerator = new DebuggerIdGenerator(); |
|
42
|
|
|
$debugger = new Debugger($idGenerator, new MemoryStorage($idGenerator), []); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertEquals($idGenerator->getId(), $debugger->getId()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testWithIgnoredRequests(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$idGenerator = new DebuggerIdGenerator(); |
|
50
|
|
|
$debugger1 = new Debugger($idGenerator, new MemoryStorage($idGenerator), []); |
|
51
|
|
|
$debugger2 = $debugger1->withIgnoredRequests(['/test']); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertNotSame($debugger1, $debugger2); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testWithIgnoredCommands(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$idGenerator = new DebuggerIdGenerator(); |
|
59
|
|
|
$debugger1 = new Debugger($idGenerator, new MemoryStorage($idGenerator), []); |
|
60
|
|
|
$debugger2 = $debugger1->withIgnoredCommands(['command/test']); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertNotSame($debugger1, $debugger2); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testShutdown(): void |
|
66
|
|
|
{ |
|
67
|
|
|
$idGenerator = new DebuggerIdGenerator(); |
|
68
|
|
|
$collector = $this->getMockBuilder(CollectorInterface::class)->getMock(); |
|
69
|
|
|
$collector->expects($this->once())->method('shutdown'); |
|
70
|
|
|
|
|
71
|
|
|
$debugger = new Debugger($idGenerator, new MemoryStorage($idGenerator), [$collector]); |
|
72
|
|
|
$debugger->shutdown(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testShutdownWithSkipCollect(): void |
|
76
|
|
|
{ |
|
77
|
|
|
$idGenerator = new DebuggerIdGenerator(); |
|
78
|
|
|
$collector = $this->getMockBuilder(CollectorInterface::class)->getMock(); |
|
79
|
|
|
$collector->expects($this->once())->method('shutdown'); |
|
80
|
|
|
$storage = $this->getMockBuilder(StorageInterface::class)->getMock(); |
|
81
|
|
|
$storage->expects($this->exactly(0))->method('flush'); |
|
82
|
|
|
|
|
83
|
|
|
$debugger = new Debugger($idGenerator, $storage, [$collector], ['/test']); |
|
84
|
|
|
$debugger->startup(new BeforeRequest(new ServerRequest('GET', '/test'))); |
|
85
|
|
|
$debugger->shutdown(); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|