ai_agents_test-1.0.0-alpha1/src/Drush/Commands/AiAgentImportTestCommands.php

src/Drush/Commands/AiAgentImportTestCommands.php
<?php

declare(strict_types=1);

namespace Drupal\ai_agents_test\Drush\Commands;

use Drupal\ai_agents_test\Service\TestSyncService;
use Drush\Attributes as CLI;
use Drush\Boot\DrupalBootLevels;
use Drush\Commands\DrushCommands;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides Drush commands that imports stuff.
 */
class AiAgentImportTestCommands extends DrushCommands {

  /**
   * The constructor.
   *
   * @param \Drupal\ai_agents_test\Service\TestSyncService $testSync
   *   The test synchronization service.
   */
  public function __construct(
    protected TestSyncService $testSync,
  ) {
    parent::__construct();
  }

  /**
   * Return an instance of these Drush commands.
   *
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   *   The container.
   *
   * @return \Drupal\ai\Drush\Commands\AiAgentImportTestCommands
   *   The instance of Drush commands.
   */
  public static function create(ContainerInterface $container): AiAgentImportTestCommands {
    return new AiAgentImportTestCommands(
      $container->get('ai_agents_test.test_sync_service'),
    );
  }

  /**
   * Run one or multiple tests.
   */
  #[CLI\Command(name: 'agents:test-agents-group-import', aliases: ['agetig'])]
  #[CLI\Argument(name: 'file_url', description: 'The file URL to import the test group from.')]
  #[CLI\Bootstrap(level: DrupalBootLevels::FULL)]
  public function runTests(
    string $file_url,
  ) {
    $this->logger()->info(dt('Importing test group from file: @file_url', ['@file_url' => $file_url]));

    // Check if the file exists.
    if (!file_exists($file_url)) {
      $this->logger()->error(dt('The provided file does not exist: @file_url', ['@file_url' => $file_url]));
      return;
    }

    // Import the test group.
    try {
      $test_group = $this->testSync->importTestGroup($file_url);
      $this->logger()->success(dt('Test group imported successfully: @group', ['@group' => $test_group->label()]));
    }
    catch (\Exception $e) {
      $this->logger()->error(dt('Failed to import test group: @message', ['@message' => $e->getMessage()]));
    }
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc