-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'pr/26882' of https://github.com/themsaid/framework into…
… themsaid-pr/26882
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/Integration/Database/EloquentModelDateCastingTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Database\EloquentModelDateCastingTest; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Tests\Integration\Database\DatabaseTestCase; | ||
|
||
/** | ||
* @group integration | ||
*/ | ||
class EloquentModelDateCastingTest extends DatabaseTestCase | ||
{ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
Schema::create('test_model1', function ($table) { | ||
$table->increments('id'); | ||
$table->date('date_field')->nullable(); | ||
$table->datetime('datetime_field')->nullable(); | ||
}); | ||
} | ||
|
||
public function test_user_can_update_nullable_date() | ||
{ | ||
$user = TestModel1::create([ | ||
'date_field' => '2019-10-01', | ||
'datetime_field' => '2019-10-01 10:15:20', | ||
]); | ||
|
||
$this->assertEquals('2019-10', $user->toArray()['date_field']); | ||
$this->assertEquals('2019-10 10:15', $user->toArray()['datetime_field']); | ||
$this->assertInstanceOf(Carbon::class, $user->date_field); | ||
$this->assertInstanceOf(Carbon::class, $user->datetime_field); | ||
} | ||
} | ||
|
||
class TestModel1 extends Model | ||
{ | ||
public $table = 'test_model1'; | ||
public $timestamps = false; | ||
protected $guarded = ['id']; | ||
protected $dates = ['date_field', 'datetime_field']; | ||
|
||
public $casts = [ | ||
'date_field' => 'date:Y-m', | ||
'datetime_field' => 'datetime:Y-m H:i', | ||
]; | ||
} |