Skip to content

Commit

Permalink
Message 支持 json 序列化 overtrue/laravel-wechat#471
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Apr 14, 2023
1 parent f0d5294 commit bf84fca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Kernel/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace EasyWeChat\Kernel;

use ArrayAccess;
use EasyWeChat\Kernel\Contracts\Jsonable;
use EasyWeChat\Kernel\Exceptions\BadRequestException;
use EasyWeChat\Kernel\Support\Xml;
use EasyWeChat\Kernel\Traits\HasAttributes;
Expand All @@ -17,7 +18,7 @@
*
* @implements ArrayAccess<array-key, mixed>
*/
abstract class Message implements ArrayAccess
abstract class Message implements ArrayAccess, Jsonable, \JsonSerializable
{
use HasAttributes;

Expand Down
6 changes: 6 additions & 0 deletions tests/Kernel/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ public function test_message()
$this->assertSame($message->one, 1);
$this->assertSame($message['one'], 1);
}

public function test_message_can_be_encode_as_json()
{
$message = new Message(['one' => 1]);
$this->assertSame(json_encode($message), '{"one":1}');
}
}

1 comment on commit bf84fca

@vercel
Copy link

@vercel vercel bot commented on bf84fca Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

easywechat – ./

easywechat-git-6x-overtrue.vercel.app
easywechat.vercel.app
easywechat-overtrue.vercel.app

Please sign in to comment.