-
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.
- Loading branch information
Showing
2 changed files
with
61 additions
and
3 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
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,57 @@ | ||
<?php | ||
|
||
use Orchestra\Testbench\TestCase; | ||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* @group integration | ||
*/ | ||
class EloquentModelTest extends TestCase | ||
{ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$app['config']->set('app.debug', 'true'); | ||
|
||
$app['config']->set('database.default', 'testbench'); | ||
|
||
$app['config']->set('database.connections.testbench', [ | ||
'driver' => 'sqlite', | ||
'database' => ':memory:', | ||
'prefix' => '', | ||
]); | ||
} | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
Schema::create('users', function ($table) { | ||
$table->increments('id'); | ||
$table->timestamp('nullable_date')->nullable(); | ||
}); | ||
} | ||
|
||
public function test_user_can_update_nullable_date() | ||
{ | ||
$user = EloquentModelTestModel::create([ | ||
'nullable_date' => null, | ||
]); | ||
|
||
$user->fill([ | ||
'nullable_date' => $now = \Carbon\Carbon::now(), | ||
]); | ||
$this->assertTrue($user->isDirty('nullable_date')); | ||
|
||
$user->save(); | ||
$this->assertEquals($now->toDateString(), $user->nullable_date->toDateString()); | ||
} | ||
} | ||
|
||
class EloquentModelTestModel extends Model | ||
{ | ||
public $table = 'users'; | ||
public $timestamps = false; | ||
protected $guarded = ['id']; | ||
protected $dates = ['nullable_date']; | ||
} |