Skip to content

Commit 7737800

Browse files
authored
Merge branch 'codeigniter4:develop' into patch-2
2 parents 84fa8f0 + 8738340 commit 7737800

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of CodeIgniter 4 framework.
7+
*
8+
* (c) CodeIgniter Foundation <[email protected]>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
namespace Tests\Support\Entity;
15+
16+
use CodeIgniter\Entity\Entity;
17+
18+
class UserWithCasts extends Entity
19+
{
20+
protected $casts = [
21+
'email' => 'json',
22+
];
23+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of CodeIgniter 4 framework.
7+
*
8+
* (c) CodeIgniter Foundation <[email protected]>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
namespace Tests\Support\Models;
15+
16+
use CodeIgniter\Model;
17+
use Tests\Support\Entity\UserWithCasts;
18+
19+
class UserEntityWithCastsModel extends Model
20+
{
21+
protected $table = 'user';
22+
protected $allowedFields = [
23+
'name',
24+
'email',
25+
'country',
26+
'deleted_at',
27+
];
28+
protected $returnType = UserWithCasts::class;
29+
}

tests/system/Models/FindModelTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515

1616
use CodeIgniter\Database\Exceptions\DataException;
1717
use CodeIgniter\Exceptions\ModelException;
18+
use Tests\Support\Entity\UserWithCasts;
1819
use Tests\Support\Models\JobModel;
1920
use Tests\Support\Models\SecondaryModel;
21+
use Tests\Support\Models\UserEntityWithCastsModel;
2022
use Tests\Support\Models\UserModel;
2123

2224
/**
@@ -32,6 +34,24 @@ public function testFindReturnsRow(): void
3234
$this->assertSame('Musician', $this->model->find(4)->name);
3335
}
3436

37+
public function testFindReturnsEntityWithCasts(): void
38+
{
39+
$this->createModel(UserEntityWithCastsModel::class);
40+
$this->model->builder()->truncate();
41+
$user = new UserWithCasts([
42+
'name' => 'John Smith',
43+
44+
'country' => 'US',
45+
]);
46+
$id = $this->model->insert($user, true);
47+
48+
/** @var UserWithCasts $user */
49+
$user = $this->model->find($id);
50+
51+
$this->assertSame('John Smith', $user->name);
52+
$this->assertSame(['[email protected]', '[email protected]'], $user->email);
53+
}
54+
3555
public function testFindReturnsMultipleRows(): void
3656
{
3757
$this->createModel(JobModel::class);

0 commit comments

Comments
 (0)