DriverTestCase   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 73
Duplicated Lines 15.07 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 11
loc 73
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
createDriver() 0 1 ?
A testLoadMetadataForClass() 0 47 1
A testGetAllClassNames() 11 11 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\ClassMetadata;
15
use Cubiche\Core\Metadata\Driver\DriverInterface;
16
use Cubiche\Core\Metadata\Exception\MappingException;
17
use Cubiche\Core\Metadata\Tests\Fixtures\Address;
18
use Cubiche\Core\Metadata\Tests\Fixtures\User;
19
use Cubiche\Core\Metadata\Tests\Units\TestCase;
20
21
/**
22
 * DriverTestCase class.
23
 *
24
 * Generated by TestGenerator on 2017-05-16 at 13:17:21.
25
 */
26
abstract class DriverTestCase extends TestCase
27
{
28
    /**
29
     * @return DriverInterface
30
     */
31
    abstract protected function createDriver();
32
33
    /**
34
     * Test loadMetadataForClass method.
35
     */
36
    public function testLoadMetadataForClass()
37
    {
38
        $this
39
            ->given($driver = $this->createDriver())
40
            ->then()
41
                ->exception(function () use ($driver) {
42
                    $driver->loadMetadataForClass('Cubiche\Core\Metadata\Tests\Fixtures\Post');
43
                })->isInstanceOf(MappingException::class)
44
                ->exception(function () use ($driver) {
45
                    $driver->loadMetadataForClass('Cubiche\Core\Metadata\Tests\Fixtures\Blog');
46
                })->isInstanceOf(MappingException::class)
47
        ;
48
49
        $this
50
            ->given($driver = $this->createDriver())
51
            ->when($classMetadata = $driver->loadMetadataForClass(User::class))
52
            ->then()
53
                ->object($classMetadata)
54
                    ->isInstanceOf(ClassMetadata::class)
55
                ->array($classMetadata->propertiesMetadata())
56
                    ->hasSize(7)
57
                    ->hasKey('id')
58
                    ->hasKey('name')
59
                    ->hasKey('username')
60
                    ->hasKey('age')
61
                    ->hasKey('email')
62
                    ->hasKey('addresses')
63
                    ->hasKey('friends')
64
                ->object($propertyMetadata = $classMetadata->propertyMetadata('id'))
65
                    ->isNotNull()
66
                ->boolean($propertyMetadata->getMetadata('identifier'))
67
                    ->isTrue()
68
                ->string($propertyMetadata->getMetadata('name'))
69
                    ->isEqualTo('_id')
70
                ->string($classMetadata->propertyMetadata('name')->getMetadata('name'))
71
                    ->isEqualTo('fullName')
72
                ->string($classMetadata->propertyMetadata('addresses')->getMetadata('type'))
73
                    ->isEqualTo('ArraySet')
74
                ->string($classMetadata->propertyMetadata('addresses')->getMetadata('of'))
75
                    ->isEqualTo('Cubiche\Core\Metadata\Tests\Fixtures\Address')
76
            ->and()
77
            ->when($classMetadata = $driver->loadMetadataForClass(User::class))
78
            ->then()
79
                ->object($classMetadata)
80
                    ->isInstanceOf(ClassMetadata::class)
81
        ;
82
    }
83
84
    /**
85
     * Test getAllClassNames method.
86
     */
87 View Code Duplication
    public function testGetAllClassNames()
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...
88
    {
89
        $this
90
            ->given($driver = $this->createDriver())
91
            ->when($classNames = $driver->getAllClassNames())
92
            ->then()
93
                ->array($classNames)
94
                    ->contains(User::class)
95
                    ->contains(Address::class)
96
        ;
97
    }
98
}
99