|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File contains Test 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
|
|
|
namespace eZ\Publish\Core\Persistence\Cache\Tests; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\SPI\Persistence\TransactionHandler; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Test case for Persistence\Cache\TransactionHandler. |
|
15
|
|
|
*/ |
|
16
|
|
|
class TransactionHandlerTest extends AbstractCacheHandlerTest |
|
17
|
|
|
{ |
|
18
|
|
|
public function getHandlerMethodName(): string |
|
19
|
|
|
{ |
|
20
|
|
|
return 'transactionHandler'; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function getHandlerClassName(): string |
|
24
|
|
|
{ |
|
25
|
|
|
return TransactionHandler::class; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function providerForUnCachedMethods(): array |
|
29
|
|
|
{ |
|
30
|
|
|
// string $method, array $arguments, array? $tags, string? $key |
|
31
|
|
|
return [ |
|
32
|
|
|
['beginTransaction', []], |
|
33
|
|
|
['commit', []], |
|
34
|
|
|
]; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function providerForCachedLoadMethods(): array |
|
38
|
|
|
{ |
|
39
|
|
|
// string $method, array $arguments, string $key, mixed? $data |
|
40
|
|
|
return [ |
|
41
|
|
|
]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\TransactionHandler::rollback |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testRollback() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->loggerMock |
|
50
|
|
|
->expects($this->once()) |
|
51
|
|
|
->method('logCall'); |
|
52
|
|
|
|
|
53
|
|
|
$this->cacheMock |
|
54
|
|
|
->expects($this->once()) |
|
55
|
|
|
->method('clear'); |
|
56
|
|
|
|
|
57
|
|
|
$this->cacheMock |
|
58
|
|
|
->expects($this->once()) |
|
59
|
|
|
->method('stopTransaction'); |
|
60
|
|
|
|
|
61
|
|
|
$innerHandlerMock = $this->createMock(TransactionHandler::class); |
|
62
|
|
|
$this->persistenceHandlerMock |
|
63
|
|
|
->expects($this->once()) |
|
64
|
|
|
->method('transactionHandler') |
|
65
|
|
|
->will($this->returnValue($innerHandlerMock)); |
|
66
|
|
|
|
|
67
|
|
|
$innerHandlerMock |
|
68
|
|
|
->expects($this->once()) |
|
69
|
|
|
->method('rollback'); |
|
70
|
|
|
|
|
71
|
|
|
$handler = $this->persistenceCacheHandler->transactionHandler(); |
|
72
|
|
|
$handler->rollback(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\TransactionHandler::commit |
|
77
|
|
|
*/ |
|
78
|
|
View Code Duplication |
public function testCommitStopsCacheTransaction() |
|
79
|
|
|
{ |
|
80
|
|
|
$this->loggerMock |
|
81
|
|
|
->expects($this->once()) |
|
82
|
|
|
->method('logCall'); |
|
83
|
|
|
|
|
84
|
|
|
$this->cacheMock |
|
85
|
|
|
->expects($this->once()) |
|
86
|
|
|
->method('stopTransaction'); |
|
87
|
|
|
|
|
88
|
|
|
$innerHandlerMock = $this->createMock(TransactionHandler::class); |
|
89
|
|
|
$this->persistenceHandlerMock |
|
90
|
|
|
->expects($this->once()) |
|
91
|
|
|
->method('transactionHandler') |
|
92
|
|
|
->will($this->returnValue($innerHandlerMock)); |
|
93
|
|
|
|
|
94
|
|
|
$innerHandlerMock |
|
95
|
|
|
->expects($this->once()) |
|
96
|
|
|
->method('commit'); |
|
97
|
|
|
|
|
98
|
|
|
$handler = $this->persistenceCacheHandler->transactionHandler(); |
|
99
|
|
|
$handler->commit(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\TransactionHandler::beginTransaction |
|
104
|
|
|
*/ |
|
105
|
|
View Code Duplication |
public function testBeginTransactionStartsCacheTransaction() |
|
106
|
|
|
{ |
|
107
|
|
|
$this->loggerMock |
|
108
|
|
|
->expects($this->once()) |
|
109
|
|
|
->method('logCall'); |
|
110
|
|
|
|
|
111
|
|
|
$this->cacheMock |
|
112
|
|
|
->expects($this->once()) |
|
113
|
|
|
->method('startTransaction'); |
|
114
|
|
|
|
|
115
|
|
|
$innerHandlerMock = $this->createMock(TransactionHandler::class); |
|
116
|
|
|
$this->persistenceHandlerMock |
|
117
|
|
|
->expects($this->once()) |
|
118
|
|
|
->method('transactionHandler') |
|
119
|
|
|
->will($this->returnValue($innerHandlerMock)); |
|
120
|
|
|
|
|
121
|
|
|
$innerHandlerMock |
|
122
|
|
|
->expects($this->once()) |
|
123
|
|
|
->method('beginTransaction'); |
|
124
|
|
|
|
|
125
|
|
|
$handler = $this->persistenceCacheHandler->transactionHandler(); |
|
126
|
|
|
$handler->beginTransaction(); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|