CreateEdgeRoleCommandTest.php in Apigee Edge 8
File
tests/src/Unit/Command/CreateEdgeRoleCommandTest.php
View source
<?php
namespace Drupal\Tests\apigee_edge\Unit\Command {
use Drupal\apigee_edge\CliServiceInterface;
use Drupal\apigee_edge\Command\CreateEdgeRoleCommand;
use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Logger\LogMessageParserInterface;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CreateEdgeRoleCommandTest extends UnitTestCase {
protected $createEdgeRoleCommand;
protected $cliService;
protected $io;
protected $logMessageParser;
protected $loggerChannelFactory;
private $input;
private $output;
private $outputFormatter;
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);
}
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);
}
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);
}
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());
$this->input
->getOption('password')
->shouldHaveBeenCalled();
$this->input
->setOption('password')
->shouldNotHaveBeenCalled();
}
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());
$this->input
->getOption('password')
->shouldHaveBeenCalled();
$this->input
->setOption('password', NULL)
->shouldHaveBeenCalled();
}
}
}
namespace {
use Drush\Utils\StringUtils;
if (!function_exists('t')) {
function t(string $message, array $context = []) : string {
return StringUtils::interpolate($message, $context);
}
}
}