Skip to content

Commit

Permalink
Let the MessageBag handle arrayable items
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot authored and taylorotwell committed Aug 16, 2017
1 parent cec46b0 commit 6f1f4d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Support/MessageBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MessageBag implements Arrayable, Countable, Jsonable, JsonSerializable, Me
public function __construct(array $messages = [])
{
foreach ($messages as $key => $value) {
$this->messages[$key] = (array) $value;
$this->messages[$key] = $value instanceof Arrayable ? $value->toArray() : (array) $value;
}
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Support/SupportMessageBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Mockery as m;
use PHPUnit\Framework\TestCase;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;

class SupportMessageBagTest extends TestCase
Expand Down Expand Up @@ -49,6 +50,15 @@ public function testMessageBagsCanBeMerged()
$this->assertEquals(['foo' => ['bar', 'baz'], 'bar' => ['foo']], $container->getMessages());
}

public function testMessageBagsCanConvertToArrays()
{
$container = new MessageBag([
Collection::make(['foo', 'bar']),
Collection::make(['baz', 'qux']),
]);
$this->assertSame([['foo', 'bar'], ['baz', 'qux']], $container->getMessages());
}

public function testGetReturnsArrayOfMessagesByKey()
{
$container = new MessageBag;
Expand Down

0 comments on commit 6f1f4d8

Please sign in to comment.