Completed
Push — feature-EZP-25696 ( 52d929...5f47d3 )
by André
23:51
created

RepositoryTest::testCommit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 13
loc 13
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Repository\Tests\Service\Mock\RepositoryTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 *
9
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\Core\Repository\Tests\Service\Mock;
12
13
use eZ\Publish\Core\Repository\Tests\Service\Mock\Base as BaseServiceMockTest;
14
15
/**
16
 * Mock test case for Repository.
17
 */
18
class RepositoryTest extends BaseServiceMockTest
19
{
20
    /**
21
     * Test for the beginTransaction() method.
22
     *
23
     * @covers \eZ\Publish\API\Repository\Repository::beginTransaction
24
     */
25
    public function testBeginTransaction()
26
    {
27
        $mockedRepository = $this->getRepository();
28
        $persistenceHandlerMock = $this->getPersistenceMock();
29
30
        $persistenceHandlerMock->expects(
31
            $this->once()
32
        )->method(
33
            'beginTransaction'
34
        );
35
36
        $mockedRepository->beginTransaction();
37
    }
38
39
    /**
40
     * Test for the commit() method.
41
     *
42
     * @covers \eZ\Publish\API\Repository\Repository::commit
43
     */
44 View Code Duplication
    public function testCommit()
45
    {
46
        $mockedRepository = $this->getRepository();
47
        $persistenceHandlerMock = $this->getPersistenceMock();
48
49
        $persistenceHandlerMock->expects(
50
            $this->once()
51
        )->method(
52
            'commit'
53
        );
54
55
        $mockedRepository->commit();
56
    }
57
58
    /**
59
     * Test for the commit() method.
60
     *
61
     * @covers \eZ\Publish\API\Repository\Repository::commit
62
     * @expectedException \RuntimeException
63
     */
64 View Code Duplication
    public function testCommitThrowsRuntimeException()
65
    {
66
        $mockedRepository = $this->getRepository();
67
        $persistenceHandlerMock = $this->getPersistenceMock();
68
69
        $persistenceHandlerMock->expects(
70
            $this->once()
71
        )->method(
72
            'commit'
73
        )->will(
74
            $this->throwException(new \Exception())
75
        );
76
77
        $mockedRepository->commit();
78
    }
79
80
    /**
81
     * Test for the rollback() method.
82
     *
83
     * @covers \eZ\Publish\API\Repository\Repository::rollback
84
     */
85 View Code Duplication
    public function testRollback()
86
    {
87
        $mockedRepository = $this->getRepository();
88
        $persistenceHandlerMock = $this->getPersistenceMock();
89
90
        $persistenceHandlerMock->expects(
91
            $this->once()
92
        )->method(
93
            'rollback'
94
        );
95
96
        $mockedRepository->rollback();
97
    }
98
99
    /**
100
     * Test for the rollback() method.
101
     *
102
     * @covers \eZ\Publish\API\Repository\Repository::rollback
103
     * @expectedException \RuntimeException
104
     */
105 View Code Duplication
    public function testRollbackThrowsRuntimeException()
106
    {
107
        $mockedRepository = $this->getRepository();
108
        $persistenceHandlerMock = $this->getPersistenceMock();
109
110
        $persistenceHandlerMock->expects(
111
            $this->once()
112
        )->method(
113
            'rollback'
114
        )->will(
115
            $this->throwException(new \Exception())
116
        );
117
118
        $mockedRepository->rollback();
119
    }
120
}
121