12 use Symfony\Component\Console\Application;
13 use Symfony\Component\Console\Helper\QuestionHelper;
14 use Symfony\Component\Console\Input\InputOption;
15 use Symfony\Component\Console\Tester\CommandTester;
25 private $questionHelperMock;
30 private $installerFactoryMock;
39 $this->installerFactoryMock = $this->createMock(\
Magento\Setup\Model\InstallerFactory::class);
42 $this->questionHelperMock = $this->getMockBuilder(QuestionHelper::class)
64 $commandTester =
new CommandTester($this->command);
65 $installerMock = $this->createMock(\
Magento\Setup\Model\Installer::class);
66 $installerMock->expects($this->once())->method(
'installAdminUser')->with(
$data);
67 $this->installerFactoryMock->expects($this->once())->method(
'create')->willReturn($installerMock);
68 $commandTester->execute(
$options, [
'interactive' =>
false]);
69 $this->assertEquals(
'Created Magento administrator user named user' . PHP_EOL, $commandTester->getDisplay());
77 $this->questionHelperMock->expects($this->at(0))
79 ->will($this->returnValue(
'admin'));
81 $this->questionHelperMock->expects($this->at(1))
83 ->will($this->returnValue(
'Password123'));
85 $this->questionHelperMock->expects($this->at(2))
89 $this->questionHelperMock->expects($this->at(3))
91 ->will($this->returnValue(
'John'));
93 $this->questionHelperMock->expects($this->at(4))
95 ->will($this->returnValue(
'Doe'));
98 $this->command->getHelperSet()->set($this->questionHelperMock,
'question');
100 $installerMock = $this->createMock(\
Magento\Setup\Model\Installer::class);
103 'admin-user' =>
'admin',
104 'admin-password' =>
'Password123',
106 'admin-firstname' =>
'John',
107 'admin-lastname' =>
'Doe',
108 'magento-init-params' =>
null,
115 'no-interaction' =>
false,
118 $installerMock->expects($this->once())->method(
'installAdminUser')->with($expectedData);
119 $this->installerFactoryMock->expects($this->once())->method(
'create')->willReturn($installerMock);
121 $commandTester =
new CommandTester($this->command);
122 $commandTester->execute([
123 'command' => $this->command->getName(),
127 'Created Magento administrator user named admin' . PHP_EOL,
128 $commandTester->getDisplay()
140 $argsList = $this->command->getOptionsList(
$mode);
142 $this->assertEquals(
$description, $argsList[2]->getDescription());
152 'mode' => InputOption::VALUE_REQUIRED,
153 'description' =>
'(Required) Admin email',
156 'mode' => InputOption::VALUE_OPTIONAL,
157 'description' =>
'Admin email',
169 $inputMock = $this->getMockForAbstractClass(
170 \Symfony\Component\Console\Input\InputInterface::class,
177 $inputMock->expects($this->at(
$index++))->method(
'getOption')->willReturn(
$option);
179 $this->assertEquals(
$errors, $this->command->validate($inputMock));
190 [
'"First Name" is required. Enter and try again.']
194 [
'"User Name" is required. Enter and try again.',
'"Last Name" is required. Enter and try again.'],
196 [[
'John',
'Doe',
'admin',
null,
'123123q',
'123123q'], [
'Please enter a valid email.']],
198 [
'John',
'Doe',
'admin',
'test',
'123123q',
'123123q'],
199 [
"'test' is not a valid email address in the basic format local-part@hostname"]
204 'Password is required field.',
205 'Your password must be at least 7 characters.',
206 'Your password must include both numeric and alphabetic characters.' 212 'Your password must be at least 7 characters.',
213 'Your password must include both numeric and alphabetic characters.' 218 [
'Your password must include both numeric and alphabetic characters.']
getOptionListDataProvider()
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
testGetOptionsList($mode, $description)
testValidate(array $options, array $errors)