Passed
Push — main ( 03d564...d959bf )
by Gabriel
03:34
created

PropertyOverloadingTest::test_setIfEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 13
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 17
rs 9.8333
1
<?php
2
3
namespace ByTIC\DataObjects\Tests\Behaviors\PropertyOverloading;
4
5
use ByTIC\DataObjects\BaseDto;
6
use ByTIC\DataObjects\Tests\AbstractTest;
7
8
/**
9
 * Class PropertyOverloadingTest
10
 * @package ByTIC\DataObjects\Tests\Behaviors\PropertyOverloading
11
 */
12
class PropertyOverloadingTest extends AbstractTest
13
{
14
    public function test_fill()
15
    {
16
        $object = new BaseDto();
17
        $object->fill(['test1' => 'value1']);
18
        self::assertSame('value1', $object->test1);
0 ignored issues
show
Bug Best Practice introduced by
The property test1 does not exist on ByTIC\DataObjects\BaseDto. Since you implemented __get, consider adding a @property annotation.
Loading history...
19
20
        $object->fill(['test1' => 'value11','test2' => 'value2']);
21
        self::assertSame('value11', $object->test1);
22
        self::assertSame('value2', $object->test2);
0 ignored issues
show
Bug Best Practice introduced by
The property test2 does not exist on ByTIC\DataObjects\BaseDto. Since you implemented __get, consider adding a @property annotation.
Loading history...
23
    }
24
25
    public function test_setIf()
26
    {
27
        $object = new BaseDto();
28
        $object->exist = 456;
0 ignored issues
show
Bug Best Practice introduced by
The property exist does not exist on ByTIC\DataObjects\BaseDto. Since you implemented __set, consider adding a @property annotation.
Loading history...
29
30
        $object->setIf('dnx1', 123, true);
31
        $object->setIf('dnx2', 123, false);
32
        $object->setIf('exist', 123, false);
33
34
        self::assertSame(123, $object->get('dnx1'));
35
        self::assertSame(null, $object->get('dnx2'));
36
        self::assertSame(456, $object->get('exist'));
37
    }
38
39
    public function test_setIfNull()
40
    {
41
        $object = new BaseDto();
42
        $object->exist = 456;
0 ignored issues
show
Bug Best Practice introduced by
The property exist does not exist on ByTIC\DataObjects\BaseDto. Since you implemented __set, consider adding a @property annotation.
Loading history...
43
        self::assertFalse($object->has('dnx'));
44
        self::assertNull($object->get('dnx'));
45
46
        $object->setIfNull('dnx', 123);
47
        $object->setIfNull('dnx', 123);
48
49
        self::assertSame(123, $object->get('dnx'));
50
        self::assertSame(456, $object->get('exist'));
51
    }
52
53
    public function test_setIfEmpty()
54
    {
55
        $object = new BaseDto();
56
        $object->exist = 456;
0 ignored issues
show
Bug Best Practice introduced by
The property exist does not exist on ByTIC\DataObjects\BaseDto. Since you implemented __set, consider adding a @property annotation.
Loading history...
57
        $object->dnx1 = '';
0 ignored issues
show
Bug Best Practice introduced by
The property dnx1 does not exist on ByTIC\DataObjects\BaseDto. Since you implemented __set, consider adding a @property annotation.
Loading history...
58
        $object->dnx2 = '0';
0 ignored issues
show
Bug Best Practice introduced by
The property dnx2 does not exist on ByTIC\DataObjects\BaseDto. Since you implemented __set, consider adding a @property annotation.
Loading history...
59
        $object->dnx3 = null;
0 ignored issues
show
Bug Best Practice introduced by
The property dnx3 does not exist on ByTIC\DataObjects\BaseDto. Since you implemented __set, consider adding a @property annotation.
Loading history...
60
61
        $object->setIfEmpty('dnx1', 123);
62
        $object->setIfEmpty('dnx2', 123);
63
        $object->setIfEmpty('dnx3', 123);
64
        $object->setIfEmpty('exist', 123);
65
66
        self::assertSame(123, $object->get('dnx1'));
67
        self::assertSame(123, $object->get('dnx2'));
68
        self::assertSame(123, $object->get('dnx3'));
69
        self::assertSame(456, $object->get('exist'));
70
    }
71
}
72