Commit 5d7c37bd by Jin Hu

Incorrect array representation when has previous

parent efef0e52
......@@ -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(
......
<?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']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment