Passed
Push — master ( db5c4e...adaaa2 )
by Kirill
03:03
created

SchematicEntityTest::getSetters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 17
rs 9.9332
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Models;
13
14
use PHPUnit\Framework\TestCase;
15
use Spiral\Models\ModelSchema;
16
use Spiral\Models\SchematicEntity;
17
18
class SchematicEntityTest extends TestCase
19
{
20
    public function testFillable(): void
21
    {
22
        $schema = [ModelSchema::SECURED => []];
23
24
        $data = ['a' => 1, 'b' => 2, 'c' => 3];
25
26
        $entity = new SchematicEntity([], $schema);
27
        $entity->setFields($data);
28
        $this->assertSame($data, $entity->getFields());
29
    }
30
31
    public function testFillable2(): void
32
    {
33
        $schema = [ModelSchema::FILLABLE => '*'];
34
35
        $data = ['a' => 1, 'b' => 2, 'c' => 3];
36
37
        $entity = new SchematicEntity([], $schema);
38
        $entity->setFields($data);
39
        $this->assertSame($data, $entity->getFields());
40
    }
41
42
    public function testSecured(): void
43
    {
44
        $schema = [ModelSchema::SECURED => '*'];
45
46
        $data = ['a' => 1, 'b' => 2, 'c' => 3];
47
48
        $entity = new SchematicEntity([], $schema);
49
        $entity->setFields($data);
50
        $this->assertSame([], $entity->getFields());
51
    }
52
53
    public function testPartiallySecured(): void
54
    {
55
        $schema = [
56
            ModelSchema::SECURED  => '*',
57
            ModelSchema::FILLABLE => ['a', 'b'],
58
        ];
59
60
        $data = ['a' => 1, 'b' => 2, 'c' => 3];
61
62
        $entity = new SchematicEntity([], $schema);
63
        $entity->setFields($data);
64
        $this->assertSame(['a' => 1, 'b' => 2], $entity->getFields());
65
    }
66
67
    public function getSetters(): void
68
    {
69
        $schema = [
70
            ModelSchema::MUTATORS => [
71
                'setter' => ['a' => 'intval'],
72
            ],
73
        ];
74
75
        $entity = new SchematicEntity([], $schema);
76
        $entity->setField('a', '123');
77
78
        $this->assertInternalType('int', $entity->getField('a'));
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

78
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType('int', $entity->getField('a'));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
79
        $this->assertSame(123, $entity->getField('a'));
80
81
        $entity->a = '800';
0 ignored issues
show
Bug Best Practice introduced by
The property a does not exist on Spiral\Models\SchematicEntity. Since you implemented __set, consider adding a @property annotation.
Loading history...
82
        $this->assertInternalType('int', $entity->a);
0 ignored issues
show
Bug Best Practice introduced by
The property a does not exist on Spiral\Models\SchematicEntity. Since you implemented __get, consider adding a @property annotation.
Loading history...
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

82
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType('int', $entity->a);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
83
        $this->assertSame(800, $entity->a);
84
    }
85
86
    public function testGetters(): void
87
    {
88
        $schema = [
89
            ModelSchema::MUTATORS => [
90
                'getter' => ['a' => 'intval'],
91
            ],
92
        ];
93
94
        $entity = new SchematicEntity([], $schema);
95
96
        $entity->setField('a', false);
97
        $this->assertInternalType('int', $entity->getField('a'));
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

97
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType('int', $entity->getField('a'));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
98
        $this->assertInternalType('bool', $entity->getValue()['a']);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

98
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType('bool', $entity->getValue()['a']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
99
100
        $entity->a = 8000.1;
0 ignored issues
show
Bug Best Practice introduced by
The property a does not exist on Spiral\Models\SchematicEntity. Since you implemented __set, consider adding a @property annotation.
Loading history...
101
        $this->assertInternalType('int', $entity->a);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

101
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType('int', $entity->a);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Bug Best Practice introduced by
The property a does not exist on Spiral\Models\SchematicEntity. Since you implemented __get, consider adding a @property annotation.
Loading history...
102
        $this->assertInternalType('float', $entity->getValue()['a']);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

102
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType('float', $entity->getValue()['a']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
103
    }
104
}
105