Skip to content

Commit 701d6bf

Browse files
#39729: Cannot return null for non-nullable field
- Refactor tests to improve callback formatting.
1 parent d44689d commit 701d6bf

File tree

1 file changed

+56
-44
lines changed

1 file changed

+56
-44
lines changed

app/code/Magento/QuoteGraphQl/Test/Unit/Model/Resolver/CustomizableOptionsTest.php

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,24 @@ public function testResolveReturnsCustomizableOptionsData(): void
152152

153153
$this->customizableOptionMock->expects($this->exactly(3))
154154
->method('getData')
155-
->willReturnCallback(function ($cartItem, $optionId) use ($expectedOptionData1, $expectedOptionData2, $expectedOptionData3) {
156-
switch ($optionId) {
157-
case 1:
158-
return $expectedOptionData1;
159-
case 2:
160-
return $expectedOptionData2;
161-
case 3:
162-
return $expectedOptionData3;
163-
default:
164-
return [];
155+
->willReturnCallback(
156+
function ($unused, $optionId) use (
157+
$expectedOptionData1,
158+
$expectedOptionData2,
159+
$expectedOptionData3
160+
) {
161+
switch ($optionId) {
162+
case 1:
163+
return $expectedOptionData1;
164+
case 2:
165+
return $expectedOptionData2;
166+
case 3:
167+
return $expectedOptionData3;
168+
default:
169+
return [];
170+
}
165171
}
166-
});
172+
);
167173

168174
$result = $this->resolver->resolve($this->fieldMock, null, $this->resolveInfoMock, $value);
169175

@@ -201,18 +207,20 @@ public function testResolveSkipsEmptyCustomizableOptions(): void
201207

202208
$this->customizableOptionMock->expects($this->exactly(3))
203209
->method('getData')
204-
->willReturnCallback(function ($cartItem, $optionId) use ($expectedOptionData1, $expectedOptionData3) {
205-
switch ($optionId) {
206-
case 1:
207-
return $expectedOptionData1;
208-
case 2:
209-
return [];
210-
case 3:
211-
return $expectedOptionData3;
212-
default:
213-
return [];
210+
->willReturnCallback(
211+
function ($unused, $optionId) use ($expectedOptionData1, $expectedOptionData3) {
212+
switch ($optionId) {
213+
case 1:
214+
return $expectedOptionData1;
215+
case 2:
216+
return [];
217+
case 3:
218+
return $expectedOptionData3;
219+
default:
220+
return [];
221+
}
214222
}
215-
});
223+
);
216224

217225
$result = $this->resolver->resolve($this->fieldMock, null, $this->resolveInfoMock, $value);
218226

@@ -272,18 +280,20 @@ public function testResolveHandlesMixedNullAndEmptyArrayReturns(): void
272280

273281
$this->customizableOptionMock->expects($this->exactly(4))
274282
->method('getData')
275-
->willReturnCallback(function ($cartItem, $optionId) use ($expectedOptionData1) {
276-
switch ($optionId) {
277-
case 1:
278-
return $expectedOptionData1;
279-
case 2:
280-
case 3:
281-
case 4:
282-
return [];
283-
default:
284-
return [];
283+
->willReturnCallback(
284+
function ($unused, $optionId) use ($expectedOptionData1) {
285+
switch ($optionId) {
286+
case 1:
287+
return $expectedOptionData1;
288+
case 2:
289+
case 3:
290+
case 4:
291+
return [];
292+
default:
293+
return [];
294+
}
285295
}
286-
});
296+
);
287297

288298
$result = $this->resolver->resolve($this->fieldMock, null, $this->resolveInfoMock, $value);
289299

@@ -419,18 +429,20 @@ public function testResolveHandlesDeletedCustomOption(): void
419429

420430
$this->customizableOptionMock->expects($this->exactly(3))
421431
->method('getData')
422-
->willReturnCallback(function ($cartItem, $optionId) use ($validOption1, $validOption2) {
423-
switch ($optionId) {
424-
case 1:
425-
return $validOption1;
426-
case 999:
427-
return [];
428-
case 2:
429-
return $validOption2;
430-
default:
431-
return [];
432+
->willReturnCallback(
433+
function ($unused, $optionId) use ($validOption1, $validOption2) {
434+
switch ($optionId) {
435+
case 1:
436+
return $validOption1;
437+
case 999:
438+
return [];
439+
case 2:
440+
return $validOption2;
441+
default:
442+
return [];
443+
}
432444
}
433-
});
445+
);
434446

435447
$result = $this->resolver->resolve($this->fieldMock, null, $this->resolveInfoMock, $value);
436448

0 commit comments

Comments
 (0)