View source
<?php
namespace Drupal\Tests\apigee_edge\Unit\Commands {
use Consolidation\AnnotatedCommand\CommandData;
use Drupal\apigee_edge\CliServiceInterface;
use Drupal\apigee_edge\Commands\ApigeeEdgeCommands;
use Drupal\Tests\UnitTestCase;
use Drush\Style\DrushStyle;
use Prophecy\Argument;
use ReflectionClass;
use Symfony\Component\Console\Input\InputInterface;
class ApigeeEdgeCommandsTest extends UnitTestCase {
protected $apigeeEdgeCommands;
protected $cliService;
protected $io;
protected function setUp() {
parent::setUp();
$this->cliService = $this
->prophesize(CliServiceInterface::class);
$this->apigeeEdgeCommands = new ApigeeEdgeCommands($this->cliService
->reveal());
$apigee_edge_commands_reflection = new ReflectionClass($this->apigeeEdgeCommands);
$reflection_io_property = $apigee_edge_commands_reflection
->getProperty('io');
$reflection_io_property
->setAccessible(TRUE);
$this->io = $this
->prophesize(DrushStyle::class);
$reflection_io_property
->setValue($this->apigeeEdgeCommands, $this->io
->reveal());
$this->io
->askHidden(Argument::type('string'), Argument::any())
->willReturn('I<3APIS!');
}
public function testCreateEdgeRole() {
$drush_options = [
'password' => 'opensesame',
'base-url' => 'http://api.apigee.com/v1',
'role-name' => 'portalRole',
'force' => 'FALSE',
];
$this->apigeeEdgeCommands
->createEdgeRole('orgA', 'emailA', $drush_options);
$this->cliService
->createEdgeRoleForDrupal(Argument::type(DrushStyle::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 testValidatePasswordParam() {
$command_data_input = $this
->prophesize(InputInterface::class);
$command_data_input
->getOption('password')
->willReturn('secret');
$command_data_input
->getArgument('email')
->willReturn('email.example.com');
$command_data = $this
->prophesize(CommandData::class);
$command_data
->input()
->willReturn($command_data_input
->reveal());
$this->apigeeEdgeCommands
->validateCreateEdgeRole($command_data
->reveal());
$command_data_input
->getOption('password')
->shouldHaveBeenCalled();
$this->io
->askHidden(Argument::type('string'), Argument::any())
->shouldNotBeCalled();
$command_data_input
->setOption()
->shouldNotHaveBeenCalled();
}
public function testValidatePasswordParamEmpty() {
$command_data_input = $this
->prophesize(InputInterface::class);
$command_data_input
->getOption('password')
->willReturn(NULL);
$command_data_input
->setOption(Argument::type('string'), Argument::type('string'))
->willReturn();
$command_data_input
->getArgument('email')
->willReturn('email.example.com');
$command_data = $this
->prophesize(CommandData::class);
$command_data
->input()
->willReturn($command_data_input
->reveal());
$this->apigeeEdgeCommands
->validateCreateEdgeRole($command_data
->reveal());
$command_data_input
->getOption('password')
->shouldHaveBeenCalled();
$this->io
->askHidden(Argument::type('string'), Argument::any())
->shouldBeCalled();
$command_data_input
->setOption('password', 'I<3APIS!')
->shouldHaveBeenCalled();
}
public function testCreateEdgeEdgeRoleWithForceParam() {
$drush_options = [
'password' => 'opensesame',
'base-url' => 'http://api.apigee.com/v1',
'role-name' => 'portalRole',
'force' => TRUE,
];
$this->apigeeEdgeCommands
->createEdgeRole('orgA', 'emailA', $drush_options);
$this->cliService
->createEdgeRoleForDrupal(Argument::type(DrushStyle::class), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('string'), TRUE)
->shouldHaveBeenCalledTimes(1);
}
public function testCreateEdgeEdgeRoleWithoutForceParam() {
$drush_options = [
'password' => 'opensesame',
'base-url' => 'http://api.apigee.com/v1',
'role-name' => 'portalRole',
'force' => FALSE,
];
$this->apigeeEdgeCommands
->createEdgeRole('orgA', 'emailA', $drush_options);
$this->cliService
->createEdgeRoleForDrupal(Argument::type(DrushStyle::class), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('string'), FALSE)
->shouldHaveBeenCalledTimes(1);
}
}
}
namespace {
use Drush\Utils\StringUtils;
if (!function_exists('dt')) {
function dt(string $message, array $context = []) : string {
return StringUtils::interpolate($message, $context);
}
}
}