Completed
Push — master ( dcc2fa...fd2fad )
by Christian
02:34
created

MappedStatementRepositoryTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 99
Duplicated Lines 34.34 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 7
c 1
b 1
f 0
lcom 1
cbo 3
dl 34
loc 99
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testStatementDocumentIsPersisted() 12 12 1
A testFlushIsCalledByDefault() 11 11 1
A testCallToFlushCanBeSuppressed() 11 11 1
getObjectManagerClass() 0 1 ?
A createObjectManagerMock() 0 7 1
getUnitOfWorkClass() 0 1 ?
A createUnitOfWorkMock() 0 7 1
getClassMetadataClass() 0 1 ?
A createClassMetadataMock() 0 7 1
createMappedStatementRepository() 0 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 xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
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 XApi\Repository\Doctrine\Test\Unit\Repository;
13
14
use Xabbuh\XApi\DataFixtures\StatementFixtures;
15
use XApi\Repository\Api\Mapping\MappedStatement;
16
use XApi\Repository\Doctrine\Repository\MappedStatementRepository;
17
18
/**
19
 * @author Christian Flothmann <[email protected]>
20
 */
21
abstract class MappedStatementRepositoryTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var \PHPUnit_Framework_MockObject_MockObject
25
     */
26
    private $objectManager;
27
28
    /**
29
     * @var \PHPUnit_Framework_MockObject_MockObject
30
     */
31
    private $unitOfWork;
32
33
    /**
34
     * @var \PHPUnit_Framework_MockObject_MockObject
35
     */
36
    private $classMetadata;
37
38
    /**
39
     * @var MappedStatementRepository
40
     */
41
    private $repository;
42
43
    protected function setUp()
44
    {
45
        $this->objectManager = $this->createObjectManagerMock();
46
        $this->unitOfWork = $this->createUnitOfWorkMock();
47
        $this->classMetadata = $this->createClassMetadataMock();
48
        $this->repository = $this->createMappedStatementRepository($this->objectManager, $this->unitOfWork, $this->classMetadata);
49
    }
50
51 View Code Duplication
    public function testStatementDocumentIsPersisted()
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
            ->objectManager
55
            ->expects($this->once())
56
            ->method('persist')
57
            ->with($this->isInstanceOf('\XApi\Repository\Api\Mapping\MappedStatement'))
58
        ;
59
60
        $mappedStatement = MappedStatement::createFromModel(StatementFixtures::getMinimalStatement());
61
        $this->repository->storeMappedStatement($mappedStatement, true);
62
    }
63
64 View Code Duplication
    public function testFlushIsCalledByDefault()
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...
65
    {
66
        $this
67
            ->objectManager
68
            ->expects($this->once())
69
            ->method('flush')
70
        ;
71
72
        $mappedStatement = MappedStatement::createFromModel(StatementFixtures::getMinimalStatement());
73
        $this->repository->storeMappedStatement($mappedStatement);
74
    }
75
76 View Code Duplication
    public function testCallToFlushCanBeSuppressed()
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...
77
    {
78
        $this
79
            ->objectManager
80
            ->expects($this->never())
81
            ->method('flush')
82
        ;
83
84
        $mappedStatement = MappedStatement::createFromModel(StatementFixtures::getMinimalStatement());
85
        $this->repository->storeMappedStatement($mappedStatement, false);
86
    }
87
88
    abstract protected function getObjectManagerClass();
89
90
    protected function createObjectManagerMock()
91
    {
92
        return $this
93
            ->getMockBuilder($this->getObjectManagerClass())
94
            ->disableOriginalConstructor()
95
            ->getMock();
96
    }
97
98
    abstract protected function getUnitOfWorkClass();
99
100
    protected function createUnitOfWorkMock()
101
    {
102
        return $this
103
            ->getMockBuilder($this->getUnitOfWorkClass())
104
            ->disableOriginalConstructor()
105
            ->getMock();
106
    }
107
108
    abstract protected function getClassMetadataClass();
109
110
    protected function createClassMetadataMock()
111
    {
112
        return $this
113
            ->getMockBuilder($this->getClassMetadataClass())
114
            ->disableOriginalConstructor()
115
            ->getMock();
116
    }
117
118
    abstract protected function createMappedStatementRepository($objectManager, $unitOfWork, $classMetadata);
119
}
120