Passed
Push — main ( c84275...1d7014 )
by Gabriel
03:41
created

CastableTraitTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 22
c 1
b 0
f 1
dl 0
loc 33
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_castsDatetime() 0 9 1
A test_transformInboundValue_Datetime() 0 20 1
1
<?php
2
3
namespace ByTIC\DataObjects\Tests\Behaviors\Castable;
4
5
use ByTIC\DataObjects\Tests\AbstractTest;
6
use ByTIC\DataObjects\Tests\Fixtures\Models\Books\Book;
7
use Nip\Utility\Date;
8
9
/**
10
 * Class CastableTraitTest
11
 * @package ByTIC\DataObjects\Tests\Behaviors\Castable
12
 */
13
class CastableTraitTest extends AbstractTest
14
{
15
    public function test_castsDatetime()
16
    {
17
        $book = new Book();
18
        $date = date('Y-m-d');
19
        $book->published = $date;
0 ignored issues
show
Bug Best Practice introduced by
The property published does not exist on ByTIC\DataObjects\Tests\Fixtures\Models\Books\Book. Since you implemented __set, consider adding a @property annotation.
Loading history...
20
21
        $dateGet = $book->published;
0 ignored issues
show
Bug Best Practice introduced by
The property published does not exist on ByTIC\DataObjects\Tests\Fixtures\Models\Books\Book. Since you implemented __get, consider adding a @property annotation.
Loading history...
22
        self::assertInstanceOf(\DateTime::class, $dateGet);
23
        self::assertSame($date, $dateGet->format('Y-m-d'));
24
    }
25
26
    public function test_transformInboundValue_Datetime()
27
    {
28
        $book = new Book();
29
        $date = date('Y-m-d');
30
        $book->published = $date;
0 ignored issues
show
Bug Best Practice introduced by
The property published does not exist on ByTIC\DataObjects\Tests\Fixtures\Models\Books\Book. Since you implemented __set, consider adding a @property annotation.
Loading history...
31
32
        $dateGet = $book->published;
0 ignored issues
show
Bug Best Practice introduced by
The property published does not exist on ByTIC\DataObjects\Tests\Fixtures\Models\Books\Book. Since you implemented __get, consider adding a @property annotation.
Loading history...
33
        self::assertInstanceOf(\DateTime::class, $dateGet);
34
        self::assertSame($date, $dateGet->format('Y-m-d'));
35
        self::assertSame($date . ' 00:00:00', $book->getPropertyRaw('published'));
36
37
        $book = new Book();
38
        $date = Date::now();
39
        $book->published = $date;
40
41
        $dateGet = $book->published;
42
        $dateFormatted = $dateGet->format('Y-m-d H:i:s');
43
        self::assertInstanceOf(\DateTime::class, $dateGet);
44
        self::assertSame($dateFormatted, $dateGet->format('Y-m-d H:i:s'));
45
        self::assertSame($dateFormatted, $book->getPropertyRaw('published'));
46
    }
47
}
48