Completed
Push — master ( 7888fa...8e3a44 )
by Ivannis Suárez
04:39
created

ClassMetadataTests::testAddPropertyMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 15

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 15
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\ClassMetadata;
15
use Cubiche\Core\Metadata\MethodMetadata;
16
use Cubiche\Core\Metadata\PropertyMetadata;
17
use Cubiche\Core\Metadata\Tests\Fixtures\Address;
18
use Cubiche\Core\Metadata\Tests\Fixtures\User;
19
20
/**
21
 * ClassMetadataTests class.
22
 *
23
 * Generated by TestGenerator on 2017-05-16 at 13:17:21.
24
 */
25
class ClassMetadataTests extends TestCase
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function createClassMetadata($className)
31
    {
32
        return new ClassMetadata($className);
33
    }
34
35
    /**
36
     * Test ClassName method.
37
     */
38
    public function testClassName()
39
    {
40
        $this
41
            ->given($className = User::class)
42
            ->when($classMetadata = $this->createClassMetadata($className))
43
            ->then()
44
                ->string($classMetadata->className())
45
                    ->isEqualTo($className)
46
        ;
47
    }
48
49
    /**
50
     * Test Reflection method.
51
     */
52
    public function testReflection()
53
    {
54
        $this
55
            ->given($className = User::class)
56
            ->when($classMetadata = $this->createClassMetadata($className))
57
            ->then()
58
                ->object($classMetadata->reflection())
59
                    ->isInstanceOf(\ReflectionClass::class)
60
                ->string($classMetadata->reflection()->name)
61
                    ->isEqualTo($className)
62
        ;
63
    }
64
65
    /**
66
     * Test AddMethodMetadata method.
67
     */
68 View Code Duplication
    public function testAddMethodMetadata()
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...
69
    {
70
        $this
71
            ->given($className = User::class)
72
            ->and($methodMetadata = new MethodMetadata($className, 'username'))
73
            ->when($classMetadata = $this->createClassMetadata($className))
74
            ->then()
75
                ->array($classMetadata->methodsMetadata())
76
                    ->isEmpty()
77
                ->and()
78
                ->when($classMetadata->addMethodMetadata($methodMetadata))
79
                ->then()
80
                    ->array($classMetadata->methodsMetadata())
81
                        ->hasKey('username')
82
                    ->object($classMetadata->methodMetadata('username'))
83
                        ->isEqualTo($methodMetadata)
84
        ;
85
    }
86
87
    /**
88
     * Test AddPropertyMetadata method.
89
     */
90 View Code Duplication
    public function testAddPropertyMetadata()
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...
91
    {
92
        $this
93
            ->given($className = User::class)
94
            ->and($propertyMetadata = new PropertyMetadata($className, 'username'))
95
            ->when($classMetadata = $this->createClassMetadata($className))
96
            ->then()
97
                ->array($classMetadata->propertiesMetadata())
98
                    ->isEmpty()
99
                ->and()
100
                ->when($classMetadata->addPropertyMetadata($propertyMetadata))
101
                ->then()
102
                    ->array($classMetadata->propertiesMetadata())
103
                        ->hasKey('username')
104
                    ->object($classMetadata->propertyMetadata('username'))
105
                        ->isEqualTo($propertyMetadata)
106
        ;
107
    }
108
109
    /**
110
     * Test merge method.
111
     */
112
    public function testMerge()
113
    {
114
        $this
115
            ->given($classMetadata = $this->createClassMetadata(User::class))
116
            ->and($classMetadata->addPropertyMetadata(new PropertyMetadata(User::class, 'email')))
117
            ->and($classMetadata->addMethodMetadata(new MethodMetadata(User::class, 'username')))
118
            ->and($classMetadata1 = $this->createClassMetadata(User::class))
119
            ->and($classMetadata1->addPropertyMetadata(new PropertyMetadata(User::class, 'age')))
120
            ->and($classMetadata1->addMethodMetadata(new MethodMetadata(User::class, 'addresses')))
121
            ->then()
122
                ->array($classMetadata->propertiesMetadata())
123
                    ->hasSize(1)
124
                    ->notHasKey('age')
125
                ->array($classMetadata->methodsMetadata())
126
                    ->hasSize(1)
127
                    ->notHasKey('addresses')
128
                ->and()
129
                ->when($classMetadata->merge($classMetadata1))
130
                ->then()
131
                    ->array($classMetadata->propertiesMetadata())
132
                        ->hasSize(2)
133
                        ->hasKey('age')
134
                    ->array($classMetadata->methodsMetadata())
135
                        ->hasSize(2)
136
                        ->hasKey('addresses')
137
        ;
138
    }
139
140
    /**
141
     * Test Serialize/Unserialize method.
142
     */
143
    public function testSerialize()
144
    {
145
        $this
146
            ->given($classMetadata = $this->createClassMetadata(User::class))
147
            ->and($classMetadata->addMethodMetadata(new MethodMetadata(User::class, 'username')))
148
            ->and($classMetadata->addMethodMetadata(new MethodMetadata(User::class, 'email')))
149
            ->and($classMetadata1 = $this->createClassMetadata(Address::class))
150
            ->and($classMetadata1->addMethodMetadata(new MethodMetadata(Address::class, 'city')))
151
            ->when($classMetadata->unserialize($classMetadata1->serialize()))
152
            ->then()
153
                ->string($classMetadata->className())
154
                    ->isEqualTo(Address::class)
155
                ->array($classMetadata->methodsMetadata())
156
                    ->hasKey('city')
157
        ;
158
    }
159
}
160