-
Notifications
You must be signed in to change notification settings - Fork 11.3k
/
Copy pathServeCommandLogParserTest.php
76 lines (55 loc) · 2.63 KB
/
ServeCommandLogParserTest.php
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
<?php
namespace Illuminate\Tests\Foundation\Console;
use Illuminate\Foundation\Console\ServeCommand;
use PHPUnit\Framework\TestCase;
class ServeCommandLogParserTest extends TestCase
{
public function testExtractRequestPortWithValidLogLine()
{
$line = '[Mon Nov 19 10:30:45 2024] :8080 Info';
$this->assertEquals(8080, ServeCommand::getRequestPortFromLine($line));
}
public function testExtractRequestPortWithValidLogLineAndExtraData()
{
$line = '[Mon Nov 19 10:30:45 2024] :3000 [Client Connected]';
$this->assertEquals(3000, ServeCommand::getRequestPortFromLine($line));
}
public function testExtractRequestPortWithValidLogLineWithoutDate()
{
$line = ':5000 [Server Started]';
$this->assertEquals(5000, ServeCommand::getRequestPortFromLine($line));
}
public function testExtractRequestPortWithMissingPort()
{
$line = '[Mon Nov 19 10:30:45 2024] Info';
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Failed to extract the request port. Ensure the log line contains a valid port: [Mon Nov 19 10:30:45 2024] Info');
ServeCommand::getRequestPortFromLine($line);
}
public function testExtractRequestPortWithInvalidPortFormat()
{
$line = '[Mon Nov 19 10:30:45 2024] :abcd Info';
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Failed to extract the request port. Ensure the log line contains a valid port: [Mon Nov 19 10:30:45 2024] :abcd Info');
ServeCommand::getRequestPortFromLine($line);
}
public function testExtractRequestPortWithEmptyLogLine()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Failed to extract the request port. Ensure the log line contains a valid port: ');
ServeCommand::getRequestPortFromLine('');
}
public function testExtractRequestPortWithWhitespaceOnlyLine()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Failed to extract the request port. Ensure the log line contains a valid port: ');
ServeCommand::getRequestPortFromLine(' ');
}
public function testExtractRequestPortWithRandomString()
{
$line = 'Random log entry without port';
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Failed to extract the request port. Ensure the log line contains a valid port: Random log entry without port');
ServeCommand::getRequestPortFromLine($line);
}
}