Browse files

json issue

  • Loading branch information...
1 parent 4e7b205 commit 71f9046d1fda05d921d3a8505f479308d451fd1e @kkamkou kkamkou committed Mar 5, 2012
Showing with 15 additions and 14 deletions.
  1. +1 −1 src/morph/Object.php
  2. +6 −8 src/morph/property/Generic.php
  3. +8 −5 unit-tests/TestObject.php
View
2 src/morph/Object.php
@@ -303,7 +303,7 @@ public function __toString()
// iterate through all the properties this object has and print them out
foreach ($this->propertySet as $name => $property) {
- $data[$name] = (string)$property;
+ $data[$name] = $property->__toString();
}
return \json_encode($data);
View
14 src/morph/property/Generic.php
@@ -32,27 +32,25 @@ class Generic
* @var mixed
*/
protected $value;
-
+
/**
* The current state of this property
- *
+ *
* @see Morph_Enum::STATE_*
* @var string
*/
protected $state = \morph\Enum::STATE_NEW;
/**
- *
- * @param $name
- * @param $default
- * @return ar_Field
+ * @param string $name
+ * @param mixed $default
*/
public function __construct($name, $default = null)
{
$this->name = $name;
$this->value = $default;
}
-
+
/**
* @return string
*/
@@ -126,6 +124,6 @@ public function __setRawValue($value, $state = null)
*/
public function __toString()
{
- return (string)$this->getValue();
+ return $this->getValue();
}
}
View
13 unit-tests/TestObject.php
@@ -13,8 +13,6 @@
*/
class TestObject extends \PHPUnit_Framework_TestCase
{
-
-
public function testGetCollection()
{
$obj = new ForTesting();
@@ -75,8 +73,13 @@ public function test__toString()
{
$expected = '{"Id":null,"State":"New","testField":"TEST"}';
$obj = new ForTesting();
+
$obj->testField = 'TEST';
- $this->assertEquals($expected, $obj->__toString());
- }
+ $this->assertEquals($expected, (string)$obj);
-}
+ // null test
+ $expected = '{"Id":null,"State":"New","testField":null}';
+ $obj->testField = null;
+ $this->assertEquals($expected, (string)$obj);
+ }
+}

0 comments on commit 71f9046

Please sign in to comment.