-
Notifications
You must be signed in to change notification settings - Fork 132
MQE-1257: MFTF Doctor command #500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7ac812b
MQE-1257: MFTF Troubleshoot command
jilu1 7bdcafd
MQE-1257: MFTF Troubleshoot command
jilu1 4fdf441
MQE-1257: MFTF Troubleshoot command
jilu1 f1299b1
MQE-1257: MFTF doctor command
jilu1 25c5706
MQE-1257: MFTF doctor command
jilu1 4908777
MQE-1257: MFTF doctor command
jilu1 bea39a9
MQE-1257: MFTF doctor command
jilu1 485c49b
Merge remote-tracking branch 'origin/develop' into MQE-1257
jilu1 de359cb
MQE-1257: MFTF doctor command
jilu1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
src/Magento/FunctionalTestingFramework/Console/TroubleShootCommand.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types = 1); | ||
|
||
namespace Magento\FunctionalTestingFramework\Console; | ||
|
||
use Codeception\Configuration; | ||
use Symfony\Component\EventDispatcher\EventDispatcher; | ||
use Codeception\SuiteManager; | ||
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig; | ||
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Magento\FunctionalTestingFramework\Util\ModuleResolver; | ||
|
||
class TroubleShootCommand extends Command | ||
{ | ||
const CODECEPTION_AUTOLOAD_FILE = PROJECT_ROOT . '/vendor/codeception/codeception/autoload.php'; | ||
const MFTF_CODECEPTION_CONFIG_FILE = ENV_FILE_PATH . 'codeception.yml'; | ||
const SUITE = 'functional'; | ||
const REQUIRED_PHP_EXTS = ['CURL', 'mbstring', 'bcmath', 'zip', 'dom', 'gd', 'intl']; | ||
|
||
/** | ||
* Command Output | ||
* | ||
* @var OutputInterface | ||
*/ | ||
private $output; | ||
|
||
/** | ||
* Configures the current command. | ||
* | ||
* @return void | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setName('troubleshoot') | ||
->setDescription( | ||
'This command checks environment readiness for generating and running MFTF tests.' | ||
); | ||
} | ||
|
||
/** | ||
* Executes the current command. | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return integer | ||
* @throws TestFrameworkException | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$cmdStatus = true; | ||
|
||
// Config application | ||
$verbose = $output->isVerbose(); | ||
$this->output = $output; | ||
MftfApplicationConfig::create( | ||
false, | ||
MftfApplicationConfig::DIAGNOSTIC_PHASE, | ||
$verbose, | ||
MftfApplicationConfig::LEVEL_DEVELOPER, | ||
false | ||
); | ||
|
||
// Check required PHP extensions | ||
foreach (self::REQUIRED_PHP_EXTS as $ext) { | ||
$status = $this->checkPhpExtIsAvailable($ext); | ||
$cmdStatus = $cmdStatus && !$status ? false : $cmdStatus; | ||
} | ||
|
||
// Check authentication to Magento Admin | ||
$status = $this->checkAuthenticationToMagentoAdmin(); | ||
$cmdStatus = $cmdStatus && !$status ? false : $cmdStatus; | ||
|
||
// Check connectivity and authentication to Magento Admin | ||
$status = $this->checkConnectivityToSeleniumServer(); | ||
$cmdStatus = $cmdStatus && !$status ? false : $cmdStatus; | ||
|
||
if ($cmdStatus) { | ||
return 0; | ||
} else { | ||
return 1; | ||
} | ||
} | ||
|
||
/** | ||
* Check php extention is installed and available | ||
* | ||
* @param string $ext | ||
* @return boolean | ||
*/ | ||
private function checkPhpExtIsAvailable($ext) | ||
{ | ||
$result = false; | ||
$this->output->writeln("\nChecking PHP extenstion \"{$ext}\" ..."); | ||
if (extension_loaded(strtolower($ext))) { | ||
$this->output->writeln('Successful'); | ||
$result = true; | ||
} else { | ||
$this->output->writeln( | ||
"MFTF requires \"{$ext}\" extension installed to make tests run\n" | ||
. "Please make sure that the PHP you run has \"{$ext}\" installed and enabled." | ||
); | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* Check authentication to Magento Admin | ||
* | ||
* @return boolean | ||
*/ | ||
private function checkAuthenticationToMagentoAdmin() | ||
{ | ||
$result = false; | ||
try { | ||
$this->output->writeln("\nChecking authentication to Magento Admin ..."); | ||
ModuleResolver::getInstance()->getAdminToken(); | ||
$this->output->writeln('Successful'); | ||
$result = true; | ||
} catch (TestFrameworkException $e) { | ||
$this->output->writeln($e->getMessage()); | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* Check Connectivity to Selenium Server | ||
* | ||
* @return boolean | ||
*/ | ||
private function checkConnectivityToSeleniumServer() | ||
{ | ||
$result = false; | ||
|
||
// Check connectivity to Selenium through Codeception | ||
$this->output->writeln("\nChecking connectivity to Selenium Server ..."); | ||
require_once realpath(self::CODECEPTION_AUTOLOAD_FILE); | ||
|
||
$config = Configuration::config(realpath(self::MFTF_CODECEPTION_CONFIG_FILE)); | ||
$settings = Configuration::suiteSettings(self::SUITE, $config); | ||
$dispatcher = new EventDispatcher(); | ||
$suiteManager = new SuiteManager($dispatcher, self::SUITE, $settings); | ||
try { | ||
$suiteManager->initialize(); | ||
$this->output->writeln('Successful'); | ||
$result = true; | ||
} catch (TestFrameworkException $e) { | ||
$this->output->writeln($e->getMessage()); | ||
} | ||
return $result; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.