EloquentModelReturnsDatesTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
c 2
b 0
f 0
dl 0
loc 32
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A seedData() 0 3 1
A testDateFieldsReturnChronos() 0 10 1
A tearDown() 0 3 1
A createSchema() 0 7 1
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);
0 ignored issues
show
Bug introduced by
The property date does not exist on Cino\LaravelChronos\Test...odelReturnsDatesArticle. Did you mean dates?
Loading history...
40
        $this->assertInstanceOf(ChronosInterface::class, $article->datetime);
0 ignored issues
show
Bug introduced by
The property datetime does not seem to exist on Cino\LaravelChronos\Test...odelReturnsDatesArticle. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
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