Browse Source

Incorrect array representation when has previous

tags/2.0.0-beta
Jin Hu 11 years ago
parent
commit
5d7c37bd7e
  1. 8
      framework/yii/base/Exception.php
  2. 23
      tests/unit/framework/base/ExceptionTest.php

8
framework/yii/base/Exception.php

@ -41,10 +41,10 @@ class Exception extends \Exception implements Arrayable
{
if ($exception instanceof self) {
$array = array(
'type' => get_class($this),
'name' => $this->getName(),
'message' => $this->getMessage(),
'code' => $this->getCode(),
'type' => get_class($exception),
'name' => $exception->getName(),
'message' => $exception->getMessage(),
'code' => $exception->getCode(),
);
} else {
$array = array(

23
tests/unit/framework/base/ExceptionTest.php

@ -0,0 +1,23 @@
<?php
namespace yiiunit\framework\base;
use yii\test\TestCase;
use yii\base\UserException;
use yii\base\InvalidCallException;
class ExceptionTest extends TestCase
{
public function testToArrayWithPrevious()
{
$e = new InvalidCallException('bar', 0 ,new InvalidCallException('foo'));
$array = $e->toArray();
$this->assertEquals('bar', $array['message']);
$this->assertEquals('foo', $array['previous']['message']);
$e = new InvalidCallException('bar', 0 ,new UserException('foo'));
$array = $e->toArray();
$this->assertEquals('bar', $array['message']);
$this->assertEquals('foo', $array['previous']['message']);
}
}
Loading…
Cancel
Save