diff --git a/lib/PayPal/Common/PayPalModel.php b/lib/PayPal/Common/PayPalModel.php index d90287a..8a7b177 100644 --- a/lib/PayPal/Common/PayPalModel.php +++ b/lib/PayPal/Common/PayPalModel.php @@ -106,7 +106,7 @@ class PayPalModel public function __set($key, $value) { ModelAccessorValidator::validate($this, $this->convertToCamelCase($key)); - if (!is_array($value) && $value == null) { + if (!is_array($value) && $value === null) { $this->__unset($key); } else { $this->_propMap[$key] = $value; diff --git a/tests/PayPal/Test/Common/PayPalModelTest.php b/tests/PayPal/Test/Common/PayPalModelTest.php index b518cc5..d6bbef6 100644 --- a/tests/PayPal/Test/Common/PayPalModelTest.php +++ b/tests/PayPal/Test/Common/PayPalModelTest.php @@ -8,6 +8,7 @@ class SimpleModelTestClass extends PayPalModel * * @access public * @param string $field1 + * @return self */ public function setField1($field1) { @@ -29,6 +30,7 @@ class SimpleModelTestClass extends PayPalModel * * @access public * @param string $field2 + * @return self */ public function setField2($field2) { @@ -264,6 +266,29 @@ class PayPalModelTest extends PHPUnit_Framework_TestCase $parentCopy = new ListModelTestClass(); $parentCopy->fromJson($parent->toJSON()); $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); } }