@@ -147,58 +147,76 @@ public function getDataByName($dataName, $uniDataFormat)
147
147
if (null === $ uniData || $ uniDataFormat == self ::NO_UNIQUE_PROCESS ) {
148
148
return $ this ->data [$ name ];
149
149
}
150
-
151
- switch ($ uniDataFormat ) {
152
- case self ::SUITE_UNIQUE_VALUE :
153
- if (!function_exists (self ::SUITE_UNIQUE_FUNCTION )) {
154
- throw new TestFrameworkException (
155
- sprintf (
156
- 'Unique data format value: %s can only be used when running cests.\n ' ,
157
- $ uniDataFormat
158
- )
159
- );
160
- } elseif ($ uniData == 'prefix ' ) {
161
- return msqs ($ this ->getName ()) . $ this ->data [$ name ];
162
- } else { // $uniData == 'suffix'
163
- return $ this ->data [$ name ] . msqs ($ this ->getName ());
164
- }
165
- break ;
166
- case self ::CEST_UNIQUE_VALUE :
167
- if (!function_exists (self ::CEST_UNIQUE_FUNCTION )) {
168
- throw new TestFrameworkException (
169
- sprintf (
170
- 'Unique data format value: %s can only be used when running cests.\n ' ,
171
- $ uniDataFormat
172
- )
173
- );
174
- } elseif ($ uniData == 'prefix ' ) {
175
- return msq ($ this ->getName ()) . $ this ->data [$ name ];
176
- } else { // $uniData == 'suffix'
177
- return $ this ->data [$ name ] . msq ($ this ->getName ());
178
- }
179
- break ;
180
- case self ::SUITE_UNIQUE_NOTATION :
181
- if ($ uniData == 'prefix ' ) {
182
- return self ::SUITE_UNIQUE_FUNCTION . '(" ' . $ this ->getName () . '") ' . $ this ->data [$ name ];
183
- } else { // $uniData == 'suffix'
184
- return $ this ->data [$ name ] . self ::SUITE_UNIQUE_FUNCTION . '(" ' . $ this ->getName () . '") ' ;
185
- }
186
- break ;
187
- case self ::CEST_UNIQUE_NOTATION :
188
- if ($ uniData == 'prefix ' ) {
189
- return self ::CEST_UNIQUE_FUNCTION . '(" ' . $ this ->getName () . '") ' . $ this ->data [$ name ];
190
- } else { // $uniData == 'suffix'
191
- return $ this ->data [$ name ] . self ::CEST_UNIQUE_FUNCTION . '(" ' . $ this ->getName () . '") ' ;
192
- }
193
- break ;
194
- default :
195
- break ;
196
- }
150
+ return $ this ->formatUniqueData ($ name , $ uniData , $ uniDataFormat );
197
151
}
152
+ return null ;
153
+ }
198
154
155
+ /**
156
+ * Formats and returns data based on given uniqueDataFormat and prefix/suffix.
157
+ * @param string $name
158
+ * @param string $uniqueData
159
+ * @param string $uniqueDataFormat
160
+ * @return null|string
161
+ */
162
+ private function formatUniqueData ($ name , $ uniqueData , $ uniqueDataFormat )
163
+ {
164
+ switch ($ uniqueDataFormat ) {
165
+ case self ::SUITE_UNIQUE_VALUE :
166
+ $ this ->checkUniquenessFunctionExists (self ::SUITE_UNIQUE_FUNCTION , $ uniqueDataFormat );
167
+ if ($ uniqueData == 'prefix ' ) {
168
+ return msqs ($ this ->getName ()) . $ this ->data [$ name ];
169
+ } else { // $uniData == 'suffix'
170
+ return $ this ->data [$ name ] . msqs ($ this ->getName ());
171
+ }
172
+ break ;
173
+ case self ::CEST_UNIQUE_VALUE :
174
+ $ this ->checkUniquenessFunctionExists (self ::CEST_UNIQUE_FUNCTION , $ uniqueDataFormat );
175
+ if ($ uniqueData == 'prefix ' ) {
176
+ return msq ($ this ->getName ()) . $ this ->data [$ name ];
177
+ } else { // $uniqueData == 'suffix'
178
+ return $ this ->data [$ name ] . msq ($ this ->getName ());
179
+ }
180
+ break ;
181
+ case self ::SUITE_UNIQUE_NOTATION :
182
+ if ($ uniqueData == 'prefix ' ) {
183
+ return self ::SUITE_UNIQUE_FUNCTION . '(" ' . $ this ->getName () . '") ' . $ this ->data [$ name ];
184
+ } else { // $uniqueData == 'suffix'
185
+ return $ this ->data [$ name ] . self ::SUITE_UNIQUE_FUNCTION . '(" ' . $ this ->getName () . '") ' ;
186
+ }
187
+ break ;
188
+ case self ::CEST_UNIQUE_NOTATION :
189
+ if ($ uniqueData == 'prefix ' ) {
190
+ return self ::CEST_UNIQUE_FUNCTION . '(" ' . $ this ->getName () . '") ' . $ this ->data [$ name ];
191
+ } else { // $uniqueData == 'suffix'
192
+ return $ this ->data [$ name ] . self ::CEST_UNIQUE_FUNCTION . '(" ' . $ this ->getName () . '") ' ;
193
+ }
194
+ break ;
195
+ default :
196
+ break ;
197
+ }
199
198
return null ;
200
199
}
201
200
201
+ /**
202
+ * Performs a check that the given uniqueness function exists, throws an exception if it doesn't.
203
+ * @param string $function
204
+ * @param string $uniqueDataFormat
205
+ * @return void
206
+ * @throws TestFrameworkException
207
+ */
208
+ private function checkUniquenessFunctionExists ($ function , $ uniqueDataFormat )
209
+ {
210
+ if (!function_exists ($ function )) {
211
+ throw new TestFrameworkException (
212
+ sprintf (
213
+ 'Unique data format value: %s can only be used when running cests.\n ' ,
214
+ $ uniqueDataFormat
215
+ )
216
+ );
217
+ }
218
+ }
219
+
202
220
/**
203
221
* Function which returns a reference to another entity (e.g. a var with entity="category" field="id" returns as
204
222
* category->id)
0 commit comments