File: ServeCommandLogParserTest.php

package info (click to toggle)
php-laravel-framework 11.46.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,276 kB
  • sloc: php: 266,630; sh: 167; javascript: 51; makefile: 46
file content (76 lines) | stat: -rw-r--r-- 2,690 bytes parent folder | download
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);
    }
}