Skip to content

MQE-1470: add interface to handle file path and url format #509

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 6 commits into from
Nov 26, 2019
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Tests\unit\Magento\FunctionalTestFramework\Util\Path;

use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;

class FilePathFormatterTest extends MagentoTestCase
{
/**
* Test file format
*
* @dataProvider formatDataProvider
* @param string $path
* @param boolean $withTrailingSeparator
* @param mixed string|boolean $expectedPath
* @return void
* @throws TestFrameworkException
*/
public function testFormat($path, $withTrailingSeparator, $expectedPath)
{
if (null !== $expectedPath) {
$this->assertEquals($expectedPath, FilePathFormatter::format($path, $withTrailingSeparator));
} else {
// Assert no exception
FilePathFormatter::format($path, $withTrailingSeparator);
$this->assertTrue(true);
}
}

/**
* Test file format with exception
*
* @dataProvider formatExceptionDataProvider
* @param string $path
* @param boolean $withTrailingSeparator
* @return void
* @throws TestFrameworkException
*/
public function testFormatWithException($path, $withTrailingSeparator)
{
$this->expectException(TestFrameworkException::class);
$this->expectExceptionMessage("Invalid or non-existing file: $path\n");
FilePathFormatter::format($path, $withTrailingSeparator);
}

/**
* Data input
*
* @return array
*/
public function formatDataProvider()
{
$path1 = rtrim(TESTS_BP, '/');
$path2 = $path1 . DIRECTORY_SEPARATOR;
return [
[$path1, null, $path1],
[$path1, false, $path1],
[$path1, true, $path2],
[$path2, null, $path1],
[$path2, false, $path1],
[$path2, true, $path2],
[__DIR__. DIRECTORY_SEPARATOR . basename(__FILE__), null, __FILE__],
['', null, null] // Empty string is valid
];
}

/**
* Invalid data input
*
* @return array
*/
public function formatExceptionDataProvider()
{
return [
['abc', null],
['X://some\dir/@', null],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Tests\unit\Magento\FunctionalTestFramework\Util\Path;

use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
use Magento\FunctionalTestingFramework\Util\Path\UrlFormatter;
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;

class UrlFormatterTest extends MagentoTestCase
{
/**
* Test url format
*
* @dataProvider formatDataProvider
* @param string $path
* @param boolean $withTrailingSeparator
* @param mixed string|boolean $expectedPath
* @return void
* @throws TestFrameworkException
*/
public function testFormat($path, $withTrailingSeparator, $expectedPath)
{
$this->assertEquals($expectedPath, UrlFormatter::format($path, $withTrailingSeparator));
}

/**
* Test url format with exception
*
* @dataProvider formatExceptionDataProvider
* @param string $path
* @param boolean $withTrailingSeparator
* @return void
* @throws TestFrameworkException
*/
public function testFormatWithException($path, $withTrailingSeparator)
{
$this->expectException(TestFrameworkException::class);
$this->expectExceptionMessage("Invalid url: $path\n");
UrlFormatter::format($path, $withTrailingSeparator);
}

/**
* Data input
*
* @return array
*/
public function formatDataProvider()
{
$url1 = 'http://magento.local/index.php';
$url2 = $url1 . '/';
$url3 = 'https://www.example.com/index.php/admin';
$url4 = $url3 . '/';
$url5 = 'www.google.com';
$url6 = 'http://www.google.com/';
$url7 = 'http://127.0.0.1:8200';
$url8 = 'wwøw.goåoøgle.coøm';
$url9 = 'http://www.google.com';
return [
[$url1, null, $url1],
[$url1, false, $url1],
[$url1, true, $url2],
[$url2, null, $url1],
[$url2, false, $url1],
[$url2, true, $url2],
[$url3, null, $url3],
[$url3, false, $url3],
[$url3, true, $url4],
[$url4, null, $url3],
[$url4, false, $url3],
[$url4, true, $url4],
[$url5, true, $url6],
[$url7, false, $url7],
[$url8, false, $url9],
];
}

/**
* Invalid data input
*
* @return array
*/
public function formatExceptionDataProvider()
{
return [
['', null],
];
}
}
6 changes: 4 additions & 2 deletions dev/tests/verification/Tests/SuiteGenerationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

namespace tests\verification\Tests;

use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
use Magento\FunctionalTestingFramework\Suite\SuiteGenerator;
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
use Magento\FunctionalTestingFramework\Util\Manifest\DefaultTestManifest;
use Magento\FunctionalTestingFramework\Util\Manifest\ParallelTestManifest;
use Magento\FunctionalTestingFramework\Util\Manifest\TestManifestFactory;
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
use PHPUnit\Util\Filesystem;
use Symfony\Component\Yaml\Yaml;
use tests\unit\Util\TestLoggingUtil;
Expand Down Expand Up @@ -413,11 +415,11 @@ public static function tearDownAfterClass()
* Getter for manifest file path
*
* @return string
* @throws TestFrameworkException
*/
private static function getManifestFilePath()
{
return TESTS_BP .
DIRECTORY_SEPARATOR .
return FilePathFormatter::format(TESTS_BP) .
"verification" .
DIRECTORY_SEPARATOR .
"_generated" .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

namespace Magento\FunctionalTestingFramework\Config\FileResolver;

use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
use Magento\FunctionalTestingFramework\Util\Iterator\File;
use Magento\FunctionalTestingFramework\Config\FileResolverInterface;
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;

/**
* Provides the list of global configuration files.
Expand Down Expand Up @@ -54,6 +56,7 @@ private function getFilePaths($filename, $scope)
* @param string $filename
* @param string $scope
* @return array
* @throws TestFrameworkException
*/
private function getPathPatterns($filename, $scope)
{
Expand All @@ -69,8 +72,9 @@ private function getPathPatterns($filename, $scope)
$defaultPath . DIRECTORY_SEPARATOR . $scope . DIRECTORY_SEPARATOR . $filename,
$defaultPath . DIRECTORY_SEPARATOR . $scope . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR
. $filename,
FW_BP . DIRECTORY_SEPARATOR . $scope . DIRECTORY_SEPARATOR . $filename,
FW_BP . DIRECTORY_SEPARATOR . $scope . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $filename
FilePathFormatter::format(FW_BP) . $scope . DIRECTORY_SEPARATOR . $filename,
FilePathFormatter::format(FW_BP) . $scope . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR
. $filename
];
}
return str_replace(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $patterns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
namespace Magento\FunctionalTestingFramework\Config\FileResolver;

use Magento\FunctionalTestingFramework\Config\FileResolverInterface;
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
use Magento\FunctionalTestingFramework\Util\Iterator\File;
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;

class Root extends Module
{
Expand All @@ -20,12 +22,13 @@ class Root extends Module
* @param string $filename
* @param string $scope
* @return array|\Iterator,\Countable
* @throws TestFrameworkException
*/
public function get($filename, $scope)
{
// first pick up the root level test suite dir
$paths = glob(
TESTS_BP . DIRECTORY_SEPARATOR . self::ROOT_SUITE_DIR
FilePathFormatter::format(TESTS_BP) . self::ROOT_SUITE_DIR
. DIRECTORY_SEPARATOR . $filename
);

Expand Down
11 changes: 8 additions & 3 deletions src/Magento/FunctionalTestingFramework/Config/SchemaLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace Magento\FunctionalTestingFramework\Config;

use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;

/**
* Configuration schema locator.
*/
Expand All @@ -30,12 +33,14 @@ class SchemaLocator implements \Magento\FunctionalTestingFramework\Config\Schema
*
* @param string $schemaPath
* @param string|null $perFileSchema
* @throws TestFrameworkException
*/
public function __construct($schemaPath, $perFileSchema = null)
{
if (constant('FW_BP') && file_exists(FW_BP . DIRECTORY_SEPARATOR . $schemaPath)) {
$this->schemaPath = FW_BP . DIRECTORY_SEPARATOR . $schemaPath;
$this->perFileSchema = $perFileSchema === null ? null : FW_BP . DIRECTORY_SEPARATOR . $perFileSchema;
if (constant('FW_BP') && file_exists(FilePathFormatter::format(FW_BP) . $schemaPath)) {
$this->schemaPath = FilePathFormatter::format(FW_BP) . $schemaPath;
$this->perFileSchema = $perFileSchema === null ? null : FilePathFormatter::format(FW_BP)
. $perFileSchema;
} else {
$path = dirname(dirname(dirname(__DIR__)));
$path = str_replace('\\', DIRECTORY_SEPARATOR, $path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

namespace Magento\FunctionalTestingFramework\Console;

use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -57,10 +59,11 @@ protected function configure()
* @param OutputInterface $output
* @param bool $verbose
* @return void
* @throws TestFrameworkException
*/
protected function removeGeneratedDirectory(OutputInterface $output, bool $verbose)
{
$generatedDirectory = TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . TestGenerator::GENERATED_DIR;
$generatedDirectory = FilePathFormatter::format(TESTS_MODULE_PATH) . TestGenerator::GENERATED_DIR;

if (file_exists($generatedDirectory)) {
DirSetupUtil::rmdirRecursive($generatedDirectory);
Expand Down
Loading