Skip to content

Commit

Permalink
List all process
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <vitor@php.rio>
  • Loading branch information
vitormattos committed May 29, 2023
1 parent b7f5e3b commit 1ab25ca
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ jobs:
run: composer install

- name: Run behat
run: vendor/bin/behat
run: |
export BEHAT_RUN_AS=$(ls -ld behat.yml | awk '{print $3}')
export BEHAT_VERBOSE="$RUNNER_DEBUG"
env
vendor/bin/behat
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ default:

| config | default | Environment | Description |
| ------- | ------------- | -------------- | -------------------------------------------------- |
| verbose | false | none | Enables/disables verbose mode |
| verbose | false | BEHAT_VERBOSE | Enables/disables verbose mode |
| rootDir | /var/www/html | BEHAT_HOST | Specifies http root dir |
| host | localhost | BEHAT_ROOT_DIR | Host domain or IP |
| runAs | | BEHAT_RUN_AS | The username to be used to run the built-in server |
Expand Down
8 changes: 6 additions & 2 deletions src/RunServerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ public function start(): void
}

if (!$this->isRunning()) {
throw new ServerException('Failed to start server. Is something already running on port ' . self::$port . '?');
throw new ServerException(
'Failed to start server. Is something already running on port ' . self::$port . "?\n" .
'Full command: ' . $fullCmd
);
}

register_shutdown_function(function () {
Expand All @@ -136,6 +139,7 @@ public function isRunning(): bool
}

exec(sprintf('ps %d', $this->pid), $result);
var_dump($result);

return count($result) > 1;
}
Expand All @@ -162,7 +166,7 @@ public function killZombies(): void
'grep "php -S ' . self::$host . '"|' .
'grep -v grep|' .
'sed -e "s/^[[:space:]]*//"|cut -d" " -f1';
$pids = trim(exec($cmd));
$pids = trim(shell_exec($cmd));
$pids = explode("\n", $pids);
foreach ($pids as $pid) {
if ($pid) {
Expand Down
13 changes: 10 additions & 3 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,19 @@ public function configure(ArrayNodeDefinition $builder): void
/** @inheritDoc */
public function load(ContainerBuilder $container, array $config): void
{
$verbose = $this->getVerboseLevel($container, $config);
$rootDir = $this->getRootDir($config);
$host = $this->getHost($config);
$runAs = $this->getRunAs($config);
$verbose = $this->getVerboseLevel($container, $config);
if (is_numeric($verbose)) {
$output = $container->get('cli.output');
if ($output instanceof OutputInterface) {
$output->writeln('<info>Root dir: ' . $rootDir . '</info>');
$output->writeln('<info>Verbose: ' . $verbose . '</info>');
$output->writeln('<info>Host: ' . $host . '</info>');
$output->writeln('<info>RunAs: ' . $runAs . '</info>');
}
}
$host = $this->getHost($config);
$runAs = $this->getRunAs($config);
$definition = (new Definition('PhpBuiltin\RunServerListener'))
->addTag('event_dispatcher.subscriber')
->setArguments([$verbose, $rootDir, $host, $runAs])
Expand Down Expand Up @@ -150,6 +153,10 @@ private function getVerboseLevel(ContainerBuilder $container, array $config): ?i
$verbose = $input->getParameterOption('-v');
return strlen($verbose);
}
$runAs = getenv('BEHAT_VERBOSE');
if (is_numeric($runAs)) {
return (int) $runAs;
}
return $config['verbose'] ? 0 : null;
}

Expand Down
13 changes: 8 additions & 5 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.12.0@f90118cdeacd0088e7215e64c0c99ceca819e176">
<file src="src/Server.php">
<UndefinedInterfaceMethod>
<code>scalarNode</code>
</UndefinedInterfaceMethod>
<files psalm-version="5.4.0@62db5d4f6a7ae0a20f7cc5a4952d730272fc0863">
<file src="src/RunServerListener.php">
<ForbiddenCode occurrences="1">
<code>shell_exec($cmd)</code>
</ForbiddenCode>
<PossiblyNullArgument occurrences="1">
<code>shell_exec($cmd)</code>
</PossiblyNullArgument>
</file>
</files>

0 comments on commit 1ab25ca

Please sign in to comment.