From 9227ae03a20c3f5cb68bedbdfdd169c6bd183009 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Mon, 29 May 2023 12:44:25 -0300 Subject: [PATCH] List all process Signed-off-by: Vitor Mattos --- .github/workflows/behat.yml | 6 +++++- README.md | 2 +- src/RunServerListener.php | 7 +++++-- src/Server.php | 13 ++++++++++--- tests/psalm-baseline.xml | 13 ++++++++----- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index 0d608b2..beaf1c4 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -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 diff --git a/README.md b/README.md index 0589f83..715bceb 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/src/RunServerListener.php b/src/RunServerListener.php index 2972e2b..d4c303b 100644 --- a/src/RunServerListener.php +++ b/src/RunServerListener.php @@ -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 () { @@ -162,7 +165,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) { diff --git a/src/Server.php b/src/Server.php index be19fa1..f8d81b1 100644 --- a/src/Server.php +++ b/src/Server.php @@ -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('Root dir: ' . $rootDir . ''); + $output->writeln('Verbose: ' . $verbose . ''); + $output->writeln('Host: ' . $host . ''); + $output->writeln('RunAs: ' . $runAs . ''); } } - $host = $this->getHost($config); - $runAs = $this->getRunAs($config); $definition = (new Definition('PhpBuiltin\RunServerListener')) ->addTag('event_dispatcher.subscriber') ->setArguments([$verbose, $rootDir, $host, $runAs]) @@ -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; } diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 4e198d3..44c9394 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -1,8 +1,11 @@ - - - - scalarNode - + + + + shell_exec($cmd) + + + shell_exec($cmd) +