PayPalModel Set Conditions updated

- passing null to setter would unset the value
- passing empty string would set the value as empty string
- passing 0 would set the value as 0
- Fixes #285
This commit is contained in:
Jay Patel
2015-04-15 11:59:48 -05:00
parent 553589e511
commit ec58775bca
2 changed files with 26 additions and 1 deletions

View File

@@ -106,7 +106,7 @@ class PayPalModel
public function __set($key, $value) public function __set($key, $value)
{ {
ModelAccessorValidator::validate($this, $this->convertToCamelCase($key)); ModelAccessorValidator::validate($this, $this->convertToCamelCase($key));
if (!is_array($value) && $value == null) { if (!is_array($value) && $value === null) {
$this->__unset($key); $this->__unset($key);
} else { } else {
$this->_propMap[$key] = $value; $this->_propMap[$key] = $value;

View File

@@ -8,6 +8,7 @@ class SimpleModelTestClass extends PayPalModel
* *
* @access public * @access public
* @param string $field1 * @param string $field1
* @return self
*/ */
public function setField1($field1) public function setField1($field1)
{ {
@@ -29,6 +30,7 @@ class SimpleModelTestClass extends PayPalModel
* *
* @access public * @access public
* @param string $field2 * @param string $field2
* @return self
*/ */
public function setField2($field2) public function setField2($field2)
{ {
@@ -264,6 +266,29 @@ class PayPalModelTest extends PHPUnit_Framework_TestCase
$parentCopy = new ListModelTestClass(); $parentCopy = new ListModelTestClass();
$parentCopy->fromJson($parent->toJSON()); $parentCopy->fromJson($parent->toJSON());
$this->assertEquals($parent, $parentCopy); $this->assertEquals($parent, $parentCopy);
}
public function EmptyNullProvider()
{
return array(
array(0, true),
array(null, false),
array("", true),
array("null", true),
array(-1, true),
array('', true)
);
}
/**
* @dataProvider EmptyNullProvider
* @param string|null $field2
* @param bool $matches
*/
public function testEmptyNullConversion($field2, $matches)
{
$c1 = new SimpleModelTestClass();
$c1->setField1("a")->setField2($field2);
$this->assertTrue(strpos($c1->toJSON(),"field2") !== !$matches);
} }
} }