class CreateEdgeRoleCommandTest in Apigee Edge 8
Test ApigeeEdgeCommands class.
@group apigee_edge
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\apigee_edge\Unit\Command\CreateEdgeRoleCommandTest
 
 
Expanded class hierarchy of CreateEdgeRoleCommandTest
File
- tests/
src/ Unit/ Command/ CreateEdgeRoleCommandTest.php, line 38  
Namespace
Drupal\Tests\apigee_edge\Unit\CommandView source
class CreateEdgeRoleCommandTest extends UnitTestCase {
  /**
   * The system under test.
   *
   * @var \Drupal\apigee_edge\Command\CreateEdgeRoleCommand
   */
  protected $createEdgeRoleCommand;
  /**
   * The CLI Service mock.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  protected $cliService;
  /**
   * The IO mock.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  protected $io;
  /**
   * The LogMessageParser mock.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  protected $logMessageParser;
  /**
   * The LoggerChannelFactory mock.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  protected $loggerChannelFactory;
  /**
   * The InputInterface mock.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  private $input;
  /**
   * The OutputInterface mock.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  private $output;
  /**
   * OutputFormatterInterface mock.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  private $outputFormatter;
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    if (!class_exists('Drupal\\Console\\Core\\Command\\Command')) {
      $this
        ->markTestSkipped('Skipping because Drupal Console is not installed.');
    }
    parent::setUp();
    $this->cliService = $this
      ->prophesize(CliServiceInterface::class);
    $this->logMessageParser = $this
      ->prophesize(LogMessageParserInterface::class);
    $this->loggerChannelFactory = $this
      ->prophesize(LoggerChannelFactoryInterface::class);
    $this->createEdgeRoleCommand = new CreateEdgeRoleCommand($this->cliService
      ->reveal(), $this->logMessageParser
      ->reveal(), $this->loggerChannelFactory
      ->reveal());
    $this->input = $this
      ->prophesize(InputInterface::class);
    $this->output = $this
      ->prophesize(OutputInterface::class);
    $this->io = $this
      ->prophesize(DrupalStyle::class);
    $this->outputFormatter = $this
      ->prophesize(OutputFormatterInterface::class)
      ->reveal();
    $this->output
      ->getFormatter()
      ->willReturn($this->outputFormatter);
    $this->output
      ->getVerbosity()
      ->willReturn(OutputInterface::VERBOSITY_DEBUG);
  }
  /**
   * Calls to Drush command should pass through to CLI service.
   */
  public function testCreateEdgeRole() {
    $this->input
      ->getArgument(Argument::type('string'))
      ->willReturn('XXX');
    $this->input
      ->getOption(Argument::type('string'))
      ->willReturn('XXX');
    $this->createEdgeRoleCommand
      ->execute($this->input
      ->reveal(), $this->output
      ->reveal());
    $this->cliService
      ->createEdgeRoleForDrupal(Argument::type(DrupalStyle::class), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('bool'))
      ->shouldHaveBeenCalledTimes(1);
  }
  /**
   * Calls to Drush command should pass through to CLI service.
   */
  public function testCreateEdgeRoleForceParam() {
    $this->input
      ->getArgument(Argument::is('org'))
      ->willReturn('myorg');
    $this->input
      ->getArgument(Argument::is('email'))
      ->willReturn('email@example.com');
    $this->input
      ->getOption(Argument::is('password'))
      ->willReturn('secret');
    $this->input
      ->getOption(Argument::is('base-url'))
      ->willReturn('http://base-url');
    $this->input
      ->getOption(Argument::is('role-name'))
      ->willReturn('custom_drupal_role');
    $this->input
      ->getOption(Argument::is('force'))
      ->willReturn('true');
    $this->createEdgeRoleCommand
      ->execute($this->input
      ->reveal(), $this->output
      ->reveal());
    $this->cliService
      ->createEdgeRoleForDrupal(Argument::type(DrupalStyle::class), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('bool'))
      ->shouldHaveBeenCalledTimes(1);
  }
  /**
   * Test validateCreateEdgeRole function does not prompt for password.
   *
   * When password option is set, do not prompt for password.
   */
  public function testInteractWithPasswordParam() {
    $this->input
      ->getArgument(Argument::type('string'))
      ->willReturn('XXX');
    $this->input
      ->getOption('password')
      ->willReturn('secret');
    $this->input
      ->getOption(Argument::type('string'))
      ->willReturn('XXX');
    $this->input
      ->isInteractive()
      ->willReturn(FALSE);
    $this->createEdgeRoleCommand
      ->interact($this->input
      ->reveal(), $this->output
      ->reveal());
    // Interact should not change password since it was passed in.
    $this->input
      ->getOption('password')
      ->shouldHaveBeenCalled();
    $this->input
      ->setOption('password')
      ->shouldNotHaveBeenCalled();
  }
  /**
   * Test validateCreateEdgeRole prompts for password.
   *
   * When password option not set, password should be inputted by user.
   */
  public function testInteractPasswordParamEmpty() {
    $this->input
      ->getArgument(Argument::type('string'))
      ->willReturn('XXX');
    $this->input
      ->getOption('password')
      ->willReturn(NULL);
    $this->input
      ->getOption(Argument::type('string'))
      ->willReturn('XXX');
    $this->input
      ->setOption(Argument::type('string'), NULL)
      ->willReturn(NULL);
    $this->input
      ->isInteractive()
      ->willReturn(FALSE);
    $this->createEdgeRoleCommand
      ->interact($this->input
      ->reveal(), $this->output
      ->reveal());
    // Interact should not change password since it was passed in.
    $this->input
      ->getOption('password')
      ->shouldHaveBeenCalled();
    $this->input
      ->setOption('password', NULL)
      ->shouldHaveBeenCalled();
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            CreateEdgeRoleCommandTest:: | 
                  protected | property | The CLI Service mock. | |
| 
            CreateEdgeRoleCommandTest:: | 
                  protected | property | The system under test. | |
| 
            CreateEdgeRoleCommandTest:: | 
                  private | property | The InputInterface mock. | |
| 
            CreateEdgeRoleCommandTest:: | 
                  protected | property | The IO mock. | |
| 
            CreateEdgeRoleCommandTest:: | 
                  protected | property | The LoggerChannelFactory mock. | |
| 
            CreateEdgeRoleCommandTest:: | 
                  protected | property | The LogMessageParser mock. | |
| 
            CreateEdgeRoleCommandTest:: | 
                  private | property | The OutputInterface mock. | |
| 
            CreateEdgeRoleCommandTest:: | 
                  private | property | OutputFormatterInterface mock. | |
| 
            CreateEdgeRoleCommandTest:: | 
                  protected | function | 
            Overrides UnitTestCase:: | 
                  |
| 
            CreateEdgeRoleCommandTest:: | 
                  public | function | Calls to Drush command should pass through to CLI service. | |
| 
            CreateEdgeRoleCommandTest:: | 
                  public | function | Calls to Drush command should pass through to CLI service. | |
| 
            CreateEdgeRoleCommandTest:: | 
                  public | function | Test validateCreateEdgeRole prompts for password. | |
| 
            CreateEdgeRoleCommandTest:: | 
                  public | function | Test validateCreateEdgeRole function does not prompt for password. | |
| 
            PhpunitCompatibilityTrait:: | 
                  public | function | Returns a mock object for the specified class using the available method. | |
| 
            PhpunitCompatibilityTrait:: | 
                  public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
| 
            UnitTestCase:: | 
                  protected | property | The random generator. | |
| 
            UnitTestCase:: | 
                  protected | property | The app root. | 1 | 
| 
            UnitTestCase:: | 
                  protected | function | Asserts if two arrays are equal by sorting them first. | |
| 
            UnitTestCase:: | 
                  protected | function | Mocks a block with a block plugin. | 1 | 
| 
            UnitTestCase:: | 
                  protected | function | Returns a stub class resolver. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub config factory that behaves according to the passed array. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub config storage that returns the supplied configuration. | |
| 
            UnitTestCase:: | 
                  protected | function | Sets up a container with a cache tags invalidator. | |
| 
            UnitTestCase:: | 
                  protected | function | Gets the random generator for the utility methods. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub translation manager that just returns the passed string. | |
| 
            UnitTestCase:: | 
                  public | function | Generates a unique random string containing letters and numbers. |