Skip to content

Commit

Permalink
fix option on command
Browse files Browse the repository at this point in the history
  • Loading branch information
asciito committed Oct 23, 2023
1 parent e18c204 commit c19c958
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions app/Commands/DriverManagerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class DriverManagerCommand extends Command
];

protected array $commands = [
'start' => './chromedriver --log-level=ALL --port {port} &',
'pid' => "ps aux | grep '[c]hromedriver --log-level=ALL {options}' | awk '{print $2,$14}'",
'start' => './chromedriver --log-level=ALL --port={port} &',
'pid' => "ps aux | grep '[c]hromedriver --log-level=ALL {options}' | awk '{print $2,$13}'",
'stop' => 'kill -9 {pid}',
];
Expand All @@ -46,6 +46,7 @@ public function handle(): int
'stop' => 'Stop a server',
'restart' => 'Restart a server',
'status' => 'Status of a server',
'list' => 'List all the server available in the system',
'kill' => 'Kill all the servers available in the system',
]);
Expand Down Expand Up @@ -207,7 +208,7 @@ protected function command(string $cmd, array $with)

protected function getProcessID(string $port): ?int
{
$process = $this->command('pid', ['{options}' => '--port '.$port]);
$process = $this->command('pid', ['{options}' => '--port='.$port]);

$output = explode(' ', trim($process->output()));

Expand All @@ -216,7 +217,7 @@ protected function getProcessID(string $port): ?int

protected function getProcessIDs(): ?Collection
{
$process = $this->command('pid', ['{pid}' => '']);
$process = $this->command('pid', ['{options}' => '']);

if (empty($process->output())) {
return null;
Expand All @@ -227,7 +228,7 @@ protected function getProcessIDs(): ?Collection
return collect($raw)->map(function (string $data) {
$data = explode(' ', $data);

return ['pid' => $data[0], 'port' => $data[1]];
return ['pid' => $data[0], 'port' => Str::remove('--port=', $data[1])];
});
}

Expand Down
10 changes: 5 additions & 5 deletions tests/Feature/ManageDriverCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
->expectsOutputToContain('Google Chrome Driver server is up and running')
->assertSuccessful();

Process::assertRan('./chromedriver --log-level=ALL --port 9515 &');
Process::assertRan('./chromedriver --log-level=ALL --port=9515 &');
});

it('stop a Chrome Driver server', function () {
Expand All @@ -32,7 +32,7 @@
->doesntExpectOutputToContain("There's no server to stop on port [9515]")
->assertSuccessful();

Process::assertRan("ps aux | grep '[c]hromedriver --log-level=ALL --port 9515' | awk '{print $2,$14}'");
Process::assertRan("ps aux | grep '[c]hromedriver --log-level=ALL --port=9515' | awk '{print $2,$13}'");
Process::assertRan('kill -9 10101');
});
Expand All @@ -49,11 +49,11 @@
->doesntExpectOutputToContain("There's no server to restart on port [9515]")
->assertSuccessful();

Process::assertRan("ps aux | grep '[c]hromedriver --log-level=ALL --port 9515' | awk '{print $2,$14}'");
Process::assertRan("ps aux | grep '[c]hromedriver --log-level=ALL --port=9515' | awk '{print $2,$13}'");
Process::assertRan('kill -9 10101');
Process::assertRan('./chromedriver --log-level=ALL --port 9515 &');
Process::assertRan('./chromedriver --log-level=ALL --port=9515 &');
});
test('status of Chrome Driver server', function () {
Expand Down Expand Up @@ -115,7 +115,7 @@
artisan('manage:driver', ['action' => 'start', '-p' => [9515, 9516, 9517, 9518]])
->assertSuccessful();

Process::assertRanTimes(fn (PendingProcess $process) => Str::match('/^\.\/chromedriver --log-level=ALL --port \d+ &$/', $process->command), 4);
Process::assertRanTimes(fn (PendingProcess $process) => Str::match('/^\.\/chromedriver --log-level=ALL --port=\d+ &$/', $process->command), 4);
});

it('stop all the available Chrome Driver servers', function () {
Expand Down

0 comments on commit c19c958

Please sign in to comment.