@@ -18,8 +18,18 @@ class UpdateAssertionSchema implements UpgradeInterface
18
18
{
19
19
const OLD_ASSERTION_ATTRIBUTES = ["expected " , "expectedType " , "actual " , "actualType " ];
20
20
21
+ /**
22
+ * Current file being inspected, for error messaging
23
+ * @var string
24
+ */
21
25
private $ currentFile ;
26
+
27
+ /**
28
+ * Potential errors reported during replacement.
29
+ * @var array
30
+ */
22
31
private $ errors = [];
32
+
23
33
/**
24
34
* Upgrades all test xml files, changing <assert> actions to be nested
25
35
*
@@ -40,7 +50,7 @@ public function execute(InputInterface $input)
40
50
}
41
51
$ this ->currentFile = $ file ->getFilename ();
42
52
$ contents = $ file ->getContents ();
43
- // Isolate <assert ... /> but not <assert ... >
53
+ // Isolate <assert ... /> but not <assert> ... </assert >
44
54
preg_match_all ('/<assert[^>]*\/>/ ' , $ contents , $ potentialAssertions );
45
55
$ newAssertions = [];
46
56
$ index = 0 ;
@@ -58,6 +68,12 @@ public function execute(InputInterface $input)
58
68
return ("Assertion Syntax updated in {$ testsUpdated } file(s). \n" . implode ("\n\t" , $ this ->errors ));
59
69
}
60
70
71
+ /**
72
+ * Detects present of attributes in file
73
+ *
74
+ * @param string $file
75
+ * @return boolean
76
+ */
61
77
private function detectOldAttributes ($ file )
62
78
{
63
79
foreach (self ::OLD_ASSERTION_ATTRIBUTES as $ OLD_ASSERTION_ATTRIBUTE ) {
@@ -68,6 +84,13 @@ private function detectOldAttributes($file)
68
84
return false ;
69
85
}
70
86
87
+ /**
88
+ * Takes given string and attempts to convert it from single line to multi-line
89
+ *
90
+ * @param string $assertion
91
+ * @return string
92
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
93
+ */
71
94
private function convertOldAssertionToNew ($ assertion )
72
95
{
73
96
// <assertSomething => assertSomething
@@ -112,7 +135,8 @@ private function convertOldAssertionToNew($assertion)
112
135
foreach ($ subElements as $ type => $ subElement ) {
113
136
if (!isset ($ subElement ['value ' ]) || !isset ($ subElement ['type ' ])) {
114
137
//don't have all the info we need to rebuild
115
- $ this ->errors [] = "UNABLE TO FULLY REBUILD ASSERTION, PLEASE MANUALLY CHECK FORMAT ( $ assertType \"$ stepKey \" in $ this ->currentFile ) " ;
138
+ $ this ->errors [] = "UNABLE TO FULLY REBUILD ASSERTION, PLEASE MANUALLY CHECK FORMAT " .
139
+ "( $ assertType \"$ stepKey \" in $ this ->currentFile ) " ;
116
140
continue ;
117
141
}
118
142
$ value = $ subElement ['value ' ];
@@ -122,5 +146,4 @@ private function convertOldAssertionToNew($assertion)
122
146
$ newString .= "</ $ assertType> " ;
123
147
return $ newString ;
124
148
}
125
-
126
149
}
0 commit comments