Completed
Push — master ( 2f57a2...d63f8e )
by Christian
02:21
created

testStatementDocumentIsPersisted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
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\Mapping;
13
14
use Xabbuh\XApi\DataFixtures\StatementFixtures;
15
use XApi\Repository\Doctrine\Mapping\Statement;
16
use XApi\Repository\Doctrine\Repository\Mapping\StatementRepository;
17
18
/**
19
 * @author Christian Flothmann <[email protected]>
20
 */
21
abstract class StatementRepositoryTest 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 StatementRepository
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\Doctrine\Mapping\Statement'))
58
        ;
59
60
        $mappedStatement = Statement::fromModel(StatementFixtures::getMinimalStatement());
61
        $this->repository->storeStatement($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 = Statement::fromModel(StatementFixtures::getMinimalStatement());
73
        $this->repository->storeStatement($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 = Statement::fromModel(StatementFixtures::getMinimalStatement());
85
        $this->repository->storeStatement($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