Skip to content
This repository has been archived by the owner on Dec 11, 2021. It is now read-only.

Commit

Permalink
Fix some issues with Infection
Browse files Browse the repository at this point in the history
  • Loading branch information
shochdoerfer committed Feb 19, 2021
1 parent 99d1bba commit 6fb3cea
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 3 deletions.
Expand Up @@ -95,7 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// check environment
$force = (bool) $input->getOption(self::OPTION_FORCE);

if (!($force || State::MODE_DEVELOPER === $this->getState()->getMode())) {
if (!($force === true || State::MODE_DEVELOPER === $this->getState()->getMode())) {
throw new LocalizedException(__('This command can only be run in developer mode!'));
}

Expand Down
Expand Up @@ -19,7 +19,6 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\Indexer\Model\Indexer;
use N98\Magento\Application;
use PHPUnit\Framework\Constraint\Callback;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -117,6 +116,40 @@ public function commandCannotBeRunInProductionMode(): void
$command->run($this->input, $this->output);
}

/**
* @test
*/
public function commandCanBeRunInProductionModeWithForceMode(): void
{
$this->input->expects(self::any())
->method('getOption')
->willReturnMap([
[PasswordNormalizer::OPTION_FORCE, true],
[PasswordNormalizer::OPTION_PASSWORD, 'random-password-to-set'],
[PasswordNormalizer::OPTION_EMAIL_MASK, 'customer_(ID)@example.com'],
[PasswordNormalizer::OPTION_EXCLUDE_EMAILS, ''],
]);

$this->state->expects(self::any())
->method('getMode')
->willReturn(\Magento\Framework\App\State::MODE_PRODUCTION);

$this->connection->expects(self::any())
->method('query')
->willReturn($this->statement);

$this->encryptor->expects(self::any())
->method('getHash')
->willReturn('abcdef');

/** @var PasswordNormalizer $command */
$command = $this->getPasswordNormalizerMock();
$command->setApplication($this->application);
$return = $command->run($this->input, $this->output);

self::assertSame(0, $return);
}

/**
* @test
*/
Expand All @@ -135,6 +168,75 @@ public function commandCannotBeRunInDefaultMode(): void
$command->run($this->input, $this->output);
}

/**
* @test
*/
public function commandCanBeRunInDefaultModeWithForceMode(): void
{
$this->input->expects(self::any())
->method('getOption')
->willReturnMap([
[PasswordNormalizer::OPTION_FORCE, true],
[PasswordNormalizer::OPTION_PASSWORD, 'random-password-to-set'],
[PasswordNormalizer::OPTION_EMAIL_MASK, 'customer_(ID)@example.com'],
[PasswordNormalizer::OPTION_EXCLUDE_EMAILS, ''],
]);

$this->state->expects(self::any())
->method('getMode')
->willReturn(\Magento\Framework\App\State::MODE_DEFAULT);

$this->connection->expects(self::any())
->method('query')
->willReturn($this->statement);

$this->encryptor->expects(self::any())
->method('getHash')
->willReturn('abcdef');

/** @var PasswordNormalizer $command */
$command = $this->getPasswordNormalizerMock();
$command->setApplication($this->application);
$return = $command->run($this->input, $this->output);

self::assertSame(0, $return);
}


/**
* @test
*/
public function nonBoolForceModeWillBeCastedToBool(): void
{
$this->input->expects(self::any())
->method('getOption')
->willReturnMap([
[PasswordNormalizer::OPTION_FORCE, "yes"],
[PasswordNormalizer::OPTION_PASSWORD, 'random-password-to-set'],
[PasswordNormalizer::OPTION_EMAIL_MASK, 'customer_(ID)@example.com'],
[PasswordNormalizer::OPTION_EXCLUDE_EMAILS, ''],
]);

$this->state->expects(self::any())
->method('getMode')
->willReturn(\Magento\Framework\App\State::MODE_PRODUCTION);

$this->connection->expects(self::any())
->method('query')
->willReturn($this->statement);

$this->encryptor->expects(self::any())
->method('getHash')
->willReturn('abcdef');

/** @var PasswordNormalizer $command */
$command = $this->getPasswordNormalizerMock();
$command->setApplication($this->application);
$return = $command->run($this->input, $this->output);

self::assertSame(0, $return);
}

/**
* @test
*/
Expand Down Expand Up @@ -216,7 +318,9 @@ public function passingRequiredPasswordParameterSucceeds(): void
/** @var PasswordNormalizer $command */
$command = $this->getPasswordNormalizerMock();
$command->setApplication($this->application);
$command->run($this->input, $this->output);
$return = $command->run($this->input, $this->output);

self::assertSame(0, $return);
}

/**
Expand Down

0 comments on commit 6fb3cea

Please sign in to comment.