Skip to content

Commit 4640c03

Browse files
committed
MQE-2493: Update assert implementation in mftf 2.x to work with phpunit 9
1 parent 21c6bf9 commit 4640c03

File tree

3 files changed

+156
-28
lines changed

3 files changed

+156
-28
lines changed

dev/tests/verification/Resources/AssertTest.txt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class AssertTestCest
4545
$I->assertArrayNotHasKey("kiwi", ['orange' => 2, 'apple' => 1], "pass"); // stepKey: assertArrayNotHasKey
4646
$I->assertArraySubset([1, 2], [1, 2, 3, 5], "pass"); // stepKey: assertArraySubset
4747
$I->assertContains("ab", ['item1' => 'a', 'item2' => 'ab'], "pass"); // stepKey: assertContains
48+
$I->assertStringContainsString("ab", "abcde", "pass"); // stepKey: assertStringContainsString
4849
$I->assertCount(2, ['a', 'b'], "pass"); // stepKey: assertCount
4950
$I->assertEmpty([], "pass"); // stepKey: assertEmpty
5051
$I->assertEquals($text, "Copyright © 2013-2017 Magento, Inc. All rights reserved.", "pass"); // stepKey: assertEquals1
@@ -56,17 +57,17 @@ class AssertTestCest
5657
$I->assertGreaterOrEquals(2, 5, "pass"); // stepKey: assertGreaterOrEquals
5758
$I->assertGreaterThan(2, 5, "pass"); // stepKey: assertGreaterthan
5859
$I->assertGreaterThanOrEqual(2, 5, "pass"); // stepKey: assertGreaterThanOrEqual
59-
$I->assertInternalType("string", "xyz", "pass"); // stepKey: assertInternalType1
60-
$I->assertInternalType("int", 21, "pass"); // stepKey: assertInternalType2
61-
$I->assertInternalType("string", $text, "pass"); // stepKey: assertInternalType3
60+
$I->assertIsString("xyz", "pass"); // stepKey: assertInternalType1
61+
$I->assertIsInt(21, "pass"); // stepKey: assertInternalType2
62+
$I->assertIsString($text, "pass"); // stepKey: assertInternalType3
6263
$I->assertLessOrEquals(5, 2, "pass"); // stepKey: assertLessOrEquals
6364
$I->assertLessThan(5, 2, "pass"); // stepKey: assertLessThan
6465
$I->assertLessThanOrEqual(5, 2, "pass"); // stepKey: assertLessThanOrEquals
65-
$I->assertNotContains("bc", ['item1' => 'a', 'item2' => 'ab'], "pass"); // stepKey: assertNotContains1
66-
$I->assertNotContains("bc", $text, "pass"); // stepKey: assertNotContains2
66+
$I->assertNotContains("bc", ['item1' => 'a', 'item2' => 'ab'], "pass"); // stepKey: assertNotContains
67+
$I->assertStringNotContainsString("bc", $text, "pass"); // stepKey: assertStringNotContainsString
6768
$I->assertNotEmpty([1, 2], "pass"); // stepKey: assertNotEmpty1
6869
$I->assertNotEmpty($text, "pass"); // stepKey: assertNotEmpty2
69-
$I->assertNotEquals(2, 5, "pass", 0); // stepKey: assertNotEquals
70+
$I->assertNotEqualsWithDelta(2, 5, 0, "pass"); // stepKey: assertNotEquals
7071
$I->assertNotNull("abc", "pass"); // stepKey: assertNotNull1
7172
$I->assertNotNull($text, "pass"); // stepKey: assertNotNull2
7273
$I->assertNotRegExp("/foo/", "bar", "pass"); // stepKey: assertNotRegExp
@@ -81,7 +82,8 @@ class AssertTestCest
8182
$I->assertArrayHasKey("apple", ['orange' => 2, 'apple' => 1], "pass"); // stepKey: assertArrayHasKeyBackwardCompatible
8283
$I->assertArrayNotHasKey("kiwi", ['orange' => 2, 'apple' => 1], "pass"); // stepKey: assertArrayNotHasKeyBackwardCompatible
8384
$I->assertArraySubset([1, 2], [1, 2, 3, 5], "pass"); // stepKey: assertArraySubsetBackwardCompatible
84-
$I->assertContains("ab", ['item1' => 'a', 'item2' => 'ab'], "pass"); // stepKey: assertContainsBackwardCompatible
85+
$I->assertContains("ab", ['item1' => 'a', 'item2' => 'ab'], "pass"); // stepKey: assertContains1BackwardCompatible
86+
$I->assertStringContainsString("ab", "abcde", "pass"); // stepKey: assertContains2BackwardCompatible
8587
$I->assertCount(2, ['a', 'b'], "pass"); // stepKey: assertCountBackwardCompatible
8688
$I->assertEmpty([], "pass"); // stepKey: assertEmptyBackwardCompatible
8789
$I->assertEquals($text, "Copyright © 2013-2017 Magento, Inc. All rights reserved.", "pass"); // stepKey: assertEquals1BackwardCompatible
@@ -92,17 +94,17 @@ class AssertTestCest
9294
$I->assertGreaterOrEquals(2, 5, "pass"); // stepKey: assertGreaterOrEqualsBackwardCompatible
9395
$I->assertGreaterThan(2, 5, "pass"); // stepKey: assertGreaterThanBackwardCompatible
9496
$I->assertGreaterThanOrEqual(2, 5, "pass"); // stepKey: assertGreaterThanOrEqualBackwardCompatible
95-
$I->assertInternalType("string", "xyz", "pass"); // stepKey: assertInternalType1BackwardCompatible
96-
$I->assertInternalType("int", 21, "pass"); // stepKey: assertInternalType2BackwardCompatible
97-
$I->assertInternalType("string", $text, "pass"); // stepKey: assertInternalType3BackwardCompatible
97+
$I->assertIsString("xyz", "pass"); // stepKey: assertInternalType1BackwardCompatible
98+
$I->assertIsInt(21, "pass"); // stepKey: assertInternalType2BackwardCompatible
99+
$I->assertIsString($text, "pass"); // stepKey: assertInternalType3BackwardCompatible
98100
$I->assertLessOrEquals(5, 2, "pass"); // stepKey: assertLessOrEqualBackwardCompatibles
99101
$I->assertLessThan(5, 2, "pass"); // stepKey: assertLessThanBackwardCompatible
100102
$I->assertLessThanOrEqual(5, 2, "pass"); // stepKey: assertLessThanOrEqualBackwardCompatible
101103
$I->assertNotContains("bc", ['item1' => 'a', 'item2' => 'ab'], "pass"); // stepKey: assertNotContains1BackwardCompatible
102-
$I->assertNotContains("bc", $text, "pass"); // stepKey: assertNotContains2BackwardCompatible
104+
$I->assertStringNotContainsString("bc", $text, "pass"); // stepKey: assertNotContains2BackwardCompatible
103105
$I->assertNotEmpty([1, 2], "pass"); // stepKey: assertNotEmpty1BackwardCompatible
104106
$I->assertNotEmpty($text, "pass"); // stepKey: assertNotEmpty2BackwardCompatible
105-
$I->assertNotEquals(2, 5, "pass", 0); // stepKey: assertNotEqualsBackwardCompatible
107+
$I->assertNotEqualsWithDelta(2, 5, 0, "pass"); // stepKey: assertNotEqualsBackwardCompatible
106108
$I->assertNotNull("abc", "pass"); // stepKey: assertNotNull1BackwardCompatible
107109
$I->assertNotNull($text, "pass"); // stepKey: assertNotNull2BackwardCompatible
108110
$I->assertNotRegExp("/foo/", "bar", "pass"); // stepKey: assertNotRegExpBackwardCompatible

