Skip to content

Commit f0e4816

Browse files
committed
MTA-3996: Create util for troubleshooting analysis with functional test execution
1 parent c22469e commit f0e4816

File tree

15 files changed

+1066
-17
lines changed

15 files changed

+1066
-17
lines changed

dev/tests/functional/etc/di.xml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<preference for="Magento\Mtf\Console\CommandListInterface" type="Magento\Mtf\Console\CommandList" />
910
<preference for="Magento\Mtf\Util\Command\File\ExportInterface" type="\Magento\Mtf\Util\Command\File\Export" />
1011
<preference for="Magento\Mtf\Util\Command\File\Export\ReaderInterface" type="\Magento\Mtf\Util\Command\File\Export\Reader" />
1112

@@ -19,6 +20,84 @@
1920

2021
<type name="Magento\Mtf\Util\Protocol\CurlTransport\WebapiDecorator" shared="true" />
2122

23+
<type name="Magento\Mtf\Console\CommandList">
24+
<arguments>
25+
<argument name="commands" xsi:type="array">
26+
<item name="check-magento-storefront" xsi:type="object">Magento\Mtf\Troubleshooting\StorefrontAnalyzer</item>
27+
<item name="check-phpunit-config-file" xsi:type="object">Magento\Mtf\Troubleshooting\PhpUnitAnalyzer</item>
28+
<item name="check-magento-admin" xsi:type="object">Magento\Mtf\Troubleshooting\AdminAnalyzer</item>
29+
<item name="apply-magento-configuration" xsi:type="object">Magento\Mtf\Troubleshooting\Configuration</item>
30+
<item name="check-selenium-session-connection" xsi:type="object">Magento\Mtf\Troubleshooting\SeleniumSessionAnalyzer</item>
31+
<item name="generate-static-classes" xsi:type="object">Magento\Mtf\Troubleshooting\StaticClassesGenerator</item>
32+
<item name="check-config-valid" xsi:type="object">Magento\Mtf\Troubleshooting\ConfigAnalyzer</item>
33+
<item name="check-htaccess" xsi:type="object">Magento\Mtf\Troubleshooting\HtaccessAnalyzer</item>
34+
<item name="check-all" xsi:type="object">Magento\Mtf\Troubleshooting\GlobalAnalyzer</item>
35+
</argument>
36+
</arguments>
37+
</type>
38+
39+
<type name="Magento\Mtf\Troubleshooting\GlobalAnalyzer">
40+
<arguments>
41+
<argument name="commandList" xsi:type="array">
42+
<item name="0" xsi:type="object">Magento\Mtf\Troubleshooting\PhpUnitAnalyzer</item>
43+
<item name="1" xsi:type="object">Magento\Mtf\Troubleshooting\StorefrontAnalyzer</item>
44+
<item name="2" xsi:type="object">Magento\Mtf\Troubleshooting\ConfigAnalyzer</item>
45+
<item name="3" xsi:type="object">Magento\Mtf\Troubleshooting\AdminAnalyzer</item>
46+
<item name="4" xsi:type="object">Magento\Mtf\Troubleshooting\Configuration</item>
47+
<item name="5" xsi:type="object">Magento\Mtf\Troubleshooting\HtaccessAnalyzer</item>
48+
<item name="6" xsi:type="object">Magento\Mtf\Troubleshooting\StaticClassesGenerator</item>
49+
<item name="7" xsi:type="object">Magento\Mtf\Troubleshooting\SeleniumSessionAnalyzer</item>
50+
</argument>
51+
</arguments>
52+
</type>
53+
54+
<type name="Magento\Mtf\Troubleshooting\ConfigAnalyzer">
55+
<arguments>
56+
<argument name="configXml" xsi:type="object">Magento\Mtf\Util\Troubleshooting\GlobalConfig</argument>
57+
<argument name="configXmlDist" xsi:type="object">Magento\Mtf\Util\Troubleshooting\GlobalConfigDist</argument>
58+
</arguments>
59+
</type>
60+
61+
<virtualType name="Magento\Mtf\Util\Troubleshooting\Config" type="Magento\Mtf\Config\Reader\Filesystem">
62+
<arguments>
63+
<argument name="fileResolver" xsi:type="object">Magento\Mtf\Config\FileResolver\Primary</argument>
64+
<argument name="converter" xsi:type="object">Magento\Mtf\Config\Converter</argument>
65+
<argument name="schemaLocator" xsi:type="object">Magento\Mtf\Config\SchemaLocator\Config</argument>
66+
<argument name="idAttributes" xsi:type="array">
67+
<item name="/config" xsi:type="string">scope</item>
68+
<item name="/config/server/item" xsi:type="string">name</item>
69+
</argument>
70+
<argument name="fileName" xsi:type="string">config.xml</argument>
71+
<argument name="defaultScope" xsi:type="string">etc</argument>
72+
</arguments>
73+
</virtualType>
74+
75+
<virtualType name="Magento\Mtf\Util\Troubleshooting\GlobalConfig" type="Magento\Mtf\Config\Data">
76+
<arguments>
77+
<argument name="reader" xsi:type="object">Magento\Mtf\Util\Troubleshooting\Config</argument>
78+
</arguments>
79+
</virtualType>
80+
81+
<virtualType name="Magento\Mtf\Util\Troubleshooting\ConfigDist" type="Magento\Mtf\Config\Reader\Filesystem">
82+
<arguments>
83+
<argument name="fileResolver" xsi:type="object">Magento\Mtf\Config\FileResolver\ScopeConfig</argument>
84+
<argument name="converter" xsi:type="object">Magento\Mtf\Config\Converter</argument>
85+
<argument name="schemaLocator" xsi:type="object">Magento\Mtf\Config\SchemaLocator\Config</argument>
86+
<argument name="idAttributes" xsi:type="array">
87+
<item name="/config" xsi:type="string">scope</item>
88+
<item name="/config/server/item" xsi:type="string">name</item>
89+
</argument>
90+
<argument name="fileName" xsi:type="string">config.xml.dist</argument>
91+
<argument name="defaultScope" xsi:type="string">etc</argument>
92+
</arguments>
93+
</virtualType>
94+
95+
<virtualType name="Magento\Mtf\Util\Troubleshooting\GlobalConfigDist" type="Magento\Mtf\Config\Data">
96+
<arguments>
97+
<argument name="reader" xsi:type="object">Magento\Mtf\Util\Troubleshooting\ConfigDist</argument>
98+
</arguments>
99+
</virtualType>
100+
22101
<type name="Magento\Mtf\Util\Command\File\Export\Reader">
23102
<arguments>
24103
<argument name="template" xsi:type="string">\w*?\.csv</argument>

