Skip to content
Browse files

the null issue

  • Loading branch information...
1 parent ec45937 commit 25a4a2ebd2fa82e40482a58bf3b79bc551fd8308 @kkamkou kkamkou committed Jan 29, 2012
Showing with 12 additions and 1 deletion.
  1. +5 −1 src/morph/property/String.php
  2. +7 −0 unit-tests/property/TestProperties.php
View
6 src/morph/property/String.php
@@ -37,6 +37,10 @@ public function __construct($name, $default = null, $maximumLength = null){
* @param integer $Value
*/
public function setValue($value){
+ if (null === $value) {
+ return parent::setValue($value);
+ }
+
$cleanValue = (string)$value;
if(!empty($this->maximumLength)
&& ($this->_getUnicodeValue('strlen', $cleanValue) > $this->maximumLength) ){
@@ -53,7 +57,7 @@ public function setValue($value){
* @return string
*/
public function getValue(){
- return (string)parent::getValue();
+ return (null === parent::getValue()) ? null : (string)parent::getValue();
}
/**
View
7 unit-tests/property/TestProperties.php
@@ -53,6 +53,13 @@ public function testStringProperty()
$property->setValue($string . $string);
$this->assertEquals($stringLength, iconv_strlen($property->getValue()));
+
+ $property->setValue(null);
+ $this->assertNull($property->getValue());
+
+ $default = 'ABCАБВ';
+ $propertyWithDefault = new String('NameSecond', $default);
+ $this->assertEquals($default, $propertyWithDefault->getValue());
}
public function testIntegerProperty()

0 comments on commit 25a4a2e

Please sign in to comment.
Something went wrong with that request. Please try again.