mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-13 04:38:03 +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) {
|
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(
|
||||||
|
|||||||
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