1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cino\LaravelChronos\Tests\Database; |
4
|
|
|
|
5
|
|
|
use Cake\Chronos\Chronos; |
6
|
|
|
use Cake\Chronos\ChronosInterface; |
7
|
|
|
use Cino\LaravelChronos\Eloquent\Model; |
8
|
|
|
use Illuminate\Database\Schema\Blueprint; |
9
|
|
|
|
10
|
|
|
class EloquentModelReturnsDatesTest extends EloquentTestCase |
11
|
|
|
{ |
12
|
|
|
protected function createSchema(): void |
13
|
|
|
{ |
14
|
|
|
$this->schema()->create('articles', function (Blueprint $table) { |
15
|
|
|
$table->increments('id'); |
16
|
|
|
$table->date('date'); |
17
|
|
|
$table->dateTime('datetime'); |
18
|
|
|
$table->timestamps(); |
19
|
|
|
}); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
protected function seedData(): void |
23
|
|
|
{ |
24
|
|
|
EloquentModelReturnsDatesArticle::query()->create(['date' => Chronos::now(), 'datetime' => Chronos::now()]); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function tearDown(): void |
28
|
|
|
{ |
29
|
|
|
$this->schema()->drop('articles'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testDateFieldsReturnChronos(): void |
33
|
|
|
{ |
34
|
|
|
$this->seedData(); |
35
|
|
|
|
36
|
|
|
$article = EloquentModelReturnsDatesArticle::query()->first(); |
37
|
|
|
|
38
|
|
|
$this->assertInstanceOf(ChronosInterface::class, $article->created_at); |
39
|
|
|
$this->assertInstanceOf(ChronosInterface::class, $article->date); |
|
|
|
|
40
|
|
|
$this->assertInstanceOf(ChronosInterface::class, $article->datetime); |
|
|
|
|
41
|
|
|
$this->assertInstanceOf(ChronosInterface::class, $article->updated_at); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
class EloquentModelReturnsDatesArticle extends Model |
46
|
|
|
{ |
47
|
|
|
protected $dates = ['date', 'datetime']; |
48
|
|
|
|
49
|
|
|
protected $fillable = ['date', 'datetime']; |
50
|
|
|
|
51
|
|
|
protected $table = 'articles'; |
52
|
|
|
} |
53
|
|
|
|