Skip to content

Commit

Permalink
fix unapply
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis84 committed Sep 11, 2015
1 parent d772c9b commit 1f95e10
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public function unapply($input)
$result[$name] = $child->unapply($input[$name]);
}
}

if (0 === count($result)) {
$result = null;
}
}

$data->setResult($result);
Expand Down
25 changes: 25 additions & 0 deletions tests/UnapplyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,29 @@ public function testG()
$this->assertSame('dennis', $result['username']);
$this->assertNull($result['password']);
}

public function testH()
{
$factory = new Factory;
$mapping = $factory->mapping([
'username' => $factory->mapping(),
'password' => $factory->mapping(),
'address' => $factory->mapping([
'city' => $factory->mapping(),
'street' => $factory->mapping(),
]),
]);

$result = $mapping->unapply([
'username' => 'dennis',
'password' => 'passwd',
'address' => null,
]);

$this->assertSame([
'username' => 'dennis',
'password' => 'passwd',
'address' => null,
], $result);
}
}

0 comments on commit 1f95e10

Please sign in to comment.