class ApigeeEdgeCommandsTest 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\Commands\ApigeeEdgeCommandsTest
Expanded class hierarchy of ApigeeEdgeCommandsTest
File
- tests/
src/ Unit/ Commands/ ApigeeEdgeCommandsTest.php, line 36
Namespace
Drupal\Tests\apigee_edge\Unit\CommandsView source
class ApigeeEdgeCommandsTest extends UnitTestCase {
/**
* The system under test.
*
* @var \Drupal\apigee_edge\Commands\ApigeeEdgeCommands
*/
protected $apigeeEdgeCommands;
/**
* The CLI Service mock.
*
* @var \Prophecy\Prophecy\ObjectProphecy
*/
protected $cliService;
/**
* The DrushStyle mock.
*
* @var \Prophecy\Prophecy\ObjectProphecy
*/
protected $io;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->cliService = $this
->prophesize(CliServiceInterface::class);
$this->apigeeEdgeCommands = new ApigeeEdgeCommands($this->cliService
->reveal());
// Set io in DrushCommands to a mock.
$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!');
}
/**
* Calls to Drush command should pass through to CLI service.
*/
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);
}
/**
* Test validateCreateEdgeRole function does not prompt for password.
*
* When password option is set, do not prompt for password.
*/
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());
// Make sure password was not prompted to user.
$command_data_input
->getOption('password')
->shouldHaveBeenCalled();
$this->io
->askHidden(Argument::type('string'), Argument::any())
->shouldNotBeCalled();
$command_data_input
->setOption()
->shouldNotHaveBeenCalled();
}
/**
* Test validateCreateEdgeRole prompts for password.
*
* When password option not set, password should be inputted by user.
*/
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());
// Make sure password not requested.
$command_data_input
->getOption('password')
->shouldHaveBeenCalled();
$this->io
->askHidden(Argument::type('string'), Argument::any())
->shouldBeCalled();
$command_data_input
->setOption('password', 'I<3APIS!')
->shouldHaveBeenCalled();
}
/**
* Test calling with force function when role already exists.
*/
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);
}
/**
* Test calling when role exists but force flag not given, should error.
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ApigeeEdgeCommandsTest:: |
protected | property | The system under test. | |
ApigeeEdgeCommandsTest:: |
protected | property | The CLI Service mock. | |
ApigeeEdgeCommandsTest:: |
protected | property | The DrushStyle mock. | |
ApigeeEdgeCommandsTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ApigeeEdgeCommandsTest:: |
public | function | Test calling with force function when role already exists. | |
ApigeeEdgeCommandsTest:: |
public | function | Test calling when role exists but force flag not given, should error. | |
ApigeeEdgeCommandsTest:: |
public | function | Calls to Drush command should pass through to CLI service. | |
ApigeeEdgeCommandsTest:: |
public | function | Test validateCreateEdgeRole function does not prompt for password. | |
ApigeeEdgeCommandsTest:: |
public | function | Test validateCreateEdgeRole prompts 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. |