dev/tests/verification/TestModule/Test/AssertTest.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
<expectedResult type="string">ab</expectedResult>
4040
<actualResult type="const">['item1' => 'a', 'item2' => 'ab']</actualResult>
4141
</assertContains>
42+
<assertContains stepKey="assertStringContainsString" message="pass">
43+
<expectedResult type="string">ab</expectedResult>
44+
<actualResult type="string">abcde</actualResult>
45+
</assertContains>
4246
<assertCount stepKey="assertCount" message="pass">
4347
<expectedResult type="int">2</expectedResult>
4448
<actualResult type="const">['a', 'b']</actualResult>
@@ -103,11 +107,11 @@
103107
<expectedResult type="int">5</expectedResult>
104108
<actualResult type="int">2</actualResult>
105109
</assertLessThanOrEqual>
106-
<assertNotContains stepKey="assertNotContains1" message="pass">
110+
<assertNotContains stepKey="assertNotContains" message="pass">
107111
<expectedResult type="string">bc</expectedResult>
108112
<actualResult type="const">['item1' => 'a', 'item2' => 'ab']</actualResult>
109113
</assertNotContains>
110-
<assertNotContains stepKey="assertNotContains2" message="pass">
114+
<assertNotContains stepKey="assertStringNotContainsString" message="pass">
111115
<expectedResult type="string">bc</expectedResult>
112116
<actualResult type="variable">text</actualResult>
113117
</assertNotContains>
@@ -160,7 +164,8 @@
160164
<assertArrayHasKey stepKey="assertArrayHasKeyBackwardCompatible" expected="apple" expectedType="string" actual="['orange' => 2, 'apple' => 1]" actualType="const" message="pass"/>
161165
<assertArrayNotHasKey stepKey="assertArrayNotHasKeyBackwardCompatible" expected="kiwi" expectedType="string" actual="['orange' => 2, 'apple' => 1]" message="pass"/>
162166
<assertArraySubset stepKey="assertArraySubsetBackwardCompatible" expected="[1, 2]" actual="[1, 2, 3, 5]" message="pass"/>
163-
<assertContains stepKey="assertContainsBackwardCompatible" expected="ab" expectedType="string" actual="['item1' => 'a', 'item2' => 'ab']" message="pass"/>
167+
<assertContains stepKey="assertContains1BackwardCompatible" expected="ab" expectedType="string" actual="['item1' => 'a', 'item2' => 'ab']" message="pass"/>
168+
<assertContains stepKey="assertContains2BackwardCompatible" expected="ab" expectedType="string" actual="abcde" actualType="string" message="pass"/>
164169
<assertCount stepKey="assertCountBackwardCompatible" expected="2" expectedType="int" actual="['a', 'b']" message="pass"/>
165170
<assertEmpty stepKey="assertEmptyBackwardCompatible" actual="[]" message="pass"/>
166171
<assertEquals stepKey="assertEquals1BackwardCompatible" expected="text" expectedType="variable" actual="Copyright © 2013-2017 Magento, Inc. All rights reserved." actualType="string" message="pass"/>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 134 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ class TestGenerator
6262

