mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-12 11:40:19 +08:00
Merge pull request #920 from bixuehujin/fixed-exception-toarray
Incorrect array representation when has previous exception
This commit is contained in:
@@ -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
Normal file
23
tests/unit/framework/base/ExceptionTest.php
Normal file
@@ -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']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user