createMappedStatementRepository()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
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 PHPUnit\Framework\TestCase;
15
use Xabbuh\XApi\DataFixtures\StatementFixtures;
16
use XApi\Repository\Doctrine\Mapping\Statement;
17
use XApi\Repository\Doctrine\Repository\Mapping\StatementRepository;
18
19
/**
20
 * @author Christian Flothmann <[email protected]>
21
 */
22
abstract class StatementRepositoryTest extends TestCase
23
{
24
    /**
25
     * @var \PHPUnit_Framework_MockObject_MockObject
26
     */
27
    private $objectManager;
28
29
    /**
30
     * @var \PHPUnit_Framework_MockObject_MockObject
31
     */
32
    private $unitOfWork;
33
34
    /**
35
     * @var \PHPUnit_Framework_MockObject_MockObject
36
     */
37
    private $classMetadata;
38
39
    /**
40
     * @var StatementRepository
41
     */
42
    private $repository;
43
44
    protected function setUp()
45
    {
46
        $this->objectManager = $this->createObjectManagerMock();
47
        $this->unitOfWork = $this->createUnitOfWorkMock();
48
        $this->classMetadata = $this->createClassMetadataMock();
49
        $this->repository = $this->createMappedStatementRepository($this->objectManager, $this->unitOfWork, $this->classMetadata);
50
    }
51
52 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...
53
    {
54
        $this
55
            ->objectManager
56
            ->expects($this->once())
57
            ->method('persist')
58
            ->with($this->isInstanceOf('\XApi\Repository\Doctrine\Mapping\Statement'))
59
        ;
60
61
        $mappedStatement = Statement::fromModel(StatementFixtures::getMinimalStatement());
62
        $this->repository->storeStatement($mappedStatement, true);
63
    }
64
65 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...
66
    {
67
        $this
68
            ->objectManager
69
            ->expects($this->once())
70
            ->method('flush')
71
        ;
72
73
        $mappedStatement = Statement::fromModel(StatementFixtures::getMinimalStatement());
74
        $this->repository->storeStatement($mappedStatement);
75
    }
76
77 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...
78
    {
79
        $this
80
            ->objectManager
81
            ->expects($this->never())
82
            ->method('flush')
83
        ;
84
85
        $mappedStatement = Statement::fromModel(StatementFixtures::getMinimalStatement());
86
        $this->repository->storeStatement($mappedStatement, false);
87
    }
88
89
    abstract protected function getObjectManagerClass();
90
91
    protected function createObjectManagerMock()
92
    {
93
        return $this
94
            ->getMockBuilder($this->getObjectManagerClass())
95
            ->disableOriginalConstructor()
96
            ->getMock();
97
    }
98
99
    abstract protected function getUnitOfWorkClass();
100
101
    protected function createUnitOfWorkMock()
102
    {
103
        return $this
104
            ->getMockBuilder($this->getUnitOfWorkClass())
105
            ->disableOriginalConstructor()
106
            ->getMock();
107
    }
108
109
    abstract protected function getClassMetadataClass();
110
111
    protected function createClassMetadataMock()
112
    {
113
        return $this
114
            ->getMockBuilder($this->getClassMetadataClass())
115
            ->disableOriginalConstructor()
116
            ->getMock();
117
    }
118
119
    abstract protected function createMappedStatementRepository($objectManager, $unitOfWork, $classMetadata);
120
}
121