6363
const MFTF_3_O_0_DEPRECATION_MESSAGE = ' is DEPRECATED and will be removed in MFTF 3.0.0.';
6464

65+
/**
66+
* PHPUnit 9 Assert Equal Types
67+
*/
68+
const ASSERT_EQUAL_TYPES = [
69+
'array',
70+
'bool',
71+
'float',
72+
'int',
73+
'numeric',
74+
'object',
75+
'resource',
76+
'string',
77+
'scalar',
78+
'callable',
79+
'iterable',
80+
];
81+
6582
/**
6683
* Actor name for AcceptanceTest
6784
*
@@ -1011,6 +1028,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
10111028
break;
10121029
case "selectOption":
10131030
case "unselectOption":
1031+
case "seeNumberOfElements":
10141032
$testSteps .= $this->wrapFunctionCall(
10151033
$actor,
10161034
$actionObject,
@@ -1190,15 +1208,6 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
11901208
case "seeOptionIsSelected":
11911209
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $input);
11921210
break;
1193-
case "seeNumberOfElements":
1194-
$testSteps .= $this->wrapFunctionCall(
1195-
$actor,
1196-
$actionObject,
1197-
$selector,
1198-
$input,
1199-
$parameterArray
1200-
);
1201-
break;
12021211
case "seeInPageSource":
12031212
case "dontSeeInPageSource":
12041213
case "seeInSource":
@@ -1219,14 +1228,67 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
12191228
);
12201229
break;
12211230
case "assertEquals":
1231+
if (isset($assertDelta)) {
1232+
$replaceType = 'assertEqualsWithDelta';
1233+
call_user_func(\Closure::bind(
1234+
function () use ($actionObject, $replaceType) {
1235+
$actionObject->type = $replaceType;
1236+
},
1237+
null,
1238+
$actionObject
1239+
));
1240+
$testSteps .= $this->wrapFunctionCall(
1241+
$actor,
1242+
$actionObject,
1243+
$assertExpected,
1244+
$assertActual,
1245+
$assertDelta,
1246+
$assertMessage
1247+
);
1248+
} else {
1249+
$testSteps .= $this->wrapFunctionCall(
1250+
$actor,
1251+
$actionObject,
1252+
$assertExpected,
1253+
$assertActual,
1254+
$assertMessage
1255+
);
1256+
}
1257+
break;
1258+
case "assertNotEquals":
1259+
if (isset($assertDelta)) {
1260+
$replaceType = 'assertNotEqualsWithDelta';
1261+
call_user_func(\Closure::bind(
1262+
function () use ($actionObject, $replaceType) {
1263+
$actionObject->type = $replaceType;
1264+
},
1265+
null,
1266+
$actionObject
1267+
));
1268+
$testSteps .= $this->wrapFunctionCall(
1269+
$actor,
1270+
$actionObject,
1271+
$assertExpected,
1272+
$assertActual,
1273+
$assertDelta,
1274+
$assertMessage
1275+
);
1276+
} else {
1277+
$testSteps .= $this->wrapFunctionCall(
1278+
$actor,
1279+
$actionObject,
1280+
$assertExpected,
1281+
$assertActual,
1282+
$assertMessage
1283+
);
1284+
}
1285+
break;
12221286
case "assertGreaterOrEquals":
12231287
case "assertGreaterThan":
12241288
case "assertGreaterThanOrEqual":
1225-
case "assertInternalType":
12261289
case "assertLessOrEquals":
12271290
case "assertLessThan":
12281291
case "assertLessThanOrEqual":
1229-
case "assertNotEquals":
12301292
case "assertInstanceOf":
12311293
case "assertNotInstanceOf":
12321294
case "assertNotRegExp":
@@ -1238,8 +1300,6 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
12381300
case "assertArrayHasKey":
12391301
case "assertArrayNotHasKey":
12401302
case "assertCount":
1241-
case "assertContains":
1242-
case "assertNotContains":
12431303
case "expectException":
12441304
$testSteps .= $this->wrapFunctionCall(
12451305
$actor,
@@ -1250,6 +1310,67 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
12501310
$assertDelta
12511311
);
12521312
break;
1313+
case "assertContains":
1314+
if ((substr(trim($assertActual), 0, 1) !== '[')
1315+
|| (substr(trim($assertActual), -1, 1) !== ']')) {
1316+
$replaceType = 'assertStringContainsString';
1317+
call_user_func(\Closure::bind(
1318+
function () use ($actionObject, $replaceType) {
1319+
$actionObject->type = $replaceType;
1320+
},
1321+
null,
1322+
$actionObject
1323+
));
1324+
}
1325+
$testSteps .= $this->wrapFunctionCall(
1326+
$actor,
1327+
$actionObject,
1328+
$assertExpected,
1329+
$assertActual,
1330+
$assertMessage
1331+
);
1332+
break;
1333+
case "assertNotContains":
1334+
if ((substr(trim($assertActual), 0, 1) !== '[')
1335+
|| (substr(trim($assertActual), -1, 1) !== ']')) {
1336+
$replaceType = 'assertStringNotContainsString';
1337+
call_user_func(\Closure::bind(
1338+
function () use ($actionObject, $replaceType) {
1339+
$actionObject->type = $replaceType;
1340+
},
1341+
null,
1342+
$actionObject
1343+
));
1344+
}
1345+
$testSteps .= $this->wrapFunctionCall(
1346+
$actor,
1347+
$actionObject,
1348+
$assertExpected,
1349+
$assertActual,
1350+
$assertMessage
1351+
);
1352+
break;
1353+
case "assertInternalType":
1354+
foreach (self::ASSERT_EQUAL_TYPES as $type) {
1355+
if (stristr($assertExpected, $type) !== false) {
1356+
$replaceType = 'assertIs' . ucfirst($type);
1357+
call_user_func(\Closure::bind(
1358+
function () use ($actionObject, $replaceType) {
1359+
$actionObject->type = $replaceType;
1360+
},
1361+
null,
1362+
$actionObject
1363+
));
1364+
break;
1365+
}
1366+
}
1367+
$testSteps .= $this->wrapFunctionCall(
1368+
$actor,
1369+
$actionObject,
1370+
$assertActual,
1371+
$assertMessage
1372+
);
1373+
break;
12531374
case "assertElementContainsAttribute":
12541375
// If a blank string or null is passed in we need to pass a blank string to the function.
12551376
if (empty($assertExpected)) {

0 commit comments

Comments
 (0)