Skip to content

Commit a879839

Browse files
authored
Merge branch 'MFTF3.0.0-RC2' into MQE-2043
2 parents 39f62b8 + 155d846 commit a879839

File tree

12 files changed

+976
-28
lines changed

12 files changed

+976
-28
lines changed

docs/commands/mftf.md

+6
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,12 @@ If no script name argument is specified, all existing static check scripts will
439439
vendor/bin/mftf static-checks [<names>]...
440440
```
441441

442+
#### Options
443+
444+
| Option | Description |
445+
|-----------------------|-----------------------------------------------------------------------------------------------------------|
446+
| `-p, --path` | Path to a MFTF test module to run "deprecatedEntityUsage" static check script. Option is ignored by other static check scripts.
447+
442448
#### Examples
443449

444450
To check what existing static check scripts are available

etc/codecoverage/index.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Application entry point
4+
*
5+
* Example - run a particular store or website:
6+
* --------------------------------------------
7+
* require __DIR__ . '/app/bootstrap.php';
8+
* $params = $_SERVER;
9+
* $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'website2';
10+
* $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
11+
* $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
12+
* \/** @var \Magento\Framework\App\Http $app *\/
13+
* $app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
14+
* $bootstrap->run($app);
15+
* --------------------------------------------
16+
*
17+
* Copyright © Magento, Inc. All rights reserved.
18+
* See COPYING.txt for license details.
19+
*/
20+
21+
try {
22+
require __DIR__ . '/app/bootstrap.php';
23+
} catch (\Exception $e) {
24+
echo <<<HTML
25+
<div style="font:12px/1.35em arial, helvetica, sans-serif;">
26+
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
27+
<h3 style="margin:0;font-size:1.7em;font-weight:normal;text-transform:none;text-align:left;color:#2f2f2f;">
28+
Autoload error</h3>
29+
</div>
30+
<p>{$e->getMessage()}</p>
31+
</div>
32+
HTML;
33+
exit(1);
34+
}
35+
36+
//Patch start
37+
$driver = new pcov\Clobber\Driver\PHPUnit6();
38+
$coverage = new \SebastianBergmann\CodeCoverage\CodeCoverage($driver);
39+
$coverage->filter()->addDirectoryToWhitelist("app/code/Magento/*");
40+
$coverage->filter()->removeDirectoryFromWhitelist("app/code/Magento/*/Test");
41+
$testName = "NO_TEST_NAME";
42+
if (file_exists(__DIR__ . '/CURRENT_TEST')) {
43+
$testName = file_get_contents(__DIR__ . '/CURRENT_TEST');
44+
}
45+
$id = !empty($testName) ? $testName : "NO_TEST_NAME";
46+
$coverage->start($id);
47+
//Patch end
48+
49+
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
50+
/** @var \Magento\Framework\App\Http $app */
51+
$app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
52+
$bootstrap->run($app);
53+
54+
// Patch start
55+
$coverage->stop();
56+
$writer = new \SebastianBergmann\CodeCoverage\Report\PHP();
57+
$writer->process($coverage, '/var/www/html/coverage/reports/' . $id . "_" . md5(mt_rand()) . '.cov');
58+
// Patch end

etc/codecoverage/test.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
$test = $_GET['test'] ?? "NO_TEST_SPECIFIED";
9+
file_put_contents('CURRENT_TEST', $test);
10+
echo 'SET CURRENT TEST TO ' . $test;

src/Magento/FunctionalTestingFramework/Config/FileResolver/Root.php

+13
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ public function get($filename, $scope)
3232
. DIRECTORY_SEPARATOR . '*.xml'
3333
);
3434

35+
// include root suite dir when running standalone version
36+
$altPath = FilePathFormatter::format(MAGENTO_BP) . 'dev/tests/acceptance';
37+
38+
if (realpath($altPath) && ($altPath !== TESTS_BP)) {
39+
$paths = array_merge(
40+
$paths,
41+
glob(
42+
FilePathFormatter::format($altPath) . self::ROOT_SUITE_DIR
43+
. DIRECTORY_SEPARATOR . '*.xml'
44+
)
45+
);
46+
}
47+
3548
// Then merge this path into the module based paths
3649
// Since we are sharing this code with Module based resolution we will unnecessarily glob against modules in the
3750
// dev/tests dir tree, however as we plan to migrate to app/code this will be a temporary unneeded check.

src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php

+49-15
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
use Symfony\Component\Console\Exception\InvalidArgumentException;
1616
use Symfony\Component\Console\Input\InputArgument;
1717
use Symfony\Component\Console\Input\InputInterface;
18+
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Output\OutputInterface;
1920
use Exception;
21+
use Symfony\Component\Console\Style\SymfonyStyle;
2022

2123
class StaticChecksCommand extends Command
2224
{
@@ -34,6 +36,13 @@ class StaticChecksCommand extends Command
3436
*/
3537
private $staticCheckObjects;
3638

39+
/**
40+
* Console output style
41+
*
42+
* @var SymfonyStyle
43+
*/
44+
protected $ioStyle;
45+
3746
/**
3847
* Configures the current command.
3948
*
@@ -44,14 +53,20 @@ protected function configure()
4453
$list = new StaticChecksList();
4554
$this->allStaticCheckObjects = $list->getStaticChecks();
4655
$staticCheckNames = implode(', ', array_keys($this->allStaticCheckObjects));
47-
$description = "This command will run all static checks on xml test materials. "
48-
. "Available static check scripts are:\n{$staticCheckNames}";
56+
$description = 'This command will run all static checks on xml test materials. '
57+
. 'Available static check scripts are:' . PHP_EOL . $staticCheckNames;
4958
$this->setName('static-checks')
5059
->setDescription($description)
5160
->addArgument(
5261
'names',
5362
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
5463
'name(s) of specific static check script(s) to run'
64+
)->addOption(
65+
'path',
66+
'p',
67+
InputOption::VALUE_OPTIONAL,
68+
'Path to a MFTF test module to run "deprecatedEntityUsage" static check script. ' . PHP_EOL
69+
. 'Option is ignored by other static check scripts.' . PHP_EOL
5570
);
5671
}
5772

@@ -65,32 +80,41 @@ protected function configure()
6580
*/
6681
protected function execute(InputInterface $input, OutputInterface $output)
6782
{
83+
$this->ioStyle = new SymfonyStyle($input, $output);
6884
try {
69-
$this->validateInputArguments($input, $output);
85+
$this->validateInput($input);
7086
} catch (InvalidArgumentException $e) {
7187
LoggingUtil::getInstance()->getLogger(StaticChecksCommand::class)->error($e->getMessage());
72-
$output->writeln($e->getMessage() . " Please fix input arguments and rerun.");
88+
$this->ioStyle->error($e->getMessage() . ' Please fix input argument(s) or option(s) and rerun.');
7389
return 1;
7490
}
7591

92+
$cmdFailed = false;
7693
$errors = [];
7794
foreach ($this->staticCheckObjects as $name => $staticCheck) {
7895
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->info(
79-
"\nRunning static check script for: " . $name
80-
);
81-
$output->writeln(
82-
"\nRunning static check script for: " . $name
96+
'Running static check script for: ' . $name . PHP_EOL
8397
);
8498

85-
$staticCheck->execute($input);
99+
$this->ioStyle->text(PHP_EOL . 'Running static check script for: ' . $name . PHP_EOL);
100+
$start = microtime(true);
101+
try {
102+
$staticCheck->execute($input);
103+
} catch (Exception $e) {
104+
$cmdFailed = true;
105+
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->error($e->getMessage() . PHP_EOL);
106+
$this->ioStyle->error($e->getMessage());
107+
}
108+
$end = microtime(true);
109+
$errors += $staticCheck->getErrors();
86110

87111
$staticOutput = $staticCheck->getOutput();
88112
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->info($staticOutput);
89-
$output->writeln($staticOutput);
90-
$errors += $staticCheck->getErrors();
91-
}
113+
$this->ioStyle->text($staticOutput);
92114

93-
if (empty($errors)) {
115+
$this->ioStyle->text('Total execution time is ' . (string)($end - $start) . ' seconds.' . PHP_EOL);
116+
}
117+
if (!$cmdFailed && empty($errors)) {
94118
return 0;
95119
} else {
96120
return 1;
@@ -104,7 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
104128
* @return void
105129
* @throws InvalidArgumentException
106130
*/
107-
private function validateInputArguments(InputInterface $input)
131+
private function validateInput(InputInterface $input)
108132
{
109133
$this->staticCheckObjects = [];
110134
$requiredChecksNames = $input->getArgument('names');
@@ -126,8 +150,18 @@ private function validateInputArguments(InputInterface $input)
126150

127151
if (!empty($invalidCheckNames)) {
128152
throw new InvalidArgumentException(
129-
"Invalid static check script(s): " . implode(', ', $invalidCheckNames) . "."
153+
'Invalid static check script(s): ' . implode(', ', $invalidCheckNames) . '.'
130154
);
131155
}
156+
157+
if ($input->getOption('path')) {
158+
if ( (count($this->staticCheckObjects) !== 1)
159+
|| array_keys($this->staticCheckObjects)[0] !== StaticChecksList::DEPRECATED_ENTITY_USAGE_CHECK_NAME )
160+
throw new InvalidArgumentException(
161+
'--path option can only be used for "'
162+
. StaticChecksList::DEPRECATED_ENTITY_USAGE_CHECK_NAME
163+
. '".'
164+
);
165+
}
132166
}
133167
}

src/Magento/FunctionalTestingFramework/Extension/TestContextExtension.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ class TestContextExtension extends BaseExtension
3232
*/
3333
public static $events;
3434

35+
/**
36+
* The name of the currently running test
37+
* @var string
38+
*/
39+
public $currentTest;
40+
3541
/**
3642
* Initialize local vars
3743
*
@@ -55,8 +61,20 @@ public function _initialize()
5561
* @throws \Exception
5662
* @return void
5763
*/
58-
public function testStart()
64+
public function testStart(\Codeception\Event\TestEvent $e)
5965
{
66+
if (getenv('ENABLE_CODE_COVERAGE') === 'true') {
67+
// Curl against test.php and pass in the test name. Used when gathering code coverage.
68+
$this->currentTest = $e->getTest()->getMetadata()->getName();
69+
$cURLConnection = curl_init();
70+
curl_setopt_array($cURLConnection, [
71+
CURLOPT_RETURNTRANSFER => 1,
72+
CURLOPT_URL => getenv('MAGENTO_BASE_URL') . "/test.php?test=" . $this->currentTest,
73+
]);
74+
curl_exec($cURLConnection);
75+
curl_close($cURLConnection);
76+
}
77+
6078
PersistedObjectHandler::getInstance()->clearHookObjects();
6179
PersistedObjectHandler::getInstance()->clearTestObjects();
6280
}

0 commit comments

Comments
 (0)