Skip to content

Commit 8b08abd

Browse files
committed
Add test;
1 parent 2ef0fa9 commit 8b08abd

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tests/Casts/ArrayTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MongoDB\Laravel\Tests\Casts;
6+
7+
use Illuminate\Support\Facades\DB;
8+
use MongoDB\Laravel\Tests\Models\Casting;
9+
use MongoDB\Laravel\Tests\TestCase;
10+
11+
class ArrayTest extends TestCase
12+
{
13+
protected function setUp(): void
14+
{
15+
parent::setUp();
16+
17+
Casting::truncate();
18+
}
19+
20+
public function testArray(): void
21+
{
22+
$model = Casting::query()->create(['arrayValue' => ["Dreamin' 'bout the spot that right now, I'm actually in", 'g-eazy' => 'Still']]);
23+
24+
self::assertIsArray($model->arrayValue);
25+
self::assertIsArray(
26+
DB::connection()
27+
->table((new Casting())->getTable())
28+
->where('id', $model->id)
29+
->first()->arrayValue
30+
);
31+
self::assertEquals(["Dreamin' 'bout the spot that right now, I'm actually in", 'g-eazy' => 'Still'], $model->arrayValue);
32+
33+
$model->update(['arrayValue' => ['What if I just said, f*ck it, never followed my dreams?']]);
34+
35+
self::assertIsArray($model->arrayValue);
36+
self::assertIsArray(
37+
DB::connection()
38+
->table((new Casting())->getTable())
39+
->where('id', $model->id)
40+
->first()->arrayValue
41+
);
42+
self::assertEquals(['What if I just said, f*ck it, never followed my dreams?'], $model->arrayValue);
43+
}
44+
}

tests/Models/Casting.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Casting extends Model
3636
'encryptedArray',
3737
'encryptedObject',
3838
'encryptedCollection',
39+
'arrayValue',
3940
];
4041

4142
protected $casts = [
@@ -60,5 +61,6 @@ class Casting extends Model
6061
'encryptedArray' => 'encrypted:array',
6162
'encryptedObject' => 'encrypted:object',
6263
'encryptedCollection' => 'encrypted:collection',
64+
'arrayValue' => 'array',
6365
];
6466
}

0 commit comments

Comments
 (0)