Skip to content

Commit

Permalink
Added $nullable option in HasOneStrateg/HasManyStrategy (default to
Browse files Browse the repository at this point in the history
true)
  • Loading branch information
leogr committed Jun 24, 2015
1 parent b6d5a3e commit 13c79e9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion library/Hydrator/Strategy/HasManyStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ class HasManyStrategy implements StrategyInterface, NullableStrategyInterface
*
* @param HydratorAwareInterface $objectPrototype
* @param \ArrayAccess $arrayObjectPrototype
* @param bool $nullable
*/
public function __construct(
HydratorAwareInterface $objectPrototype,
\ArrayAccess $arrayObjectPrototype = null
\ArrayAccess $arrayObjectPrototype = null,
$nullable = true
) {
$this->hasOneStrategy = new HasOneStrategy($objectPrototype);
$this->arrayObjectPrototype = $arrayObjectPrototype ? $arrayObjectPrototype : new ArrayObject([], ArrayObject::ARRAY_AS_PROPS);
$this->setNullable($nullable);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions library/Hydrator/Strategy/HasOneStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ class HasOneStrategy implements StrategyInterface, NullableStrategyInterface
/**
* Ctor
*
* @param $objectPrototype
* @param HydratorAwareInterface $objectPrototype
* @param bool $nullable
*/
public function __construct(HydratorAwareInterface $objectPrototype, $nullable = false)
public function __construct(HydratorAwareInterface $objectPrototype, $nullable = true)
{
$this->objectPrototype = $objectPrototype;
$this->setNullable($nullable);
Expand Down
2 changes: 1 addition & 1 deletion tests/Hydrator/Strategy/HasOneStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HasOneStrategyTest extends \PHPUnit_Framework_TestCase
public function testConstructor()
{
$abstractObject = $this->getMockForAbstractClass('\Matryoshka\Model\Object\AbstractObject');
$strategy = new HasOneStrategy($abstractObject, new \ArrayObject());
$strategy = new HasOneStrategy($abstractObject);
$this->assertInstanceOf('Matryoshka\Model\Hydrator\Strategy\NullableStrategyInterface', $strategy);
$this->assertTrue($strategy->isNullable());
}
Expand Down

0 comments on commit 13c79e9

Please sign in to comment.