Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
json issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kkamkou committed Mar 5, 2012
1 parent 4e7b205 commit 71f9046
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/morph/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 6 additions & 8 deletions src/morph/property/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -126,6 +124,6 @@ public final function getName()
*/
public function __toString()
{
return (string)$this->getValue();
return $this->getValue();
}
}
13 changes: 8 additions & 5 deletions unit-tests/TestObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
class TestObject extends \PHPUnit_Framework_TestCase
{


public function testGetCollection()
{
$obj = new ForTesting();
Expand Down Expand Up @@ -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.