PropertyMetadataTests::testClassName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the Cubiche/Metadata component.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Core\Metadata\Tests\Units;
13
14
use Cubiche\Core\Metadata\PropertyMetadata;
15
use Cubiche\Core\Metadata\Tests\Fixtures\User;
16
use Cubiche\Core\Metadata\Tests\Fixtures\UserId;
17
18
/**
19
 * PropertyMetadataTests class.
20
 *
21
 * Generated by TestGenerator on 2017-05-16 at 13:17:21.
22
 */
23
class PropertyMetadataTests extends TestCase
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected function createPropertyMetadata($className, $propertyName)
29
    {
30
        return new PropertyMetadata($className, $propertyName);
31
    }
32
33
    /**
34
     * Test ClassName method.
35
     */
36 View Code Duplication
    public function testClassName()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        $this
39
            ->given($className = User::class)
40
            ->and($propertyName = 'username')
41
            ->when($propertyMetadata = $this->createPropertyMetadata($className, $propertyName))
42
            ->then()
43
                ->string($propertyMetadata->className())
44
                    ->isEqualTo($className)
45
        ;
46
    }
47
48
    /**
49
     * Test PropertyName method.
50
     */
51 View Code Duplication
    public function testPropertyName()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53
        $this
54
            ->given($className = User::class)
55
            ->and($propertyName = 'username')
56
            ->when($propertyMetadata = $this->createPropertyMetadata($className, $propertyName))
57
            ->then()
58
                ->string($propertyMetadata->propertyName())
59
                    ->isEqualTo($propertyName)
60
        ;
61
    }
62
63
    /**
64
     * Test metadata methods.
65
     */
66 View Code Duplication
    public function testMetadata()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        $this
69
            ->given($propertyMetadata = $this->createPropertyMetadata(User::class, 'id'))
70
            ->when($propertyMetadata->addMetadata('identifier', true))
71
            ->and($propertyMetadata->addMetadata('fieldName', '_id'))
72
            ->then()
73
                ->array($propertyMetadata->metadata())
74
                    ->hasKey('identifier')
75
                    ->hasKey('fieldName')
76
                ->boolean($propertyMetadata->getMetadata('identifier'))
77
                    ->isTrue()
78
                ->string($propertyMetadata->getMetadata('fieldName'))
79
                    ->isEqualTo('_id')
80
        ;
81
    }
82
83
    /**
84
     * Test Reflection method.
85
     */
86 View Code Duplication
    public function testReflection()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        $this
89
            ->given($className = User::class)
90
            ->and($propertyName = 'username')
91
            ->when($propertyMetadata = $this->createPropertyMetadata($className, $propertyName))
92
            ->then()
93
                ->object($propertyMetadata->reflection())
94
                    ->isInstanceOf(\ReflectionProperty::class)
95
                ->string($propertyMetadata->reflection()->class)
96
                    ->isEqualTo($className)
97
                ->string($propertyMetadata->reflection()->name)
98
                    ->isEqualTo($propertyName)
99
        ;
100
    }
101
102
    /**
103
     * Test GetValue method.
104
     */
105 View Code Duplication
    public function testGetValue()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
    {
107
        $this
108
            ->given($user = new User(UserId::next(), 'Ivan', 'ivannis', 36, '[email protected]'))
109
            ->when($propertyMetadata = $this->createPropertyMetadata(User::class, 'username'))
110
            ->then()
111
                ->string($propertyMetadata->getValue($user)->toNative())
112
                    ->isEqualTo('ivannis')
113
        ;
114
    }
115
116
    /**
117
     * Test SetValue method.
118
     */
119
    public function testSetValue()
120
    {
121
        $this
122
            ->given($user = new User(UserId::next(), 'Ivan', 'ivannis', 36, '[email protected]'))
123
            ->when($propertyMetadata = $this->createPropertyMetadata(User::class, 'username'))
124
            ->then()
125
                ->string($propertyMetadata->getValue($user)->toNative())
126
                    ->isEqualTo('ivannis')
127
                ->and()
128
                ->when($propertyMetadata->setValue($user, 'ivan'))
129
                ->then()
130
                    ->string($user->username())
131
                        ->isEqualTo('ivan')
132
        ;
133
    }
134
135
    /**
136
     * Test Serialize/Unserialize method.
137
     */
138 View Code Duplication
    public function testSerialize()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
139
    {
140
        $this
141
            ->given($propertyMetadata = $this->createPropertyMetadata(User::class, 'username'))
142
            ->and($propertyMetadata1 = $this->createPropertyMetadata(User::class, 'email'))
143
            ->when($propertyMetadata->unserialize($propertyMetadata1->serialize()))
144
            ->then()
145
                ->string($propertyMetadata->className())
146
                    ->isEqualTo(User::class)
147
                ->string($propertyMetadata->propertyName())
148
                    ->isEqualTo('email')
149
        ;
150
    }
151
}
152