@@ -113,41 +113,7 @@ public static function fromRetryableWrites(stdClass $outcome)
113113 */
114114 public static function fromTransactions (stdClass $ operation )
115115 {
116- $ o = new self ();
117-
118- if (isset ($ operation ->error )) {
119- $ o ->isExpected = $ operation ->error ;
120- }
121-
122- $ result = isset ($ operation ->result ) ? $ operation ->result : null ;
123-
124- if (isset ($ result ->errorContains )) {
125- $ o ->messageContains = $ result ->errorContains ;
126- $ o ->isExpected = true ;
127- }
128-
129- if (isset ($ result ->errorCodeName )) {
130- $ o ->codeName = $ result ->errorCodeName ;
131- $ o ->isExpected = true ;
132- }
133-
134- if (isset ($ result ->errorLabelsContain )) {
135- if (! self ::isArrayOfStrings ($ result ->errorLabelsContain )) {
136- throw InvalidArgumentException::invalidType ('errorLabelsContain ' , $ result ->errorLabelsContain , 'string[] ' );
137- }
138- $ o ->includedLabels = $ result ->errorLabelsContain ;
139- $ o ->isExpected = true ;
140- }
141-
142- if (isset ($ result ->errorLabelsOmit )) {
143- if (! self ::isArrayOfStrings ($ result ->errorLabelsOmit )) {
144- throw InvalidArgumentException::invalidType ('errorLabelsOmit ' , $ result ->errorLabelsOmit , 'string[] ' );
145- }
146- $ o ->excludedLabels = $ result ->errorLabelsOmit ;
147- $ o ->isExpected = true ;
148- }
149-
150- return $ o ;
116+ return self ::fromGenericOperation ($ operation );
151117 }
152118
153119 public static function noError ()
@@ -232,6 +198,48 @@ private function assertCodeName(TestCase $test, Exception $actual = null)
232198 $ test ->assertSame ($ this ->codeName , $ result ->codeName );
233199 }
234200
201+ /**
202+ * @throws InvalidArgumentException
203+ */
204+ private static function fromGenericOperation (stdClass $ operation )
205+ {
206+ $ o = new self ();
207+
208+ if (isset ($ operation ->error )) {
209+ $ o ->isExpected = $ operation ->error ;
210+ }
211+
212+ $ result = isset ($ operation ->result ) ? $ operation ->result : null ;
213+
214+ if (isset ($ result ->errorContains )) {
215+ $ o ->messageContains = $ result ->errorContains ;
216+ $ o ->isExpected = true ;
217+ }
218+
219+ if (isset ($ result ->errorCodeName )) {
220+ $ o ->codeName = $ result ->errorCodeName ;
221+ $ o ->isExpected = true ;
222+ }
223+
224+ if (isset ($ result ->errorLabelsContain )) {
225+ if (! self ::isArrayOfStrings ($ result ->errorLabelsContain )) {
226+ throw InvalidArgumentException::invalidType ('errorLabelsContain ' , $ result ->errorLabelsContain , 'string[] ' );
227+ }
228+ $ o ->includedLabels = $ result ->errorLabelsContain ;
229+ $ o ->isExpected = true ;
230+ }
231+
232+ if (isset ($ result ->errorLabelsOmit )) {
233+ if (! self ::isArrayOfStrings ($ result ->errorLabelsOmit )) {
234+ throw InvalidArgumentException::invalidType ('errorLabelsOmit ' , $ result ->errorLabelsOmit , 'string[] ' );
235+ }
236+ $ o ->excludedLabels = $ result ->errorLabelsOmit ;
237+ $ o ->isExpected = true ;
238+ }
239+
240+ return $ o ;
241+ }
242+
235243 private static function isArrayOfStrings ($ array )
236244 {
237245 if (! is_array ($ array )) {
0 commit comments