forked from magento/magento2-functional-testing-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestNameValidationUtil.php
61 lines (53 loc) · 1.78 KB
/
TestNameValidationUtil.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\Test\Util;
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
class TestNameValidationUtil
{
const BLACKLISTED_CHAR = [
" " => "spaces",
"," => "commas",
"'" => "single quotes",
"\"" => "double quotes",
"{" => "curly braces",
"}" => "curly braces",
"$" => "dollar signs",
"(" => "parenthesis",
")" => "parenthesis"
];
/**
* Function which runs a validation against the blacklisted char defined in this class. Validation occurs to insure
* allure report does not error/future devOps builds do not error against illegal char.
*
* @param string $testName
* @return void
* @throws XmlException
*/
public static function validateName($testName)
{
$testChars = str_split($testName);
$diff = array_intersect($testChars, array_keys(self::BLACKLISTED_CHAR));
if (count($diff) > 0) {
$errorMessage = "Test name \"${testName}\" contains illegal characters, please fix and re-run.";
$uniqueDiff = array_unique(array_map(['self', 'nameMapper'], $diff));
foreach ($uniqueDiff as $diffChar) {
$errorMessage .= "\nTest names cannot contain " . $diffChar;
}
throw new XmlException($errorMessage);
}
}
/**
* Function which maps the blacklisted char to its name, function is used by the array map above.
*
* @param string $val
* @return string
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
*/
private static function nameMapper($val)
{
return self::BLACKLISTED_CHAR[$val];
}
}