Skip to content

MQE 1650: Update MFTF configuration to read Test entities from new location #428

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

Closed
wants to merge 10 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
use tests\unit\Util\SuiteDataArrayBuilder;
use tests\unit\Util\TestDataArrayBuilder;
use tests\unit\Util\MockModuleResolverBuilder;

class SuiteObjectHandlerTest extends MagentoTestCase
{
public function setUp()
{
$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup();
}

/**
* Tests basic parsing and accesors of suite object and suite object supporting classes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
use tests\unit\Util\SuiteDataArrayBuilder;
use tests\unit\Util\TestDataArrayBuilder;
use tests\unit\Util\TestLoggingUtil;
use tests\unit\Util\MockModuleResolverBuilder;

class SuiteGeneratorTest extends MagentoTestCase
{

/**
* Setup entry append and clear for Suite Generator
*/
Expand All @@ -42,6 +42,8 @@ public static function setUpBeforeClass()
public function setUp()
{
TestLoggingUtil::getInstance()->setMockLoggingUtil();
$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@

use AspectMock\Test as AspectMock;

use Go\Aop\Aspect;
use Magento\FunctionalTestingFramework\ObjectManager;
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
use Magento\FunctionalTestingFramework\Test\Objects\TestHookObject;
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
use Magento\FunctionalTestingFramework\Test\Parsers\TestDataParser;
use Magento\FunctionalTestingFramework\Test\Util\ActionObjectExtractor;
use Magento\FunctionalTestingFramework\Test\Util\TestObjectExtractor;
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
use tests\unit\Util\TestDataArrayBuilder;
use tests\unit\Util\MockModuleResolverBuilder;

class TestObjectHandlerTest extends MagentoTestCase
{
Expand All @@ -40,10 +39,13 @@ public function testGetTestObject()
->withTestActions()
->build();

$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup();
$this->setMockParserOutput(['tests' => $mockData]);

// run object handler method
$toh = TestObjectHandler::getInstance();
$mockConfig = AspectMock::double(TestObjectHandler::class, ['initTestData' => false]);
$actualTestObject = $toh->getObject($testDataArrayBuilder->testName);

// perform asserts
Expand Down Expand Up @@ -130,6 +132,8 @@ public function testGetTestsByGroup()
->withTestActions()
->build();

$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup();
$this->setMockParserOutput(['tests' => array_merge($includeTest, $excludeTest)]);

// execute test method
Expand All @@ -150,16 +154,20 @@ public function testGetTestsByGroup()
public function testGetTestWithModuleName()
{
// set up Test Data
$moduleExpected = "SomeTestModule";
$moduleExpected = "SomeModuleName";
$moduleExpectedTest = $moduleExpected . "Test";
$filepath = DIRECTORY_SEPARATOR .
"user" .
"user" . DIRECTORY_SEPARATOR .
"magento2ce" . DIRECTORY_SEPARATOR .
"dev" . DIRECTORY_SEPARATOR .
"tests" . DIRECTORY_SEPARATOR .
"acceptance" . DIRECTORY_SEPARATOR .
"tests" . DIRECTORY_SEPARATOR .
$moduleExpected . DIRECTORY_SEPARATOR .
"Tests" . DIRECTORY_SEPARATOR .
"functional" . DIRECTORY_SEPARATOR .
"Vendor" . DIRECTORY_SEPARATOR .
$moduleExpectedTest;
$file = $filepath . DIRECTORY_SEPARATOR .
"Test" . DIRECTORY_SEPARATOR .
"text.xml";
// set up mock data
$testDataArrayBuilder = new TestDataArrayBuilder();
Expand All @@ -169,8 +177,12 @@ public function testGetTestWithModuleName()
->withAfterHook()
->withBeforeHook()
->withTestActions()
->withFileName($filepath)
->withFileName($file)
->build();

$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup(['Vendor_' . $moduleExpected => [$filepath]]);

$this->setMockParserOutput(['tests' => $mockData]);
// Execute Test Method
$toh = TestObjectHandler::getInstance();
Expand Down Expand Up @@ -198,4 +210,14 @@ private function setMockParserOutput($data)
->make(); // bypass the private constructor
AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]);
}

/**
* After method functionality
*
* @return void
*/
public function tearDown()
{
AspectMock::clean();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PHPUnit\Framework\TestCase;
use tests\unit\Util\TestDataArrayBuilder;
use tests\unit\Util\TestLoggingUtil;
use tests\unit\Util\MockModuleResolverBuilder;

class ObjectExtensionUtilTest extends TestCase
{
Expand All @@ -30,6 +31,8 @@ class ObjectExtensionUtilTest extends TestCase
public function setUp()
{
TestLoggingUtil::getInstance()->setMockLoggingUtil();
$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,103 +7,128 @@
namespace tests\unit\Magento\FunctionalTestFramework\Test\Util;

use Magento\FunctionalTestingFramework\Util\ModulePathExtractor;
use PHPUnit\Framework\TestCase;
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
use tests\unit\Util\MockModuleResolverBuilder;

class ModulePathExtractorTest extends TestCase
class ModulePathExtractorTest extends MagentoTestCase
{
const EXTENSION_PATH = "app"
. DIRECTORY_SEPARATOR
. "code"
. DIRECTORY_SEPARATOR
. "TestExtension"
. DIRECTORY_SEPARATOR
. "[Analytics]"
. DIRECTORY_SEPARATOR
. "Test"
. DIRECTORY_SEPARATOR
. "Mftf"
. DIRECTORY_SEPARATOR
. "Test"
. DIRECTORY_SEPARATOR
. "SomeText.xml";

const MAGENTO_PATH = "dev"
. DIRECTORY_SEPARATOR
. "tests"
. DIRECTORY_SEPARATOR
. "acceptance"
. DIRECTORY_SEPARATOR
. "tests"
. DIRECTORY_SEPARATOR
. "functional"
. DIRECTORY_SEPARATOR
. "Magento"
. DIRECTORY_SEPARATOR
. "FunctionalTest"
. DIRECTORY_SEPARATOR
. "[Analytics]"
. DIRECTORY_SEPARATOR
. "Test"
. DIRECTORY_SEPARATOR
. "SomeText.xml";
/**
* Mock test module paths
*
* @var array
*/
private $mockTestModulePaths = [
'Magento_ModuleA' => ['/base/path/app/code/Magento/ModuleA/Test/Mftf'],
'VendorB_ModuleB' => ['/base/path/app/code/VendorB/ModuleB/Test/Mftf'],
'Magento_ModuleC' => ['/base/path/dev/tests/acceptance/tests/functional/Magento/ModuleCTest'],
'VendorD_ModuleD' => ['/base/path/dev/tests/acceptance/tests/functional/VendorD/ModuleDTest'],
'SomeModuleE' => ['/base/path/dev/tests/acceptance/tests/functional/FunctionalTest/SomeModuleE'],
'Magento_ModuleF' => ['/base/path/vendor/magento/module-modulef/Test/Mftf'],
'VendorG_ModuleG' => ['/base/path/vendor/vendorg/module-moduleg-test'],
];

/**
* Validate module for app/code path
*
* @throws \Exception
*/
public function testGetModuleAppCode()
{
$mockPath = '/base/path/app/code/Magento/ModuleA/Test/Mftf/Test/SomeTest.xml';

$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup($this->mockTestModulePaths);
$extractor = new ModulePathExtractor();
$this->assertEquals('ModuleA', $extractor->extractModuleName($mockPath));
}

/**
* Validate correct module is returned for dev/tests path
* Validate vendor for app/code path
*
* @throws \Exception
*/
public function testGetMagentoModule()
public function testGetVendorAppCode()
{
$modulePathExtractor = new ModulePathExtractor();
$this->assertEquals(
'[Analytics]',
$modulePathExtractor->extractModuleName(
self::MAGENTO_PATH
)
);
$mockPath = '/base/path/app/code/VendorB/ModuleB/Test/Mftf/Test/SomeTest.xml';

$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup($this->mockTestModulePaths);
$extractor = new ModulePathExtractor();
$this->assertEquals('VendorB', $extractor->getExtensionPath($mockPath));
}

/**
* Validate correct module is returned for extension path
* Validate module for dev/tests path
*
* @throws \Exception
*/
public function testGetExtensionModule()
public function testGetModuleDevTests()
{
$modulePathExtractor = new ModulePathExtractor();
$this->assertEquals(
'[Analytics]',
$modulePathExtractor->extractModuleName(
self::EXTENSION_PATH
)
);
$mockPath = '/base/path/dev/tests/acceptance/tests/functional/Magento/ModuleCTest/Test/SomeTest.xml';

$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup($this->mockTestModulePaths);
$extractor = new ModulePathExtractor();
$this->assertEquals('ModuleC', $extractor->extractModuleName($mockPath));
}

/**
* Validate Magento is returned for dev/tests/acceptance
* Validate vendor for dev/tests path
*
* @throws \Exception
*/
public function testMagentoModulePath()
public function testGetVendorDevTests()
{
$modulePathExtractor = new ModulePathExtractor();
$this->assertEquals(
'Magento',
$modulePathExtractor->getExtensionPath(
self::MAGENTO_PATH
)
);
$mockPath = '/base/path/dev/tests/acceptance/tests/functional/VendorD/ModuleDTest/Test/SomeTest.xml';

$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup($this->mockTestModulePaths);
$extractor = new ModulePathExtractor();
$this->assertEquals('VendorD', $extractor->getExtensionPath($mockPath));
}

/**
* Validate correct extension path is returned
* Validate module with no _
*
* @throws \Exception
*/
public function testExtensionModulePath()
public function testGetModule()
{
$modulePathExtractor = new ModulePathExtractor();
$this->assertEquals(
'TestExtension',
$modulePathExtractor->getExtensionPath(
self::EXTENSION_PATH
)
);
$mockPath = '/base/path/dev/tests/acceptance/tests/functional/FunctionalTest/SomeModuleE/Test/SomeTest.xml';

$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup($this->mockTestModulePaths);
$extractor = new ModulePathExtractor();
$this->assertEquals('NO MODULE DETECTED', $extractor->extractModuleName($mockPath));
}

/**
* Validate module for vendor/tests path
*
* @throws \Exception
*/
public function testGetModuleVendorDir()
{
$mockPath = '/base/path/vendor/magento/module-modulef/Test/Mftf/Test/SomeTest.xml';

$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup($this->mockTestModulePaths);
$extractor = new ModulePathExtractor();
$this->assertEquals('ModuleF', $extractor->extractModuleName($mockPath));
}

/**
* Validate vendor for vendor path
*
* @throws \Exception
*/
public function testGetVendorVendorDir()
{
$mockPath = '/base/path/vendor/vendorg/module-moduleg-test/Test/SomeTest.xml';

$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup($this->mockTestModulePaths);
$extractor = new ModulePathExtractor();
$this->assertEquals('VendorG', $extractor->getExtensionPath($mockPath));
}
}
Loading