You are here

class CreateEdgeRoleCommandTest in Apigee Edge 8

Test ApigeeEdgeCommands class.

@group apigee_edge

Hierarchy

Expanded class hierarchy of CreateEdgeRoleCommandTest

File

tests/src/Unit/Command/CreateEdgeRoleCommandTest.php, line 38

Namespace

Drupal\Tests\apigee_edge\Unit\Command
View 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

Namesort descending Modifiers Type Description Overrides
CreateEdgeRoleCommandTest::$cliService protected property The CLI Service mock.
CreateEdgeRoleCommandTest::$createEdgeRoleCommand protected property The system under test.
CreateEdgeRoleCommandTest::$input private property The InputInterface mock.
CreateEdgeRoleCommandTest::$io protected property The IO mock.
CreateEdgeRoleCommandTest::$loggerChannelFactory protected property The LoggerChannelFactory mock.
CreateEdgeRoleCommandTest::$logMessageParser protected property The LogMessageParser mock.
CreateEdgeRoleCommandTest::$output private property The OutputInterface mock.
CreateEdgeRoleCommandTest::$outputFormatter private property OutputFormatterInterface mock.
CreateEdgeRoleCommandTest::setUp protected function Overrides UnitTestCase::setUp
CreateEdgeRoleCommandTest::testCreateEdgeRole public function Calls to Drush command should pass through to CLI service.
CreateEdgeRoleCommandTest::testCreateEdgeRoleForceParam public function Calls to Drush command should pass through to CLI service.
CreateEdgeRoleCommandTest::testInteractPasswordParamEmpty public function Test validateCreateEdgeRole prompts for password.
CreateEdgeRoleCommandTest::testInteractWithPasswordParam public function Test validateCreateEdgeRole function does not prompt for password.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.