Newer
Older
<?php
namespace Higidi\Lock\Tests\Unit\Configuration;
use Higidi\Lock\Configuration\Configuration;
use Higidi\Lock\Strategy\MutexAdapterStrategy;
use Nimut\TestingFramework\TestCase\UnitTestCase;
use NinjaMutex\Lock\LockInterface;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
use NinjaMutex\Mutex;
use TYPO3\CMS\Core\Locking\LockingStrategyInterface;
use TYPO3\CMS\Core\Locking\SimpleLockStrategy;
use TYPO3\CMS\Core\SingletonInterface;
/**
* Test case for "\Higidi\Lock\Configuration\Configuration".
*
* @covers \Higidi\Lock\Configuration\Configuration
*/
class ConfigurationTest extends UnitTestCase
{
/**
* @var bool
*/
protected $backupGlobals = true;
/**
* @test
*/
public function itIsASingleton()
{
$sut = new Configuration();
$this->assertInstanceOf(SingletonInterface::class, $sut);
}
/**
* @test
*/
public function itCanBeEnabledByInitializingGlobalsConfigurationArray()
{
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locking'] = [];
$sut = new Configuration();
$this->assertTrue($sut->isActive());
}
/**
* @return array
*/
public function activeStatusDataProvider()
{
return [
'disabled' => [false],
'enabled' => [true],
];
}
/**
* @test
* @dataProvider activeStatusDataProvider
*
* @param bool $active
*/
public function itIsPossibleToActivateOrDeactivateViaGlobalsConfigurationArray($active)
{
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locking'] = [
'active' => $active,
];
$sut = new Configuration();
$this->assertSame($active, $sut->isActive());
}
/**
* @test
* @dataProvider activeStatusDataProvider
*
* @param bool $active
*/
public function itIsPossibleToActivateOrDeactivateViaConfigurationArray($active)
{
$configuration = [
'active' => $active,
];
$sut = new Configuration($configuration);
$this->assertSame($active, $sut->isActive());
}
/**
* @test
*/
public function itIsPossibleToSetStrategyViaGlobalsConfigurationArray()
{
$strategy = $this->prophesize(LockingStrategyInterface::class)->reveal();
$className = get_class($strategy);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locking'] = [
'strategy' => $className,
];
$sut = new Configuration();
$this->assertSame($className, $sut->getStrategy());
}
/**
* @test
*/
public function itIsPossibleToSetStrategyViaConfigurationArray()
{
$strategy = $this->prophesize(LockingStrategyInterface::class)->reveal();
$className = get_class($strategy);
$configuration = [
'active' => true,
'strategy' => $className,
];
$sut = new Configuration($configuration);
$this->assertSame($className, $sut->getStrategy());
}
/**
* @test
*/
public function itIsPossibleToSetMutexViaGlobalsConfigurationArray()
{
$mutex = $this->prophesize(Mutex::class)->reveal();
$className = get_class($mutex);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locking'] = [
'mutex' => $className,
];
$sut = new Configuration();
$this->assertSame($className, $sut->getMutex());
}
/**
* @test
*/
public function itIsPossibleToSetMutexViaConfigurationArray()
{
$mutex = $this->prophesize(Mutex::class)->reveal();
$className = get_class($mutex);
$configuration = [
'active' => true,
'mutex' => $className,
];
$sut = new Configuration($configuration);
$this->assertSame($className, $sut->getMutex());
}
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/**
* @test
*/
public function itIsPossibleToSetLockImplementationViaGlobalsConfigurationArray()
{
$lockImplementation = $this->prophesize(LockInterface::class)->reveal();
$className = get_class($lockImplementation);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locking'] = [
'lockImplementation' => $className,
];
$sut = new Configuration();
$this->assertSame($className, $sut->getLockImplementation());
}
/**
* @test
*/
public function itIsPossibleToSetLockImplementationViaConfigurationArray()
{
$lockImplementation = $this->prophesize(LockInterface::class)->reveal();
$className = get_class($lockImplementation);
$configuration = [
'active' => true,
'lockImplementation' => $className,
];
$sut = new Configuration($configuration);
$this->assertSame($className, $sut->getLockImplementation());
}
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/**
* @test
*/
public function itIsDisabledByDefault()
{
$sut = new Configuration();
$active = $sut->isActive();
$this->assertFalse($active);
}
/**
* @test
*/
public function itCanBeEnabled()
{
$sut = new Configuration();
$this->assertFalse($sut->isActive());
$sut->setActive(true);
$this->assertTrue($sut->isActive());
}
/**
* @test
*/
public function itHasAsDefaultStrategyTheSimpleLockingStrategy()
{
$sut = new Configuration();
$className = $sut->getStrategy();
$this->assertSame(SimpleLockStrategy::class, $className);
}
/**
* @test
* @expectedException \Higidi\Lock\Configuration\Exception\InvalidStrategyException
* @expectedExceptionCode 1510177679
*/
public function itThrowsAnInvalidStrategyExceptionIfStrategyDoNotImplementTheLockingStrategyInterface()
{
$configuration = [
'strategy' => \stdClass::class,
];
new Configuration($configuration);
}
/**
* @test
*/
public function itDetectsTheMutexAdapterStrategy()
{
$strategy = $this->prophesize(MutexAdapterStrategy::class)->reveal();
$className = get_class($strategy);
$configuration = [
'active' => true,
'strategy' => $className,
];
$sut = new Configuration($configuration);
$this->assertTrue($sut->isMutexStrategy());
}
/**
* @test
*/
public function itHasADefaultMutex()
{
$sut = new Configuration();
$className = $sut->getMutex();
$this->assertSame(Mutex::class, $className);
}
/**
* @test
* @expectedException \Higidi\Lock\Configuration\Exception\InvalidMutexException
* @expectedExceptionCode 1510177680
*/
public function itThrowsAnInvalidMutexExceptionIfMutexDoNotExtendTheBaseMutex()
{
$configuration = [
'mutex' => \stdClass::class,
];
new Configuration($configuration);
/**
* @test
*/
public function itHasNullAsDefaultLockImplementation()
{
$sut = new Configuration();
$this->assertNull($sut->getLockImplementation());
}