Skip to content

Commit 4f548b1

Browse files
committed
MQE-2242: Add static check to flag use of <pause>
1 parent 85d4fa6 commit 4f548b1

16 files changed

+547
-51
lines changed

Diff for: 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();

Diff for: dev/tests/util/MftfStaticTestCase.php

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
public static function setUpBeforeClass(): void
28+
{
29+
// remove static-results if it exists
30+
if (file_exists(self::STATIC_RESULTS_DIR)) {
31+
DirSetupUtil::rmdirRecursive(self::STATIC_RESULTS_DIR);
32+
}
33+
}
34+
35+
/**
36+
* Sets input interface
37+
* @param $path
38+
* @return \PHPUnit\Framework\MockObject\MockObject
39+
*/
40+
public function mockInputInterface($path = null)
41+
{
42+
$input = $this->getMockBuilder(InputInterface::class)
43+
->disableOriginalConstructor()
44+
->getMock();
45+
if ($path) {
46+
$input->method('getOption')
47+
->with('path')
48+
->willReturn($path);
49+
}
50+
return $input;
51+
}
52+
53+
public function tearDown(): void
54+
{
55+
DirSetupUtil::rmdirRecursive(self::STATIC_RESULTS_DIR);
56+
}
57+
}
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="MultiplePausesActionGroup">
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="NoPauseActionGroup">
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="PauseActionGroup">
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,29 @@
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="multiplePauseActionsSuite">
11+
<include>
12+
<group name="include" />
13+
<pause stepKey="pauseInclude"/>
14+
</include>
15+
<before>
16+
<amOnPage url="some.url" stepKey="before"/>
17+
<createData entity="SecretData" stepKey="create1">
18+
<field key="someKey">dataHere</field>
19+
</createData>
20+
<pause stepKey="pauseCreate1"/>
21+
</before>
22+
<after>
23+
<deleteData createDataKey="create1" stepKey="delete1"/>
24+
<deleteData url="deleteThis" stepKey="deleteThis"/>
25+
<fillField selector="#fill" userInput="{{SecretData.key2}}" stepKey="fillAfter"/>
26+
<pause stepKey="pauseFillAfter"/>
27+
</after>
28+
</suite>
29+
</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="pauseActionSuite">
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,24 @@
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="MultiplePauseActionsTest">
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+
<pause stepKey="pauseAfterStep2"/>
21+
<fillField stepKey="step3" selector="#password" userInput="step3"/>
22+
<pause stepKey="pauseAfterStep3"/>
23+
</test>
24+
</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="PauseActionTest">
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/PauseActionGroup.xml"
3+
contains pause action(s):
4+
5+
PauseActionGroup has pause action at stepKey(s): pauseAfterFillField2
6+
7+
File "/verification/PauseCheckModule/ActionGroup/MultiplePausesActionGroup.xml"
8+
contains pause action(s):
9+
10+
MultiplePausesActionGroup has pause action at stepKey(s): pauseAfterFillField1, pauseAfterFillField2, pauseAfterFillField3
11+
12+
File "/verification/PauseCheckModule/Test/PauseActionTest.xml"
13+
contains pause action(s):
14+
15+
PauseActionTest has pause action at stepKey(s): pauseAfterStep3
16+
17+
File "/verification/PauseCheckModule/Test/MultiplePauseActionsTest.xml"
18+
contains pause action(s):
19+
20+
MultiplePauseActionsTest has pause action at stepKey(s): pauseAfterStep2, pauseAfterStep3
21+
22+
File "/verification/PauseCheckModule/Suite/multiplePauseActionsSuite.xml"
23+
contains pause action(s):
24+
25+
multiplePauseActionsSuite has pause action at stepKey(s): pauseInclude, pauseCreate1, pauseFillAfter
26+
27+
File "/verification/PauseCheckModule/Suite/pauseActionSuite.xml"
28+
contains pause action(s):
29+
30+
pauseActionSuite has pause action at stepKey(s): pauseSuite

Diff for: 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,52 @@
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+
16+
class PauseActionStaticCheckTest extends MftfStaticTestCase
17+
{
18+
const LOG_FILE = self::STATIC_RESULTS_DIR .
19+
DIRECTORY_SEPARATOR .
20+
PauseActionUsageCheck::ERROR_LOG_FILENAME .
21+
'.txt';
22+
23+
const TEST_MODULE_PATH = TESTS_MODULE_PATH .
24+
DIRECTORY_SEPARATOR .
25+
'PauseCheckModule'.
26+
DIRECTORY_SEPARATOR;
27+
28+
/**
29+
* test static-check PauseActionUsageCheck.
30+
*
31+
* @throws \Exception
32+
*/
33+
public function testPauseActionUsageCheck()
34+
{
35+
$staticCheck = new PauseActionUsageCheck();
36+
37+
$input = $this->mockInputInterface(self::TEST_MODULE_PATH);
38+
AspectMock::double(StaticChecksList::class, ['getErrorFilesPath' => self::STATIC_RESULTS_DIR]);
39+
40+
/** @var InputInterface $input */
41+
$staticCheck->execute($input);
42+
43+
$this->assertTrue(file_exists(self::LOG_FILE));
44+
$this->assertFileEquals(
45+
self::RESOURCES_PATH.
46+
DIRECTORY_SEPARATOR .
47+
PauseActionUsageCheck::ERROR_LOG_FILENAME .
48+
".txt",
49+
self::LOG_FILE
50+
);
51+
}
52+
}

0 commit comments

Comments
 (0)