Skip to content

Commit d560c4f

Browse files
author
Willem Stuursma
committed
Start upgrade to more modern toolchain
1 parent 3f3788b commit d560c4f

18 files changed

+142
-115
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/.idea
2+
/.php_cs
3+
/.phpunit.result.cache
24
/vendor
35
/composer.lock
46
/phpunit.xml
5-
/.php_cs

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ cache:
55
- $HOME/.composer/cache
66

77
php:
8-
- 7.1
98
- 7.2
109
- 7.3
1110
- 7.4

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@
4242
}
4343
},
4444
"require": {
45-
"php": ">=7.1",
45+
"php": "^7.2",
4646
"psr/log": "^1"
4747
},
4848
"require-dev": {
4949
"ext-memcached": "*",
5050
"ext-pcntl": "*",
51+
"ext-pdo": "*",
5152
"ext-pdo_mysql": "*",
5253
"ext-pdo_sqlite": "*",
5354
"ext-sysvsem": "*",
5455
"eloquent/liberator": "^2.0",
55-
"friendsofphp/php-cs-fixer": "^2.14",
5656
"johnkary/phpunit-speedtrap": "^3.0",
5757
"kriswallsmith/spork": "^0.3",
5858
"mikey179/vfsstream": "^1.6",
5959
"php-mock/php-mock-phpunit": "^2.1",
60-
"phpunit/phpunit": "^7.4",
60+
"phpunit/phpunit": "^9.4",
6161
"predis/predis": "^1.1",
6262
"squizlabs/php_codesniffer": "^3.3",
6363
"symfony/event-dispatcher": "^2.8"

tests/mutex/CASMutexTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace malkusch\lock\mutex;
44

5+
use malkusch\lock\exception\LockAcquireException;
56
use phpmock\environment\SleepEnvironmentBuilder;
67
use phpmock\phpunit\PHPMock;
78
use PHPUnit\Framework\TestCase;
@@ -18,7 +19,7 @@ class CASMutexTest extends TestCase
1819
{
1920
use PHPMock;
2021

21-
protected function setUp()
22+
protected function setUp(): void
2223
{
2324
parent::setUp();
2425

@@ -33,11 +34,11 @@ protected function setUp()
3334

3435
/**
3536
* Tests exceeding the execution timeout.
36-
*
37-
* @expectedException malkusch\lock\exception\LockAcquireException
3837
*/
3938
public function testExceedTimeout()
4039
{
40+
$this->expectException(LockAcquireException::class);
41+
4142
$mutex = new CASMutex(1);
4243
$mutex->synchronized(function (): void {
4344
sleep(2);
@@ -46,11 +47,11 @@ public function testExceedTimeout()
4647

4748
/**
4849
* Tests that an exception would stop any further iteration.
49-
*
50-
* @expectedException \DomainException
5150
*/
5251
public function testExceptionStopsIteration()
5352
{
53+
$this->expectException(\DomainException::class);
54+
5455
$mutex = new CASMutex();
5556
$mutex->synchronized(function () {
5657
throw new \DomainException();

tests/mutex/FlockMutexTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace malkusch\lock\mutex;
44

55
use Eloquent\Liberator\Liberator;
6+
use malkusch\lock\exception\DeadlineException;
7+
use malkusch\lock\exception\TimeoutException;
68
use malkusch\lock\util\PcntlTimeout;
79
use PHPUnit\Framework\TestCase;
810

@@ -24,15 +26,15 @@ class FlockMutexTest extends TestCase
2426
*/
2527
private $file;
2628

27-
protected function setUp()
29+
protected function setUp(): void
2830
{
2931
parent::setUp();
3032

3133
$this->file = tempnam(sys_get_temp_dir(), 'flock-');
3234
$this->mutex = Liberator::liberate(new FlockMutex(fopen($this->file, 'r'), 1));
3335
}
3436

35-
protected function tearDown()
37+
protected function tearDown(): void
3638
{
3739
unlink($this->file);
3840

@@ -54,12 +56,13 @@ public function testCodeExecutedOutsideLockIsNotThrown(int $strategy)
5456
}
5557

5658
/**
57-
* @expectedException \malkusch\lock\exception\TimeoutException
58-
* @expectedExceptionMessage Timeout of 1 seconds exceeded.
5959
* @dataProvider dpTimeoutableStrategies
6060
*/
6161
public function testTimeoutOccurs(int $strategy)
6262
{
63+
$this->expectException(TimeoutException::class);
64+
$this->expectExceptionMessage('Timeout of 1 seconds exceeded.');
65+
6366
$another_resource = fopen($this->file, 'r');
6467
flock($another_resource, LOCK_EX);
6568

@@ -84,19 +87,18 @@ public function dpTimeoutableStrategies()
8487
];
8588
}
8689

87-
/**
88-
* @expectedException \malkusch\lock\exception\DeadlineException
89-
*/
9090
public function testNoTimeoutWaitsForever()
9191
{
92+
$this->expectException(DeadlineException::class);
93+
9294
$another_resource = fopen($this->file, 'r');
9395
flock($another_resource, LOCK_EX);
9496

9597
$this->mutex->strategy = FlockMutex::STRATEGY_BLOCK;
9698

9799
$timebox = new PcntlTimeout(1);
98100
$timebox->timeBoxed(function () {
99-
$this->mutex->synchronized(function () {
101+
$this->mutex->synchronized(function (): void {
100102
$this->fail('Did not expect code execution.');
101103
});
102104
});

tests/mutex/LockMutexTest.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class LockMutexTest extends TestCase
2121
*/
2222
private $mutex;
2323

24-
protected function setUp()
24+
protected function setUp(): void
2525
{
2626
parent::setUp();
2727

@@ -30,23 +30,22 @@ protected function setUp()
3030

3131
/**
3232
* Tests lock() fails and the code is not executed.
33-
*
34-
* @expectedException malkusch\lock\exception\LockAcquireException
3533
*/
3634
public function testLockFails()
3735
{
36+
$this->expectException(LockAcquireException::class);
37+
3838
$this->mutex->expects($this->once())
3939
->method('lock')
4040
->willThrowException(new LockAcquireException());
4141

42-
$this->mutex->synchronized(function () {
42+
$this->mutex->synchronized(function (): void {
4343
$this->fail('Should not execute code.');
4444
});
4545
}
4646

4747
/**
4848
* Tests unlock() is called after the code was executed.
49-
*
5049
*/
5150
public function testUnlockAfterCode()
5251
{
@@ -74,11 +73,11 @@ public function testUnlockAfterException()
7473

7574
/**
7675
* Tests unlock() fails after the code was executed.
77-
*
78-
* @expectedException malkusch\lock\exception\LockReleaseException
7976
*/
8077
public function testUnlockFailsAfterCode()
8178
{
79+
$this->expectException(LockReleaseException::class);
80+
8281
$this->mutex->expects($this->once())
8382
->method('unlock')
8483
->willThrowException(new LockReleaseException());
@@ -89,11 +88,11 @@ public function testUnlockFailsAfterCode()
8988

9089
/**
9190
* Tests unlock() fails after the code threw an exception.
92-
*
93-
* @expectedException malkusch\lock\exception\LockReleaseException
9491
*/
9592
public function testUnlockFailsAfterException()
9693
{
94+
$this->expectException(LockReleaseException::class);
95+
9796
$this->mutex->expects($this->once())
9897
->method('unlock')
9998
->willThrowException(new LockReleaseException());

tests/mutex/MemcachedMutexTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace malkusch\lock\mutex;
44

5+
use malkusch\lock\exception\LockReleaseException;
6+
use malkusch\lock\exception\TimeoutException;
57
use PHPUnit\Framework\MockObject\MockObject;
68
use PHPUnit\Framework\TestCase;
79

@@ -28,19 +30,19 @@ class MemcachedMutexTest extends TestCase
2830
*/
2931
private $mutex;
3032

31-
protected function setUp()
33+
protected function setUp(): void
3234
{
3335
$this->memcached = $this->createMock(\Memcached::class);
3436
$this->mutex = new MemcachedMutex('test', $this->memcached, 1);
3537
}
3638

3739
/**
3840
* Tests failing to acquire the lock within the timeout.
39-
*
40-
* @expectedException \malkusch\lock\exception\TimeoutException
4141
*/
4242
public function testFailAcquireLock()
4343
{
44+
$this->expectException(TimeoutException::class);
45+
4446
$this->memcached->expects($this->atLeastOnce())
4547
->method('add')
4648
->with('lock_test', true, 2)
@@ -53,11 +55,11 @@ public function testFailAcquireLock()
5355

5456
/**
5557
* Tests failing to release a lock.
56-
*
57-
* @expectedException \malkusch\lock\exception\LockReleaseException
5858
*/
5959
public function testFailReleasingLock()
6060
{
61+
$this->expectException(LockReleaseException::class);
62+
6163
$this->memcached->expects($this->once())
6264
->method('add')
6365
->with('lock_test', true, 2)

tests/mutex/MutexConcurrencyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class MutexConcurrencyTest extends TestCase
3636
*/
3737
private $path;
3838

39-
protected function tearDown()
39+
protected function tearDown(): void
4040
{
4141
if ($this->path) {
4242
unlink($this->path);

tests/mutex/MutexTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MutexTest extends TestCase
2626
{
2727
const TIMEOUT = 4;
2828

29-
public static function setUpBeforeClass()
29+
public static function setUpBeforeClass(): void
3030
{
3131
vfsStream::setup('test');
3232
}
@@ -92,12 +92,10 @@ public function provideMutexFactories()
9292
'LockMutex' => [function (): Mutex {
9393
$mock = $this->getMockForAbstractClass(LockMutex::class);
9494
$mock->expects($this->atLeastOnce())
95-
->method('lock')
96-
->willReturn(true);
95+
->method('lock');
9796

9897
$mock->expects($this->atLeastOnce())
99-
->method('unlock')
100-
->willReturn(true);
98+
->method('unlock');
10199

102100
return $mock;
103101
}],
@@ -183,7 +181,7 @@ public function testSynchronizedDelegates(callable $mutexFactory)
183181
{
184182
/** @var Mutex $mutex */
185183
$mutex = $mutexFactory();
186-
$result = $mutex->synchronized(function () {
184+
$result = $mutex->synchronized(function (): string {
187185
return 'test';
188186
});
189187
$this->assertSame('test', $result);
@@ -211,10 +209,11 @@ public function testRelease(callable $mutexFactory)
211209
*
212210
* @param callable $mutexFactory The Mutex factory.
213211
* @dataProvider provideMutexFactories
214-
* @expectedException \DomainException
215212
*/
216213
public function testSynchronizedPassesExceptionThrough(callable $mutexFactory)
217214
{
215+
$this->expectException(\DomainException::class);
216+
218217
/** @var Mutex $mutex */
219218
$mutex = $mutexFactory();
220219
$mutex->synchronized(function () {

tests/mutex/PHPRedisMutexTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace malkusch\lock\mutex;
44

5+
use malkusch\lock\exception\LockAcquireException;
6+
use malkusch\lock\exception\LockReleaseException;
7+
use malkusch\lock\exception\MutexException;
58
use PHPUnit\Framework\TestCase;
69
use Redis;
710

@@ -31,7 +34,7 @@ class PHPRedisMutexTest extends TestCase
3134
*/
3235
private $mutex;
3336

34-
protected function setUp()
37+
protected function setUp(): void
3538
{
3639
parent::setUp();
3740

@@ -108,12 +111,11 @@ private function closeMinorityConnections()
108111
}
109112
}
110113

111-
/**
112-
* @expectedException \malkusch\lock\exception\LockAcquireException
113-
* @expectedExceptionCode \malkusch\lock\exception\MutexException::REDIS_NOT_ENOUGH_SERVERS
114-
*/
115114
public function testAddFails()
116115
{
116+
$this->expectException(LockAcquireException::class);
117+
$this->expectExceptionCode(MutexException::REDIS_NOT_ENOUGH_SERVERS);
118+
117119
$this->closeMajorityConnections();
118120

119121
$this->mutex->synchronized(function (): void {
@@ -123,11 +125,11 @@ public function testAddFails()
123125

124126
/**
125127
* Tests evalScript() fails.
126-
*
127-
* @expectedException \malkusch\lock\exception\LockReleaseException
128128
*/
129129
public function testEvalScriptFails()
130130
{
131+
$this->expectException(LockReleaseException::class);
132+
131133
$this->mutex->synchronized(function (): void {
132134
$this->closeMajorityConnections();
133135
});

0 commit comments

Comments
 (0)