Commit 5d7c37bd by Jin Hu

Incorrect array representation when has previous

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