Skip to content

Commit

Permalink
Print additional information
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc45 committed Mar 8, 2024
1 parent ef3a695 commit 2983c90
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
Binary file modified qit
Binary file not shown.
2 changes: 0 additions & 2 deletions src/src/Commands/Environment/UpEnvironmentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ protected function execute( InputInterface $input, OutputInterface $output ): in

$env_info = $this->e2e_environment->up();

$output->writeln( '<info>Environment up.</info>' );

if ( $input->getOption( 'json' ) ) {
$output->write( json_encode( $env_info ) );
}
Expand Down
9 changes: 9 additions & 0 deletions src/src/Environment/EnvInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class EnvInfo implements \JsonSerializable {
/** @var string The domain being used. */
public $domain;

/** @var string */
public $php_version;

/** @var string */
public $wordpress_version = '';

/** @var bool */
public $redis = false;

/**
* @var array<string> Array of docker images associated with this environment.
* @example [ 'qit_php_123456', 'qit_db_123456', 'qit_nginx_123456' ]
Expand Down
53 changes: 43 additions & 10 deletions src/src/Environment/Environments/E2EEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace QIT_CLI\Environment\Environments;

use QIT_CLI\App;
use QIT_CLI\Commands\Environment\ExecEnvironmentCommand;
use QIT_CLI\Environment\EnvInfo;
use QIT_CLI\Environment\Environment;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use function QIT_CLI\is_windows;
Expand Down Expand Up @@ -100,22 +102,53 @@ protected function post_up( EnvInfo $env_info ): void {
'SITE_URL' => $env_info->site_url,
'QIT_DOCKER_REDIS' => $this->enable_object_cache ? 'yes' : 'no',
] );

$env_info->php_version = $this->php_version;
$env_info->wordpress_version = $this->wordpress_version;
$env_info->redis = $this->enable_object_cache;
}

protected function additional_output( EnvInfo $env_info ): void {
global $argv;
$io = new SymfonyStyle( App::make( InputInterface::class ), $this->output );
$io->section( 'Disposable Test Environment Created - ' . $env_info->env_id );
$io->success( 'Temporary test environment created. (' . $env_info->env_id . ')' );

$listing = [
sprintf( 'URL: %s', $env_info->site_url ),
sprintf( 'Admin URL: %s/wp-admin', $env_info->site_url ),
'Admin Credentials: admin/password',
sprintf( 'PHP Version: %s', $env_info->php_version ),
sprintf( 'WordPress Version: %s', $env_info->wordpress_version ),
sprintf( 'Redis Object Cache? %s', $env_info->redis ? 'Yes' : 'No' ),
sprintf( 'Path: %s', $env_info->temporary_env ),
];

$io->writeln( sprintf( 'URL: %s', $env_info->site_url ) );
$io->writeln( sprintf( 'Admin: %s/wp-admin', $env_info->site_url ) );
$io->writeln( sprintf( 'Path: %s', $env_info->temporary_env ) );
$io->listing( $listing );

$user_file = '/tmp/' . uniqid();
$this->docker->run_inside_docker_capture_output( $env_info, "\"wp user list --field=user_login\" > $user_file" );
$users = $this->docker->run_inside_docker_capture_output( $env_info, "cat $user_file" );
if ( $this->output->isVerbose() ) {
// Output a table of volume mappings.
$io->section( 'Additional Volume Mappings' );

if ( empty( $this->volumes ) ) {
$this->output->writeln( 'No additional volume mappings.' );
} else {
$volumes = [];

foreach ( $this->volumes as $k => $v ) {
$volumes[] = [ $v['local'], $v['in_container'] ];
}

var_dump( $users );
$table = new Table( $this->output );
$table
->setHeaders( [ 'Host Path', 'Container Path' ] )
->setRows( $volumes )
->setStyle( 'box' )
->render();
}

} else {
$io->writeln( sprintf( 'To see additional info, run with the "--verbose" flag.' ) );
}

// Try to connect to the website.
if ( ! $this->check_site( $env_info->site_url ) ) {
Expand Down Expand Up @@ -144,7 +177,7 @@ protected function additional_output( EnvInfo $env_info ): void {

protected function check_site( string $site_url ): bool {
if ( $this->output->isVerbose() ) {
$this->output->writeln( sprintf( 'Checking if %s is accessible...', $site_url ) );
$this->output->write( sprintf( 'Checking if %s is accessible...', $site_url ) );
}

$ch = curl_init( $site_url );
Expand All @@ -161,7 +194,7 @@ protected function check_site( string $site_url ): bool {
curl_close( $ch );

if ( $this->output->isVerbose() ) {
$this->output->writeln( sprintf( 'HTTP Code: %d', $http_code ) );
$this->output->write( sprintf( " HTTP Code: %d\n", $http_code ) );
}

return $http_code === 200;
Expand Down

0 comments on commit 2983c90

Please sign in to comment.