Skip to content

MQE-2242: Add static check to flag use of <pause> #783

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
merged 2 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dev/tests/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

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

require_once $vendorAutoloadPath;
require_once $mftfTestCasePath;
require_once $mftfStaticTestCasePath;

// Set up AspectMock
$kernel = \AspectMock\Kernel::getInstance();
Expand Down
49 changes: 49 additions & 0 deletions dev/tests/util/MftfStaticTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace tests\util;

use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputInterface;

class MftfStaticTestCase extends TestCase
{
const STATIC_RESULTS_DIR = TESTS_MODULE_PATH .
DIRECTORY_SEPARATOR .
'_output' .
DIRECTORY_SEPARATOR .
'static-results';

const RESOURCES_PATH = TESTS_MODULE_PATH .
DIRECTORY_SEPARATOR .
"Resources" .
DIRECTORY_SEPARATOR .
'StaticChecks';

/**
* Sets input interface
* @param $path
* @return \PHPUnit\Framework\MockObject\MockObject
*/
public function mockInputInterface($path = null)
{
$input = $this->getMockBuilder(InputInterface::class)
->disableOriginalConstructor()
->getMock();
if ($path) {
$input->method('getOption')
->with('path')
->willReturn($path);
}
return $input;
}

public function tearDown(): void
{
DirSetupUtil::rmdirRecursive(self::STATIC_RESULTS_DIR);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="ActionGroupWithMultiplePausesActionGroup">
<fillField selector="#foo" userInput="foo" stepKey="fillField1"/>
<pause stepKey="pauseAfterFillField1"/>
<fillField selector="#bar" userInput="bar" stepKey="fillField2"/>
<pause stepKey="pauseAfterFillField2"/>
<fillField selector="#baz" userInput="baz" stepKey="fillField3"/>
<pause stepKey="pauseAfterFillField3"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="ActionGroupWithNoPauseActionGroup">
<fillField selector="#foo" userInput="foo" stepKey="fillField1"/>
<fillField selector="#bar" userInput="bar" stepKey="fillField2"/>
<fillField selector="#baz" userInput="baz" stepKey="fillField3"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="ActionGroupWithPauseActionGroup">
<fillField selector="#foo" userInput="myData1" stepKey="fillField1"/>
<fillField selector="#bar" userInput="myData2" stepKey="fillField2"/>
<pause stepKey="pauseAfterFillField2"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<suites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Suite/etc/suiteSchema.xsd">
<suite name="suiteWithMultiplePauseActionsSuite">
<include>
<group name="include" />
</include>
<before>
<amOnPage url="some.url" stepKey="before"/>
<createData entity="SecretData" stepKey="create1">
<field key="someKey">dataHere</field>
</createData>
<pause stepKey="pauseCreate1"/>
</before>
<after>
<deleteData createDataKey="create1" stepKey="delete1"/>
<deleteData url="deleteThis" stepKey="deleteThis"/>
<fillField selector="#fill" userInput="{{SecretData.key2}}" stepKey="fillAfter"/>
<pause stepKey="pauseFillAfter"/>
</after>
</suite>
</suites>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<suites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Suite/etc/suiteSchema.xsd">
<suite name="suiteWithPauseActionSuite">
<include>
<group name="include" />
</include>
<before>
<amOnPage url="some.url" stepKey="before"/>
<createData entity="createThis" stepKey="create">
<field key="someKey">dataHere</field>
</createData>
<pause stepKey="pauseSuite"/>
<click stepKey="clickWithData" userInput="$create.data$"/>
<fillField selector="#foo" userInput="myData1" stepKey="fillField1"/>
</before>
<after>
<comment userInput="afterBlock" stepKey="afterBlock"/>
</after>
</suite>
</suites>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="TestWithMultiplePauseActionsTest">
<annotations>
<severity value="CRITICAL"/>
<group value="functional"/>
<features value="Pause check"/>
<stories value="MQE-433"/>
</annotations>
<before>
<amOnPage url="/beforeUrl" stepKey="beforeAmOnPageKey"/>
<pause stepKey="pauseBeforeAmOnPageKey"/>
</before>
<fillField stepKey="step1" selector="#username" userInput="step1"/>
<fillField stepKey="step2" selector="#password" userInput="step2"/>
<pause stepKey="pauseAfterStep2"/>
<after>
<amOnPage url="/afterUrl" stepKey="afterAmOnPageKey"/>
<pause stepKey="pauseAfterAmOnPageKey"/>
</after>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="TestWithPauseActionTest">
<annotations>
<severity value="CRITICAL"/>
<group value="functional"/>
<features value="Pause check"/>
<stories value="MQE-433"/>
</annotations>
<amOnPage stepKey="step1" url="/step1"/>
<fillField stepKey="step2" selector="#username" userInput="step2"/>
<fillField stepKey="step3" selector="#password" userInput="step3"/>
<pause stepKey="pauseAfterStep3"/>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

File "/verification/PauseCheckModule/ActionGroup/ActionGroupWithMultiplePausesActionGroup.xml"
contains pause action(s):

ActionGroupWithMultiplePausesActionGroup has pause action at stepKey(s): pauseAfterFillField1, pauseAfterFillField2, pauseAfterFillField3

File "/verification/PauseCheckModule/ActionGroup/ActionGroupWithPauseActionGroup.xml"
contains pause action(s):

ActionGroupWithPauseActionGroup has pause action at stepKey(s): pauseAfterFillField2

File "/verification/PauseCheckModule/Test/TestWithMultiplePauseActionsTest.xml"
contains pause action(s):

TestWithMultiplePauseActionsTest has pause action at stepKey(s): pauseBeforeAmOnPageKey, pauseAfterStep2, pauseAfterAmOnPageKey

File "/verification/PauseCheckModule/Test/TestWithPauseActionTest.xml"
contains pause action(s):

TestWithPauseActionTest has pause action at stepKey(s): pauseAfterStep3

File "/verification/PauseCheckModule/Suite/suiteWithMultiplePauseActionsSuite.xml"
contains pause action(s):

suiteWithMultiplePauseActionsSuite has pause action at stepKey(s): pauseCreate1, pauseFillAfter

File "/verification/PauseCheckModule/Suite/suiteWithPauseActionSuite.xml"
contains pause action(s):

suiteWithPauseActionSuite has pause action at stepKey(s): pauseSuite
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@
use AspectMock\Test as AspectMock;
use Magento\FunctionalTestingFramework\StaticCheck\DeprecatedEntityUsageCheck;
use Magento\FunctionalTestingFramework\StaticCheck\StaticChecksList;
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputInterface;
use tests\util\MftfStaticTestCase;

class DeprecationStaticCheckTest extends TestCase
class DeprecationStaticCheckTest extends MftfStaticTestCase
{
const STATIC_RESULTS_DIR = TESTS_MODULE_PATH .
DIRECTORY_SEPARATOR .
'_output' .
DIRECTORY_SEPARATOR .
'static-results';

const LOG_FILE = self::STATIC_RESULTS_DIR .
DIRECTORY_SEPARATOR .
DeprecatedEntityUsageCheck::ERROR_LOG_FILENAME .
Expand All @@ -30,20 +23,6 @@ class DeprecationStaticCheckTest extends TestCase
'DeprecationCheckModule'.
DIRECTORY_SEPARATOR;

const RESOURCES_PATH = TESTS_MODULE_PATH .
DIRECTORY_SEPARATOR .
"Resources" .
DIRECTORY_SEPARATOR .
'StaticChecks';

public static function setUpBeforeClass(): void
{
// remove static-results if it exists
if (file_exists(self::STATIC_RESULTS_DIR)) {
DirSetupUtil::rmdirRecursive(self::STATIC_RESULTS_DIR);
}
}

/**
* test static-check DeprecatedEntityUsageCheck.
*
Expand All @@ -68,25 +47,4 @@ public function testDeprecatedEntityUsageCheck()
self::LOG_FILE
);
}

/**
* Sets input interface
* @param $path
* @return \PHPUnit\Framework\MockObject\MockObject
*/
public function mockInputInterface($path)
{
$input = $this->getMockBuilder(InputInterface::class)
->disableOriginalConstructor()
->getMock();
$input->method('getOption')
->with('path')
->willReturn($path);
return $input;
}

public function tearDown(): void
{
DirSetupUtil::rmdirRecursive(self::STATIC_RESULTS_DIR);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace tests\verification\Tests;

use AspectMock\Test as AspectMock;
use Magento\FunctionalTestingFramework\StaticCheck\PauseActionUsageCheck;
use Magento\FunctionalTestingFramework\StaticCheck\StaticChecksList;
use Symfony\Component\Console\Input\InputInterface;

use tests\util\MftfStaticTestCase;

class PauseActionStaticCheckTest extends MftfStaticTestCase
{
const LOG_FILE = self::STATIC_RESULTS_DIR .
DIRECTORY_SEPARATOR .
PauseActionUsageCheck::ERROR_LOG_FILENAME .
'.txt';

const TEST_MODULE_PATH = TESTS_MODULE_PATH .
DIRECTORY_SEPARATOR .
'PauseCheckModule'.
DIRECTORY_SEPARATOR;

/**
* test static-check PauseActionUsageCheck.
*
* @throws \Exception
*/
public function testPauseActionUsageCheck()
{
$staticCheck = new PauseActionUsageCheck();

$input = $this->mockInputInterface(self::TEST_MODULE_PATH);
AspectMock::double(StaticChecksList::class, ['getErrorFilesPath' => self::STATIC_RESULTS_DIR]);

/** @var InputInterface $input */
$staticCheck->execute($input);

$this->assertTrue(file_exists(self::LOG_FILE));
$this->assertFileEquals(
self::RESOURCES_PATH.
DIRECTORY_SEPARATOR .
PauseActionUsageCheck::ERROR_LOG_FILENAME .
".txt",
self::LOG_FILE
);
}
}
Loading