Skip to content

Commit a3aee78

Browse files
committed
bug #120 Factories may return NULL (dragosprotung)
This PR was merged into the 0.2-dev branch. Discussion ---------- Factories may return NULL Commits ------- 8eab9c4 Factories may return NULL
2 parents 61c09ea + 8eab9c4 commit a3aee78

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/Qossmic/DataTransformer/ValueObjectTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function transform($value)
7373
return $this->getPropertyValue($this->form, $value);
7474
}
7575

76-
public function reverseTransform($value): object
76+
public function reverseTransform($value): ?object
7777
{
7878
try {
7979
return (new ViewDataInstantiator($this->form, $value))->instantiateObject();

src/Qossmic/Instantiator/ObjectInstantiator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct($factory)
3131
$this->factory = $factory;
3232
}
3333

34-
public function instantiateObject(): object
34+
public function instantiateObject(): ?object
3535
{
3636
if (\is_string($this->factory)) {
3737
$factoryMethod = (new \ReflectionClass($this->factory))->getConstructor();

tests/Integration/FactoryTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@
2121

2222
class FactoryTest extends AbstractDataMapperTest
2323
{
24+
public function testFactoryReturnsNull(): void
25+
{
26+
$form = $this->createForm(GrossPriceType::class, null, [
27+
'factory' => function () {
28+
return null;
29+
},
30+
]);
31+
$form->submit([
32+
'amount' => '500',
33+
'taxRate' => '7',
34+
]);
35+
36+
$this->assertNull($form->getData());
37+
}
38+
2439
public function testInitializeNonCompoundRootFormWithEmptyData(): void
2540
{
2641
$form = $this->createForm(PriceType::class, null, [

0 commit comments

Comments
 (0)