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

ReflectionTest::testSecured()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
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\DataEntity;
16
use Spiral\Models\Reflection\ReflectionEntity;
17
use Spiral\Models\SchematicEntity;
18
19
class ReflectionTest extends TestCase
20
{
21
    public function testReflection(): void
22
    {
23
        $schema = new ReflectionEntity(TestModel::class);
24
        $this->assertEquals(new \ReflectionClass(TestModel::class), $schema->getReflection());
25
    }
26
27
    public function testFillable(): void
28
    {
29
        $schema = new ReflectionEntity(TestModel::class);
30
        $this->assertSame(['value'], $schema->getFillable());
31
    }
32
33
    public function testFillableExtended(): void
34
    {
35
        $schema = new ReflectionEntity(ExtendedModel::class);
36
        $this->assertSame(['value', 'name'], $schema->getFillable());
37
    }
38
39
    public function testSetters(): void
40
    {
41
        $schema = new ReflectionEntity(TestModel::class);
42
        $this->assertSame(
43
            [
44
                'value' => 'intval'
45
            ],
46
            $schema->getSetters()
47
        );
48
    }
49
50
    public function testSettersExtended(): void
51
    {
52
        $schema = new ReflectionEntity(ExtendedModel::class);
53
        $this->assertSame(
54
            [
55
                'value' => 'intval',
56
                'name'  => 'strval'
57
            ],
58
            $schema->getSetters()
59
        );
60
    }
61
62
    public function testSecured(): void
63
    {
64
        $schema = new ReflectionEntity(ExtendedModel::class);
65
        $this->assertSame(['name'], $schema->getSecured());
66
    }
67
68
    public function testDeclaredMethods(): void
69
    {
70
        $schema = new ReflectionEntity(ExtendedModel::class);
71
        $this->assertEquals(
72
            [
73
                new \ReflectionMethod(ExtendedModel::class, 'methodB')
74
            ],
75
            $schema->declaredMethods()
76
        );
77
    }
78
79
    public function testGetSecured(): void
80
    {
81
        $schema = new ReflectionEntity(TestModel::class);
82
        $this->assertSame('*', $schema->getSecured());
83
    }
84
85
    public function testGetReflectionValues(): void
86
    {
87
        $schema = new ReflectionEntity(ExtendedModel::class);
88
89
        $this->assertSame([
90
            'value' => 'intval',
91
            'name'  => 'strtoupper'
92
        ], $schema->getGetters());
93
94
        $this->assertSame([
95
            'value' => 'intval',
96
            'name'  => 'strval'
97
        ], $schema->getSetters());
98
    }
99
100
    public function testGetSchema(): void
101
    {
102
        $schema = new ReflectionEntity(SchemaModel::class);
103
        $this->assertSame(['nice'], $schema->getSchema());
104
105
        $schema = new ReflectionEntity(SchemaModelB::class);
106
        $this->assertSame(['nice', 'nice2'], $schema->getSchema());
107
    }
108
109
    public function testGetSchemaNotSchematic(): void
110
    {
111
        $schema = new ReflectionEntity(SchemaModelC::class);
112
        $this->assertSame(['nice2'], $schema->getSchema());
113
    }
114
}
115