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

ChainDriverTests   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 107
Duplicated Lines 13.08 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 14
loc 107
c 0
b 0
f 0
wmc 5
lcom 1
cbo 5
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createDriver() 14 14 1
A createDriverWithDefaultDriver() 0 10 1
A createEmptyDriver() 0 4 1
B testLoadMetadataForClass() 0 39 1
A testGetAllClassNames() 0 18 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Driver;
13
14
use Cubiche\Core\Metadata\Driver\ChainDriver;
15
use Cubiche\Core\Metadata\Exception\MappingException;
16
use Cubiche\Core\Metadata\Locator\DefaultFileLocator;
17
use Cubiche\Core\Metadata\Tests\Fixtures\Address;
18
use Cubiche\Core\Metadata\Tests\Fixtures\Driver\XmlDriver;
19
use Cubiche\Core\Metadata\Tests\Fixtures\Driver\YamlDriver;
20
use Cubiche\Core\Metadata\Tests\Fixtures\User;
21
22
/**
23
 * ChainDriverTests class.
24
 *
25
 * Generated by TestGenerator on 2017-05-16 at 13:17:21.
26
 */
27
class ChainDriverTests extends DriverTestCase
28
{
29
    /**
30
     * @return ChainDriver
31
     */
32 View Code Duplication
    protected function createDriver()
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...
33
    {
34
        $mappingDirectory = __DIR__.'/../../Fixtures/mapping';
35
36
        $ymlDriver = new YamlDriver(
37
            new DefaultFileLocator([$mappingDirectory => 'Cubiche\Core\Metadata\Tests\Fixtures'])
38
        );
39
40
        $xmlDriver = new XmlDriver(
41
            new DefaultFileLocator([$mappingDirectory => 'Cubiche\Core\Metadata\Tests'])
42
        );
43
44
        return new ChainDriver([$ymlDriver, $xmlDriver]);
45
    }
46
47
    /**
48
     * @return ChainDriver
49
     */
50
    protected function createDriverWithDefaultDriver()
51
    {
52
        $mappingDirectory = __DIR__.'/../../Fixtures/mapping';
53
54
        $ymlDriver = new YamlDriver(
55
            new DefaultFileLocator([$mappingDirectory => 'Cubiche\Core\Metadata\Tests\Fixtures'])
56
        );
57
58
        return new ChainDriver([], $ymlDriver);
59
    }
60
61
    /**
62
     * @return ChainDriver
63
     */
64
    protected function createEmptyDriver()
65
    {
66
        return new ChainDriver();
67
    }
68
69
    /**
70
     * Test LoadMetadataForClass method.
71
     */
72
    public function testLoadMetadataForClass()
73
    {
74
        parent::testLoadMetadataForClass();
75
76
        $this
77
            ->given($driver = $this->createDriverWithDefaultDriver())
78
            ->when($classMetadata = $driver->loadMetadataForClass(User::class))
79
            ->then()
80
                ->array($classMetadata->propertiesMetadata())
81
                    ->hasSize(7)
82
                    ->hasKey('id')
83
                    ->hasKey('name')
84
                    ->hasKey('username')
85
                    ->hasKey('age')
86
                    ->hasKey('email')
87
                    ->hasKey('addresses')
88
                    ->hasKey('friends')
89
                ->object($propertyMetadata = $classMetadata->propertyMetadata('id'))
90
                    ->isNotNull()
91
                ->boolean($propertyMetadata->getMetadata('identifier'))
92
                    ->isTrue()
93
                ->string($propertyMetadata->getMetadata('name'))
94
                    ->isEqualTo('_id')
95
                ->string($classMetadata->propertyMetadata('name')->getMetadata('name'))
96
                    ->isEqualTo('fullName')
97
                ->string($classMetadata->propertyMetadata('addresses')->getMetadata('type'))
98
                    ->isEqualTo('ArraySet')
99
                ->string($classMetadata->propertyMetadata('addresses')->getMetadata('of'))
100
                    ->isEqualTo('Cubiche\Core\Metadata\Tests\Fixtures\Address')
101
        ;
102
103
        $this
104
            ->given($driver = $this->createEmptyDriver())
105
            ->then()
106
                ->exception(function () use ($driver) {
107
                    $driver->loadMetadataForClass(User::class);
108
                })->isInstanceOf(MappingException::class)
109
        ;
110
    }
111
112
    /**
113
     * Test GetAllClassNames method.
114
     */
115
    public function testGetAllClassNames()
116
    {
117
        parent::testGetAllClassNames();
118
119
        $this
120
            ->given($driver = $this->createDriverWithDefaultDriver())
121
            ->when($classNames = $driver->getAllClassNames())
122
            ->then()
123
                ->array($classNames)
124
                    ->contains(User::class)
125
                    ->contains(Address::class)
126
                ->and()
127
                ->when($driver = $this->createEmptyDriver())
128
                ->then()
129
                    ->array($driver->getAllClassNames())
130
                        ->isEmpty()
131
        ;
132
    }
133
}
134