Skip to content

Commit a6613cc

Browse files
committed
Merge branch 'patch-2' into 1.x
2 parents 7260b83 + fdf2703 commit a6613cc

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Commands/Concerns/InteractsWithIO.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ public function requestInfo($request, $verbosity = null)
9494
$terminalWidth = $this->getTerminalWidth();
9595

9696
$url = parse_url($request['url'], PHP_URL_PATH) ?: '/';
97-
9897
$duration = number_format(round($request['duration'], 2), 2, '.', '');
98+
$memory = number_format(round($request['memory'] ?? memory_get_usage() / 1024 / 1204, 2), 2, '.', '');
9999

100100
['method' => $method, 'statusCode' => $statusCode] = $request;
101101

102-
$dots = str_repeat('.', max($terminalWidth - strlen($method.$url.$duration) - 16, 0));
102+
$dots = str_repeat('.', max($terminalWidth - strlen($method.$url.$duration.$memory) - 19, 0));
103103

104104
if (empty($dots) && ! $this->output->isVerbose()) {
105105
$url = substr($url, 0, $terminalWidth - strlen($method.$duration) - 15 - 3).'...';
@@ -108,7 +108,7 @@ public function requestInfo($request, $verbosity = null)
108108
}
109109

110110
$this->output->writeln(sprintf(
111-
' <fg=%s;options=bold>%s </> <fg=cyan;options=bold>%s</> <options=bold>%s</><fg=#6C7280> %s%s ms</>',
111+
' <fg=%s;options=bold>%s </> <fg=cyan;options=bold>%s</> <options=bold>%s</><fg=#6C7280> %s%s mb %s ms</>',
112112
match (true) {
113113
$statusCode >= 500 => 'red',
114114
$statusCode >= 400 => 'yellow',
@@ -120,6 +120,7 @@ public function requestInfo($request, $verbosity = null)
120120
$method,
121121
$url,
122122
$dots,
123+
$memory,
123124
$duration,
124125
), $this->parseVerbosity($verbosity));
125126
}

tests/CommandTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,31 @@ public function test_request()
5454
'method' => 'GET',
5555
'url' => 'http://127.0.0.1/welcome',
5656
'statusCode' => '200',
57+
'memory' => 23.43,
5758
'duration' => 10,
5859
]);
5960

6061
$command->requestInfo([
6162
'method' => 'POST',
6263
'url' => 'http://127.0.0.1:8080',
6364
'statusCode' => '404',
65+
'memory' => 26.43,
6466
'duration' => 1234,
6567
]);
6668

6769
$command->requestInfo([
6870
'method' => 'POST',
6971
'url' => 'http://127.0.0.1:8080/'.str_repeat('foo', 100),
7072
'statusCode' => 500,
73+
'memory' => 28.43,
7174
'duration' => 4567854,
7275
]);
7376

7477
$this->assertEquals(<<<'EOF'
75-
200 GET /welcome .................. 10.00 ms
76-
404 POST / ...................... 1234.00 ms
77-
500 POST /foofoofoofoofoofo... 4567854.00 ms
78-
78+
200 GET /welcome ..........23.43 mb 10.00 ms
79+
404 POST / ..............26.43 mb 1234.00 ms
80+
500 POST /foofoofoofoofoofo... 23.46 mb 4567854.00 ms
81+
7982
EOF, $output->fetch());
8083
}
8184

0 commit comments

Comments
 (0)