dev/tests/functional/lib/Magento/Mtf/App/State/State1.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Magento\Mtf\App\State;
88

99
use Magento\Mtf\ObjectManager;
10+
use Magento\Mtf\Util\Protocol\CurlInterface;
11+
use Magento\Mtf\Util\Protocol\CurlTransport;
1012

1113
/**
1214
* Example Application State class.
@@ -28,12 +30,22 @@ class State1 extends AbstractState
2830
protected $config ='admin_session_lifetime_1_hour, wysiwyg_disabled, admin_account_sharing_enable, log_to_file';
2931

3032
/**
31-
* @construct
33+
* HTTP CURL Adapter.
34+
*
35+
* @var CurlTransport
36+
*/
37+
private $curlTransport;
38+
39+
/**
3240
* @param ObjectManager $objectManager
41+
* @param CurlTransport $curlTransport
3342
*/
34-
public function __construct(ObjectManager $objectManager)
35-
{
43+
public function __construct(
44+
ObjectManager $objectManager,
45+
CurlTransport $curlTransport
46+
) {
3647
$this->objectManager = $objectManager;
48+
$this->curlTransport = $curlTransport;
3749
}
3850

3951
/**
@@ -44,7 +56,9 @@ public function __construct(ObjectManager $objectManager)
4456
public function apply()
4557
{
4658
parent::apply();
47-
if (file_exists(dirname(dirname(dirname(MTF_BP))) . '/app/etc/config.php')) {
59+
$this->curlTransport->write($_ENV['app_frontend_url'], [], CurlInterface::GET);
60+
$response = $this->curlTransport->read();
61+
if (strpos($response, 'Home Page') !== false) {
4862
$this->objectManager->create(
4963
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
5064
['configData' => $this->config]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Mtf\Config\FileResolver;
8+
9+
use Magento\Mtf\Util\Iterator\File;
10+
11+
/**
12+
* Provides MTF configuration file from specified scope.
13+
*/
14+
class ScopeConfig extends Primary
15+
{
16+
/**
17+
* Retrieve the configuration file with given name that relate to MTF global configuration.
18+
*
19+
* @param string $filename
20+
* @param string $scope
21+
* @return \Magento\Mtf\Util\Iterator\File|array
22+
*/
23+
public function get($filename, $scope)
24+
{
25+
return new File([MTF_BP . DIRECTORY_SEPARATOR . $scope . DIRECTORY_SEPARATOR . $filename]);
26+
}
27+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Mtf\Troubleshooting;
8+
9+
use Magento\Mtf\ObjectManagerInterface;
10+
use Magento\Mtf\Troubleshooting\Helper\UrlAnalyzer;
11+
use Magento\Mtf\Util\Protocol\CurlTransport;
12+
use Magento\Mtf\Util\Protocol\CurlTransport\BackendDecorator;
13+
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Console\Output\OutputInterface;
15+
16+
/**
17+
* Analyze Magento Admin.
18+
*/
19+
class AdminAnalyzer extends \Symfony\Component\Console\Command\Command
20+
{
21+
/**
22+
* Console output of formatted messages.
23+
*
24+
* @var \Magento\Mtf\Console\Output
25+
*/
26+
private $output;
27+
28+
/**
29+
* Object manager instance.
30+
*
31+
* @var ObjectManagerInterface
32+
*/
33+
private $objectManager;
34+
35+
/**
36+
* Url analyzer helper.
37+
*
38+
* @var UrlAnalyzer
39+
*/
40+
private $urlAnalyzer;
41+
42+
/**
43+
* @param ObjectManagerInterface $objectManager
44+
* @param UrlAnalyzer $urlAnalyzer
45+
*/
46+
public function __construct(
47+
ObjectManagerInterface $objectManager,
48+
UrlAnalyzer $urlAnalyzer
49+
) {
50+
parent::__construct();
51+
$this->objectManager = $objectManager;
52+
$this->urlAnalyzer = $urlAnalyzer;
53+
}
54+
55+
/**
56+
* Configure command.
57+
*
58+
* @return void
59+
*/
60+
protected function configure()
61+
{
62+
parent::configure();
63+
$this->setName('troubleshooting:check-magento-admin')
64+
->setDescription('Check that app_backend_url is correct and admin can log in to Admin.');
65+
}
66+
67+
/**
68+
* Execute command.
69+
*
70+
* @param InputInterface $input
71+
* @param OutputInterface $output
72+
* @return void
73+
*/
74+
protected function execute(InputInterface $input, OutputInterface $output)
75+
{
76+
\PHPUnit_Util_Configuration::getInstance(MTF_PHPUNIT_FILE)->handlePHPConfiguration();
77+
$this->output = $this->objectManager->create(
78+
\Magento\Mtf\Console\Output::class,
79+
['output' => $output]
80+
);
81+
$this->output->writeln("Verifying Magento Admin...");
82+
$adminUrlAnalyzerMessages = $this->runAdminUrlAnalyzer();
83+
if (isset($adminUrlAnalyzerMessages['error']) === false) {
84+
$this->output->outputMessages($this->urlAnalyzer->checkDomain($_ENV['app_backend_url']));
85+
} else {
86+
$this->output->outputMessages($adminUrlAnalyzerMessages);
87+
}
88+
$this->output->writeln("Admin verification finished.");
89+
}
90+
91+
/**
92+
* Execute Admin url analyzer check.
93+
*
94+
* @return null|array
95+
*/
96+
public function runAdminUrlAnalyzer()
97+
{
98+
if (!isset($_ENV['app_backend_url'])) {
99+
$messages['error'][] = 'app_backend_url parameter is absent in the phpunit.xml file. '
100+
. 'Please, copy parameter from phpunit.xml.dist.';
101+
return $messages;
102+
}
103+
$this->output->outputMessages($this->urlAnalyzer->fixLastSlash('app_backend_url'));
104+
$url1 = $_ENV['app_backend_url'];
105+
if (strpos($url1, '/index.php') !== false) {
106+
$url2 = str_replace('/index.php', '', $url1);
107+
} else {
108+
$pattern = '/(\/\w+\/)$/';
109+
$replacement = '/index.php$1';
110+
$url2 = str_replace($url1, preg_replace($pattern, $replacement, $url1), $url1);
111+
}
112+
$urls = [$url1, $url2];
113+
$isUrlValid = false;
114+
foreach ($urls as $url) {
115+
$_ENV['app_backend_url'] = $url;
116+
try {
117+
$config = \Magento\Mtf\ObjectManagerFactory::getObjectManager()->create(
118+
\Magento\Mtf\Config\DataInterface::class
119+
);
120+
$curl = new BackendDecorator(new CurlTransport(), $config);
121+
$response = $curl->read();
122+
if (strpos($response, '404') !== false) {
123+
break;
124+
}
125+
$curl->close();
126+
$isUrlValid = true;
127+
break;
128+
} catch (\Exception $e) {
129+
continue;
130+
}
131+
}
132+
if ($isUrlValid == false) {
133+
$messages['error'][] = 'Check correctness of app_backend_url in phpunit.xml.';
134+
return $messages;
135+
} elseif ($url1 != $_ENV['app_backend_url']) {
136+
return $this->urlAnalyzer->resolveIndexPhpProblem($_ENV['app_backend_url']);
137+
}
138+
}
139+
}

0 commit comments

Comments
 (0)