Skip to content

Commit bd278a7

Browse files
authored
test current implode behavior for collections with models (#54704)
1 parent 6e41df6 commit bd278a7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/Support/SupportCollectionTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Exception;
1010
use Illuminate\Contracts\Support\Arrayable;
1111
use Illuminate\Contracts\Support\Jsonable;
12+
use Illuminate\Database\Eloquent\Model;
1213
use Illuminate\Support\Collection;
1314
use Illuminate\Support\HtmlString;
1415
use Illuminate\Support\ItemNotFoundException;
@@ -2331,6 +2332,19 @@ public function testImplode($collection)
23312332
$this->assertSame('taylor-foo,dayle-bar', $data->implode(fn ($user) => $user['name'].'-'.$user['email'], ','));
23322333
}
23332334

2335+
#[DataProvider('collectionClassProvider')]
2336+
public function testImplodeModels($collection)
2337+
{
2338+
$model = new class extends Model {};
2339+
$model->setAttribute('email', 'foo');
2340+
$modelTwo = new class extends Model {};
2341+
$modelTwo->setAttribute('email', 'bar');
2342+
$data = new $collection([$model, $modelTwo]);
2343+
2344+
$this->assertSame('foobar', $data->implode('email'));
2345+
$this->assertSame('foo,bar', $data->implode('email', ','));
2346+
}
2347+
23342348
#[DataProvider('collectionClassProvider')]
23352349
public function testTake($collection)
23362350
{

0 commit comments

Comments
 (0)