Skip to content
This repository was archived by the owner on Nov 6, 2021. It is now read-only.

Commit 560d38b

Browse files
author
Florian Horn
committed
Added --force flag to fuzzyfyr command to allow execution in production mode.
1 parent 041e0fb commit 560d38b

File tree

5 files changed

+118
-4
lines changed

5 files changed

+118
-4
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file, in reverse
55
## 1.6.0
66

77
- Extended customer fuzzyfyier to alter customer password.
8+
- Added --force flag to fuzzyfyr command to allow execution in production mode.
89

910
## 1.5.0
1011

Console/Command/FuzzyfyrCommand.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class FuzzyfyrCommand extends Command
3636
* Flags
3737
*/
3838
const FLAG_ONLY_EMPTY = 'only-empty';
39+
const FLAG_FORCE = 'force';
3940
const FLAG_CATEGORIES = 'categories';
4041
const FLAG_CMS_BLOCKS = 'cms-blocks';
4142
const FLAG_CMS_PAGES = 'cms-pages';
@@ -104,6 +105,12 @@ protected function configure()
104105
InputOption::VALUE_NONE,
105106
'Use dummy content only if the original data is equal to empty'
106107
),
108+
new InputOption(
109+
self::FLAG_FORCE,
110+
null,
111+
InputOption::VALUE_NONE,
112+
'Allow execution in production mode (not recommended!)'
113+
),
107114
new InputOption(
108115
self::FLAG_CATEGORIES,
109116
null,
@@ -192,13 +199,21 @@ protected function configure()
192199
*/
193200
protected function execute(InputInterface $input, OutputInterface $output)
194201
{
195-
// Check on environment
202+
$forcedUsage = !!$input->getOption(self::FLAG_FORCE);
203+
204+
// Check on force option
196205
$output->writeln(sprintf('You are running in %s mode', $this->state->getMode()));
197-
if (\Magento\Framework\App\State::MODE_PRODUCTION === $this->state->getMode()) {
206+
if ($forcedUsage) {
207+
$output->writeln(sprintf('You are running in forced mode!'));
208+
$output->writeln('You really should not use this command in a production environment.');
209+
}
210+
211+
// Check on environment
212+
if (!$forcedUsage && \Magento\Framework\App\State::MODE_PRODUCTION === $this->state->getMode()) {
198213
// prevent from being executed in production mode
199-
// this may mess up to much if it would run without any safety checks
214+
// this may mess up too much if it would run without any safety checks
200215
$output->writeln('You really should not use this command in production mode.');
201-
$output->writeln('If it is really what you want, switch to default or developer mode first.');
216+
$output->writeln('If it is really what you want, switch to default or developer mode first. You also can use --force.');
202217
return self::ERROR_PRODUCTION_MODE;
203218
}
204219

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ You may want to switch to *default* or *developer* mode to run the command:
6868
Option | Description
6969
--- | ---
7070
--only-empty | Use dummy content only if the original data is equal to empty
71+
--force | Allow execution in production mode (not recommended!)
7172
--categories | Apply dummy content to categories (content, meta description)
7273
--cms-blocks | Apply dummy content to CMS Blocks (content)
7374
--cms-pages | Apply dummy content to CMS Pages (content, meta description)

Test/Unit/Console/Command/FuzzyfyrCommandTest.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class FuzzyfyrCommandTest extends AbstractTest
3232
public function runSuccessfully()
3333
{
3434
$state = $this->getState();
35+
$state->expects($this->any())
36+
->method('getMode')
37+
->willReturn(\Magento\Framework\App\State::MODE_DEFAULT);
3538

3639
$configuration = $this->getMockBuilder(Configuration::class)->getMock();
3740
$configurationFactory = $this->getConfigurationFactory();
@@ -58,6 +61,100 @@ public function runSuccessfully()
5861
$this->assertEquals(FuzzyfyrCommand::SUCCESS, $command->run($input, $output));
5962
}
6063

64+
/**
65+
* @test
66+
*/
67+
public function runSuccessfullyInProductionModeWithForceOption()
68+
{
69+
$state = $this->getState();
70+
$state->expects($this->any())
71+
->method('getMode')
72+
->willReturn(\Magento\Framework\App\State::MODE_PRODUCTION);
73+
74+
$configuration = $this->getMockBuilder(Configuration::class)->getMock();
75+
$configurationFactory = $this->getConfigurationFactory();
76+
$configurationFactory->expects($this->once())
77+
->method('create')
78+
->willReturn($configuration);
79+
80+
$eventManager = $this->getEventManager();
81+
$eventManager->expects($this->once())
82+
->method('dispatch')
83+
->with(FuzzyfyrCommand::EVENT_NAME, [
84+
'configuration' => $configuration
85+
]);
86+
87+
$command = new FuzzyfyrCommand(
88+
$state,
89+
$eventManager,
90+
$configurationFactory
91+
);
92+
93+
$input = $this->getInput();
94+
$i = 4;
95+
$input->expects($this->at($i++))
96+
->method('getOption')
97+
->with(FuzzyfyrCommand::FLAG_FORCE)
98+
->willReturn(true);
99+
$input->expects($this->at($i++))
100+
->method('getOption')
101+
->with(FuzzyfyrCommand::FLAG_ONLY_EMPTY)
102+
->willReturn(true);
103+
$input->expects($this->at($i++))
104+
->method('getOption')
105+
->with(FuzzyfyrCommand::FLAG_CATEGORIES)
106+
->willReturn(false);
107+
$input->expects($this->at($i++))
108+
->method('getOption')
109+
->with(FuzzyfyrCommand::FLAG_CMS_BLOCKS)
110+
->willReturn(false);
111+
$input->expects($this->at($i++))
112+
->method('getOption')
113+
->with(FuzzyfyrCommand::FLAG_CMS_PAGES)
114+
->willReturn(false);
115+
$input->expects($this->at($i++))
116+
->method('getOption')
117+
->with(FuzzyfyrCommand::FLAG_CUSTOMERS)
118+
->willReturn(false);
119+
$input->expects($this->at($i++))
120+
->method('getOption')
121+
->with(FuzzyfyrCommand::FLAG_PRODUCTS)
122+
->willReturn(false);
123+
$input->expects($this->at($i++))
124+
->method('getOption')
125+
->with(FuzzyfyrCommand::FLAG_USERS)
126+
->willReturn(false);
127+
128+
$input->expects($this->at($i++))
129+
->method('getOption')
130+
->with(FuzzyfyrCommand::OPTION_DUMMY_CONTENT_TEXT)
131+
->willReturn(FuzzyfyrCommand::DEFAULT_DUMMY_CONTENT_TEXT);
132+
$input->expects($this->at($i++))
133+
->method('getOption')
134+
->with(FuzzyfyrCommand::OPTION_DUMMY_CONTENT_PASSWORD)
135+
->willReturn(FuzzyfyrCommand::DEFAULT_DUMMY_CONTENT_PASSWORD);
136+
$input->expects($this->at($i++))
137+
->method('getOption')
138+
->with(FuzzyfyrCommand::OPTION_DUMMY_CONTENT_EMAIL)
139+
->willReturn(FuzzyfyrCommand::DEFAULT_DUMMY_CONTENT_EMAIL);
140+
$input->expects($this->at($i++))
141+
->method('getOption')
142+
->with(FuzzyfyrCommand::OPTION_DUMMY_CONTENT_URL)
143+
->willReturn(FuzzyfyrCommand::DEFAULT_DUMMY_CONTENT_URL);
144+
$input->expects($this->at($i++))
145+
->method('getOption')
146+
->with(FuzzyfyrCommand::OPTION_DUMMY_CONTENT_PHONE)
147+
->willReturn(FuzzyfyrCommand::DEFAULT_DUMMY_CONTENT_PHONE);
148+
$input->expects($this->at($i++))
149+
->method('getOption')
150+
->with(FuzzyfyrCommand::OPTION_DUMMY_CONTENT_IMAGE_PATH)
151+
->willReturn(FuzzyfyrCommand::DEFAULT_DUMMY_CONTENT_IMAGE_PATH);
152+
153+
$output = $this->getOutput();
154+
155+
$this->assertEquals(FuzzyfyrCommand::SUCCESS, $command->run($input, $output));
156+
}
157+
61158
/**
62159
* @test
63160
*/

docs/UserGuide.pdf

296 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)