Skip to content

Commit 8a9986d

Browse files
author
Ben Plunkett
committed
Allow for initial null state for container property in ContainerAwareTrait
1 parent 9cac7b9 commit 8a9986d

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/Neto/Container/ContainerAwareTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
trait ContainerAwareTrait
88
{
9-
/** @var ContainerInterface */
9+
/** @var ContainerInterface|null */
1010
private $container;
1111

1212
/**
@@ -22,9 +22,9 @@ public function setContainer(ContainerInterface $container)
2222
}
2323

2424
/**
25-
* @return ContainerInterface
25+
* @return ContainerInterface|null
2626
*/
27-
public function getContainer(): ContainerInterface
27+
public function getContainer(): ?ContainerInterface
2828
{
2929
return $this->container;
3030
}

tests/ContainerAwareTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@ public function testTraitGetsAndSetsContainer()
1717
$trait->setContainer($container);
1818
$this->assertSame($container, $trait->getContainer());
1919
}
20-
}
20+
21+
public function testTraitCanGetNullContainer()
22+
{
23+
$trait = $this->getMockForTrait(ContainerAwareTrait::class);
24+
$this->assertNull($trait->getContainer());
25+
}
26+
}

0 commit comments

Comments
 (0)