ChainDriverTests   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 106
Duplicated Lines 49.06 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

5 Methods

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