Skip to content

Commit

Permalink
Add "test-tags" command
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc45 committed Apr 9, 2024
1 parent a522fe1 commit 4a4f483
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/src/Commands/TestTagsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace QIT_CLI\Commands;

use QIT_CLI\RequestBuilder;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use function QIT_CLI\get_manager_url;

class TestTagsCommand extends Command {
protected static $defaultName = 'test-tags'; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase

protected function configure() {
$this
->setDescription( 'List the Test Tags you have access to test.' );
}

protected function execute( InputInterface $input, OutputInterface $output ): int {
try {
$json = ( new RequestBuilder( get_manager_url() . "/wp-json/cd/v1/get_extensions" ) )
->with_method( 'POST' )
->with_post_body( [
'list_tests' => true,
] )
->request();
} catch ( \Exception $e ) {
$output->writeln( "<error>{$e->getMessage()}</error>" );

return Command::FAILURE;
}

$test_tags = json_decode( $json, true );

if ( empty( $test_tags ) ) {
$output->writeln( '<error>No test tags found.</error>' );

return Command::FAILURE;
}

$table = new Table( $output );
$table->setHeaders(['Slug', 'E2E Tests', 'Type']);

foreach ($test_tags as $tag => $data) {
$e2eTests = implode(', ', $data['tests']['e2e'] ?? []);
$table->addRow([$data['slug'], $e2eTests, $data['type']]);
}

$table->render();

return Command::SUCCESS;
}
}
2 changes: 2 additions & 0 deletions src/src/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use QIT_CLI\Commands\Partner\SwitchPartner;
use QIT_CLI\Commands\SetProxyCommand;
use QIT_CLI\Commands\SyncCommand;
use QIT_CLI\Commands\TestTagsCommand;
use QIT_CLI\Commands\WooExtensionsCommand;
use QIT_CLI\Config;
use QIT_CLI\Diagnosis;
Expand Down Expand Up @@ -233,6 +234,7 @@ public function filter( $in, $out, &$consumed, $closing ): int {

// List the Woo Extensions the user can run tests against.
$application->add( $container->make( WooExtensionsCommand::class ) );
$application->add( $container->make( TestTagsCommand::class ) );

$application->add( $container->make( UploadCustomTestCommand::class ) );
$application->add( $container->make( ShowReportCommand::class ) );
Expand Down

0 comments on commit 4a4f483

Please sign in to comment.