Skip to content

Commit ba3362b

Browse files
authored
MQE-2242: Add static check to flag use of <pause> (magento#783)
* MQE-2242: Add static check to flag use of <pause> * MQE-2242: Add static check to flag use of <pause>
1 parent 85d4fa6 commit ba3362b

17 files changed

+543
-52
lines changed

dev/tests/_bootstrap.php

+2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
$vendorAutoloadPath = realpath(PROJECT_ROOT . '/vendor/autoload.php');
1111
$mftfTestCasePath = realpath(PROJECT_ROOT . '/dev/tests/util/MftfTestCase.php');
12+
$mftfStaticTestCasePath = realpath(PROJECT_ROOT . '/dev/tests/util/MftfStaticTestCase.php');
1213

1314
require_once $vendorAutoloadPath;
1415
require_once $mftfTestCasePath;
16+
require_once $mftfStaticTestCasePath;
1517

1618
// Set up AspectMock
1719
$kernel = \AspectMock\Kernel::getInstance();

dev/tests/util/MftfStaticTestCase.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace tests\util;
8+
9+
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
10+
use PHPUnit\Framework\TestCase;
11+
use Symfony\Component\Console\Input\InputInterface;
12+
13+
class MftfStaticTestCase extends TestCase
14+
{
15+
const STATIC_RESULTS_DIR = TESTS_MODULE_PATH .
16+
DIRECTORY_SEPARATOR .
17+
'_output' .
18+
DIRECTORY_SEPARATOR .
19+
'static-results';
20+
21+
const RESOURCES_PATH = TESTS_MODULE_PATH .
22+
DIRECTORY_SEPARATOR .
23+
"Resources" .
24+
DIRECTORY_SEPARATOR .
25+
'StaticChecks';
26+
27+
/**
28+
* Sets input interface
29+
* @param $path
30+
* @return \PHPUnit\Framework\MockObject\MockObject
31+
*/
32+
public function mockInputInterface($path = null)
33+
{
34+
$input = $this->getMockBuilder(InputInterface::class)
35+
->disableOriginalConstructor()
36+
->getMock();
37+
if ($path) {
38+
$input->method('getOption')
39+
->with('path')
40+
->willReturn($path);
41+
}
42+
return $input;
43+
}
44+
45+
public function tearDown(): void
46+
{
47+
DirSetupUtil::rmdirRecursive(self::STATIC_RESULTS_DIR);
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="ActionGroupWithMultiplePausesActionGroup">
11+
<fillField selector="#foo" userInput="foo" stepKey="fillField1"/>
12+
<pause stepKey="pauseAfterFillField1"/>
13+
<fillField selector="#bar" userInput="bar" stepKey="fillField2"/>
14+
<pause stepKey="pauseAfterFillField2"/>
15+
<fillField selector="#baz" userInput="baz" stepKey="fillField3"/>
16+
<pause stepKey="pauseAfterFillField3"/>
17+
</actionGroup>
18+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="ActionGroupWithNoPauseActionGroup">
11+
<fillField selector="#foo" userInput="foo" stepKey="fillField1"/>
12+
<fillField selector="#bar" userInput="bar" stepKey="fillField2"/>
13+
<fillField selector="#baz" userInput="baz" stepKey="fillField3"/>
14+
</actionGroup>
15+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="ActionGroupWithPauseActionGroup">
11+
<fillField selector="#foo" userInput="myData1" stepKey="fillField1"/>
12+
<fillField selector="#bar" userInput="myData2" stepKey="fillField2"/>
13+
<pause stepKey="pauseAfterFillField2"/>
14+
</actionGroup>
15+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<suites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Suite/etc/suiteSchema.xsd">
10+
<suite name="suiteWithMultiplePauseActionsSuite">
11+
<include>
12+
<group name="include" />
13+
</include>
14+
<before>
15+
<amOnPage url="some.url" stepKey="before"/>
16+
<createData entity="SecretData" stepKey="create1">
17+
<field key="someKey">dataHere</field>
18+
</createData>
19+
<pause stepKey="pauseCreate1"/>
20+
</before>
21+
<after>
22+
<deleteData createDataKey="create1" stepKey="delete1"/>
23+
<deleteData url="deleteThis" stepKey="deleteThis"/>
24+
<fillField selector="#fill" userInput="{{SecretData.key2}}" stepKey="fillAfter"/>
25+
<pause stepKey="pauseFillAfter"/>
26+
</after>
27+
</suite>
28+
</suites>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<suites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Suite/etc/suiteSchema.xsd">
10+
<suite name="suiteWithPauseActionSuite">
11+
<include>
12+
<group name="include" />
13+
</include>
14+
<before>
15+
<amOnPage url="some.url" stepKey="before"/>
16+
<createData entity="createThis" stepKey="create">
17+
<field key="someKey">dataHere</field>
18+
</createData>
19+
<pause stepKey="pauseSuite"/>
20+
<click stepKey="clickWithData" userInput="$create.data$"/>
21+
<fillField selector="#foo" userInput="myData1" stepKey="fillField1"/>
22+
</before>
23+
<after>
24+
<comment userInput="afterBlock" stepKey="afterBlock"/>
25+
</after>
26+
</suite>
27+
</suites>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="TestWithMultiplePauseActionsTest">
12+
<annotations>
13+
<severity value="CRITICAL"/>
14+
<group value="functional"/>
15+
<features value="Pause check"/>
16+
<stories value="MQE-433"/>
17+
</annotations>
18+
<before>
19+
<amOnPage url="/beforeUrl" stepKey="beforeAmOnPageKey"/>
20+
<pause stepKey="pauseBeforeAmOnPageKey"/>
21+
</before>
22+
<fillField stepKey="step1" selector="#username" userInput="step1"/>
23+
<fillField stepKey="step2" selector="#password" userInput="step2"/>
24+
<pause stepKey="pauseAfterStep2"/>
25+
<after>
26+
<amOnPage url="/afterUrl" stepKey="afterAmOnPageKey"/>
27+
<pause stepKey="pauseAfterAmOnPageKey"/>
28+
</after>
29+
</test>
30+
</tests>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="TestWithPauseActionTest">
12+
<annotations>
13+
<severity value="CRITICAL"/>
14+
<group value="functional"/>
15+
<features value="Pause check"/>
16+
<stories value="MQE-433"/>
17+
</annotations>
18+
<amOnPage stepKey="step1" url="/step1"/>
19+
<fillField stepKey="step2" selector="#username" userInput="step2"/>
20+
<fillField stepKey="step3" selector="#password" userInput="step3"/>
21+
<pause stepKey="pauseAfterStep3"/>
22+
</test>
23+
</tests>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
File "/verification/PauseCheckModule/ActionGroup/ActionGroupWithMultiplePausesActionGroup.xml"
3+
contains pause action(s):
4+
5+
ActionGroupWithMultiplePausesActionGroup has pause action at stepKey(s): pauseAfterFillField1, pauseAfterFillField2, pauseAfterFillField3
6+
7+
File "/verification/PauseCheckModule/ActionGroup/ActionGroupWithPauseActionGroup.xml"
8+
contains pause action(s):
9+
10+
ActionGroupWithPauseActionGroup has pause action at stepKey(s): pauseAfterFillField2
11+
12+
File "/verification/PauseCheckModule/Test/TestWithMultiplePauseActionsTest.xml"
13+
contains pause action(s):
14+
15+
TestWithMultiplePauseActionsTest has pause action at stepKey(s): pauseBeforeAmOnPageKey, pauseAfterStep2, pauseAfterAmOnPageKey
16+
17+
File "/verification/PauseCheckModule/Test/TestWithPauseActionTest.xml"
18+
contains pause action(s):
19+
20+
TestWithPauseActionTest has pause action at stepKey(s): pauseAfterStep3
21+
22+
File "/verification/PauseCheckModule/Suite/suiteWithMultiplePauseActionsSuite.xml"
23+
contains pause action(s):
24+
25+
suiteWithMultiplePauseActionsSuite has pause action at stepKey(s): pauseCreate1, pauseFillAfter
26+
27+
File "/verification/PauseCheckModule/Suite/suiteWithPauseActionSuite.xml"
28+
contains pause action(s):
29+
30+
suiteWithPauseActionSuite has pause action at stepKey(s): pauseSuite

dev/tests/verification/Tests/StaticCheck/DeprecationStaticCheckTest.php

+2-44
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@
88
use AspectMock\Test as AspectMock;
99
use Magento\FunctionalTestingFramework\StaticCheck\DeprecatedEntityUsageCheck;
1010
use Magento\FunctionalTestingFramework\StaticCheck\StaticChecksList;
11-
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
12-
use PHPUnit\Framework\TestCase;
1311
use Symfony\Component\Console\Input\InputInterface;
12+
use tests\util\MftfStaticTestCase;
1413

15-
class DeprecationStaticCheckTest extends TestCase
14+
class DeprecationStaticCheckTest extends MftfStaticTestCase
1615
{
17-
const STATIC_RESULTS_DIR = TESTS_MODULE_PATH .
18-
DIRECTORY_SEPARATOR .
19-
'_output' .
20-
DIRECTORY_SEPARATOR .
21-
'static-results';
22-
2316
const LOG_FILE = self::STATIC_RESULTS_DIR .
2417
DIRECTORY_SEPARATOR .
2518
DeprecatedEntityUsageCheck::ERROR_LOG_FILENAME .
@@ -30,20 +23,6 @@ class DeprecationStaticCheckTest extends TestCase
3023
'DeprecationCheckModule'.
3124
DIRECTORY_SEPARATOR;
3225

33-
const RESOURCES_PATH = TESTS_MODULE_PATH .
34-
DIRECTORY_SEPARATOR .
35-
"Resources" .
36-
DIRECTORY_SEPARATOR .
37-
'StaticChecks';
38-
39-
public static function setUpBeforeClass(): void
40-
{
41-
// remove static-results if it exists
42-
if (file_exists(self::STATIC_RESULTS_DIR)) {
43-
DirSetupUtil::rmdirRecursive(self::STATIC_RESULTS_DIR);
44-
}
45-
}
46-
4726
/**
4827
* test static-check DeprecatedEntityUsageCheck.
4928
*
@@ -68,25 +47,4 @@ public function testDeprecatedEntityUsageCheck()
6847
self::LOG_FILE
6948
);
7049
}
71-
72-
/**
73-
* Sets input interface
74-
* @param $path
75-
* @return \PHPUnit\Framework\MockObject\MockObject
76-
*/
77-
public function mockInputInterface($path)
78-
{
79-
$input = $this->getMockBuilder(InputInterface::class)
80-
->disableOriginalConstructor()
81-
->getMock();
82-
$input->method('getOption')
83-
->with('path')
84-
->willReturn($path);
85-
return $input;
86-
}
87-
88-
public function tearDown(): void
89-
{
90-
DirSetupUtil::rmdirRecursive(self::STATIC_RESULTS_DIR);
91-
}
9250
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace tests\verification\Tests;
7+
8+
use AspectMock\Test as AspectMock;
9+
use Magento\FunctionalTestingFramework\StaticCheck\PauseActionUsageCheck;
10+
use Magento\FunctionalTestingFramework\StaticCheck\StaticChecksList;
11+
use Symfony\Component\Console\Input\InputInterface;
12+
13+
use tests\util\MftfStaticTestCase;
14+
15+
class PauseActionStaticCheckTest extends MftfStaticTestCase
16+
{
17+
const LOG_FILE = self::STATIC_RESULTS_DIR .
18+
DIRECTORY_SEPARATOR .
19+
PauseActionUsageCheck::ERROR_LOG_FILENAME .
20+
'.txt';
21+
22+
const TEST_MODULE_PATH = TESTS_MODULE_PATH .
23+
DIRECTORY_SEPARATOR .
24+
'PauseCheckModule'.
25+
DIRECTORY_SEPARATOR;
26+
27+
/**
28+
* test static-check PauseActionUsageCheck.
29+
*
30+
* @throws \Exception
31+
*/
32+
public function testPauseActionUsageCheck()
33+
{
34+
$staticCheck = new PauseActionUsageCheck();
35+
36+
$input = $this->mockInputInterface(self::TEST_MODULE_PATH);
37+
AspectMock::double(StaticChecksList::class, ['getErrorFilesPath' => self::STATIC_RESULTS_DIR]);
38+
39+
/** @var InputInterface $input */
40+
$staticCheck->execute($input);
41+
42+
$this->assertTrue(file_exists(self::LOG_FILE));
43+
$this->assertFileEquals(
44+
self::RESOURCES_PATH.
45+
DIRECTORY_SEPARATOR .
46+
PauseActionUsageCheck::ERROR_LOG_FILENAME .
47+
".txt",
48+
self::LOG_FILE
49+
);
50+
}
51+
}

0 commit comments

Comments
 (0)