Skip to content

Commit 22d4b42

Browse files
committed
Improve PHPUnit CS
1 parent dc95d05 commit 22d4b42

16 files changed

+153
-156
lines changed

.php-cs-fixer.dist.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,8 @@
6565
'increment_style' => false,
6666
'native_constant_invocation' => false,
6767
'no_useless_else' => false,
68-
'php_unit_data_provider_name' => false,
69-
'php_unit_data_provider_return_type' => false,
7068
'php_unit_data_provider_static' => false,
7169
'php_unit_strict' => false,
72-
'php_unit_test_case_static_method_calls' => false,
7370
'phpdoc_to_comment' => false,
7471
'static_lambda' => false,
7572
'strict_comparison' => false,

tests/mutex/CASMutexTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testNotify()
6464
$i++;
6565
$mutex->notify();
6666
});
67-
$this->assertEquals(1, $i);
67+
self::assertEquals(1, $i);
6868
}
6969

7070
/**
@@ -80,6 +80,6 @@ public function testIteration()
8080
$mutex->notify();
8181
}
8282
});
83-
$this->assertEquals(2, $i);
83+
self::assertEquals(2, $i);
8484
}
8585
}

tests/mutex/FlockMutexTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ protected function tearDown(): void
3636
}
3737

3838
/**
39-
* @dataProvider dpTimeoutableStrategies
39+
* @dataProvider dpTimeoutableStrategiesCases
4040
*/
4141
public function testCodeExecutedOutsideLockIsNotThrown(int $strategy)
4242
{
4343
$this->mutex->strategy = $strategy; // @phpstan-ignore-line
4444

45-
$this->assertTrue($this->mutex->synchronized(function (): bool {
45+
self::assertTrue($this->mutex->synchronized(function (): bool {
4646
usleep(1100 * 1000);
4747

4848
return true;
4949
}));
5050
}
5151

5252
/**
53-
* @dataProvider dpTimeoutableStrategies
53+
* @dataProvider dpTimeoutableStrategiesCases
5454
*/
5555
public function testTimeoutOccurs(int $strategy)
5656
{
@@ -65,15 +65,15 @@ public function testTimeoutOccurs(int $strategy)
6565
try {
6666
$this->mutex->synchronized(
6767
function () {
68-
$this->fail('Did not expect code to be executed');
68+
self::fail('Did not expect code to be executed');
6969
}
7070
);
7171
} finally {
7272
fclose($another_resource);
7373
}
7474
}
7575

76-
public function dpTimeoutableStrategies()
76+
public static function dpTimeoutableStrategiesCases(): iterable
7777
{
7878
return [
7979
[FlockMutex::STRATEGY_PCNTL],
@@ -93,7 +93,7 @@ public function testNoTimeoutWaitsForever()
9393
$timebox = new PcntlTimeout(1);
9494
$timebox->timeBoxed(function () {
9595
$this->mutex->synchronized(function (): void {
96-
$this->fail('Did not expect code execution.');
96+
self::fail('Did not expect code execution.');
9797
});
9898
});
9999
}

tests/mutex/LockMutexTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public function testLockFails()
3030
{
3131
$this->expectException(LockAcquireException::class);
3232

33-
$this->mutex->expects($this->once())
33+
$this->mutex->expects(self::once())
3434
->method('lock')
3535
->willThrowException(new LockAcquireException());
3636

3737
$this->mutex->synchronized(function (): void {
38-
$this->fail('Should not execute code.');
38+
self::fail('Should not execute code.');
3939
});
4040
}
4141

@@ -44,7 +44,7 @@ public function testLockFails()
4444
*/
4545
public function testUnlockAfterCode()
4646
{
47-
$this->mutex->expects($this->once())
47+
$this->mutex->expects(self::once())
4848
->method('unlock');
4949

5050
$this->mutex->synchronized(function (): void {});
@@ -55,7 +55,7 @@ public function testUnlockAfterCode()
5555
*/
5656
public function testUnlockAfterException()
5757
{
58-
$this->mutex->expects($this->once())
58+
$this->mutex->expects(self::once())
5959
->method('unlock');
6060

6161
$this->expectException(\DomainException::class);
@@ -71,7 +71,7 @@ public function testUnlockFailsAfterCode()
7171
{
7272
$this->expectException(LockReleaseException::class);
7373

74-
$this->mutex->expects($this->once())
74+
$this->mutex->expects(self::once())
7575
->method('unlock')
7676
->willThrowException(new LockReleaseException());
7777

@@ -85,7 +85,7 @@ public function testUnlockFailsAfterException()
8585
{
8686
$this->expectException(LockReleaseException::class);
8787

88-
$this->mutex->expects($this->once())
88+
$this->mutex->expects(self::once())
8989
->method('unlock')
9090
->willThrowException(new LockReleaseException());
9191

@@ -99,7 +99,7 @@ public function testUnlockFailsAfterException()
9999
*/
100100
public function testCodeResultAvailableAfterFailedUnlock()
101101
{
102-
$this->mutex->expects($this->once())
102+
$this->mutex->expects(self::once())
103103
->method('unlock')
104104
->willThrowException(new LockReleaseException());
105105

@@ -108,8 +108,8 @@ public function testCodeResultAvailableAfterFailedUnlock()
108108
return 'result';
109109
});
110110
} catch (LockReleaseException $exception) {
111-
$this->assertEquals('result', $exception->getCodeResult());
112-
$this->assertNull($exception->getCodeException());
111+
self::assertEquals('result', $exception->getCodeResult());
112+
self::assertNull($exception->getCodeException());
113113
}
114114
}
115115

@@ -118,7 +118,7 @@ public function testCodeResultAvailableAfterFailedUnlock()
118118
*/
119119
public function testCodeExceptionAvailableAfterFailedUnlock()
120120
{
121-
$this->mutex->expects($this->once())
121+
$this->mutex->expects(self::once())
122122
->method('unlock')
123123
->willThrowException(new LockReleaseException());
124124

@@ -127,8 +127,8 @@ public function testCodeExceptionAvailableAfterFailedUnlock()
127127
throw new \DomainException('Domain exception');
128128
});
129129
} catch (LockReleaseException $exception) {
130-
$this->assertInstanceOf(\DomainException::class, $exception->getCodeException());
131-
$this->assertEquals('Domain exception', $exception->getCodeException()->getMessage());
130+
self::assertInstanceOf(\DomainException::class, $exception->getCodeException());
131+
self::assertEquals('Domain exception', $exception->getCodeException()->getMessage());
132132
}
133133
}
134134
}

tests/mutex/MemcachedMutexTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ public function testFailAcquireLock()
3939
{
4040
$this->expectException(TimeoutException::class);
4141

42-
$this->memcached->expects($this->atLeastOnce())
42+
$this->memcached->expects(self::atLeastOnce())
4343
->method('add')
4444
->with('lock_test', true, 2)
4545
->willReturn(false);
4646

4747
$this->mutex->synchronized(function (): void {
48-
$this->fail('execution is not expected');
48+
self::fail('execution is not expected');
4949
});
5050
}
5151

@@ -56,12 +56,12 @@ public function testFailReleasingLock()
5656
{
5757
$this->expectException(LockReleaseException::class);
5858

59-
$this->memcached->expects($this->once())
59+
$this->memcached->expects(self::once())
6060
->method('add')
6161
->with('lock_test', true, 2)
6262
->willReturn(true);
6363

64-
$this->memcached->expects($this->once())
64+
$this->memcached->expects(self::once())
6565
->method('delete')
6666
->with('lock_test')
6767
->willReturn(false);

tests/mutex/MutexConcurrencyTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private function fork(int $concurrency, callable $code)
8181
* @param callable $code the counter code
8282
* @param callable $mutexFactory the mutex factory
8383
*
84-
* @dataProvider provideTestHighContention
84+
* @dataProvider provideHighContentionCases
8585
*
8686
* @slowThreshold 1000
8787
*/
@@ -102,13 +102,13 @@ public function testHighContention(callable $code, callable $mutexFactory)
102102
});
103103

104104
$counter = $code(0);
105-
$this->assertEquals($concurrency * $iterations, $counter);
105+
self::assertEquals($concurrency * $iterations, $counter);
106106
}
107107

108108
/**
109109
* Returns test cases for testHighContention().
110110
*/
111-
public function provideTestHighContention(): array
111+
public function provideHighContentionCases(): iterable
112112
{
113113
$cases = array_map(function (array $mutexFactory): array {
114114
$filename = tempnam(sys_get_temp_dir(), 'php-lock-high-contention');
@@ -128,7 +128,7 @@ function (int $increment) use ($filename): int {
128128
},
129129
$mutexFactory[0],
130130
];
131-
}, $this->provideMutexFactories());
131+
}, static::provideExecutionIsSerializedWhenLockedCases());
132132

133133
$addPDO = function ($dsn, $user, $password, $vendor) use (&$cases) {
134134
$pdo = $this->getPDO($dsn, $user, $password);
@@ -194,7 +194,7 @@ function ($timeout = 3) use ($dsn, $user, $password) {
194194
*
195195
* @param callable $mutexFactory the Mutex factory
196196
*
197-
* @dataProvider provideMutexFactories
197+
* @dataProvider provideExecutionIsSerializedWhenLockedCases
198198
*
199199
* @slowThreshold 2000
200200
*/
@@ -211,15 +211,15 @@ public function testExecutionIsSerializedWhenLocked(callable $mutexFactory)
211211
});
212212

213213
$delta = \microtime(true) - $time;
214-
$this->assertGreaterThan(1.201, $delta);
214+
self::assertGreaterThan(1.201, $delta);
215215
}
216216

217217
/**
218218
* Provides Mutex factories.
219219
*
220220
* @return callable[][] the mutex factories
221221
*/
222-
public function provideMutexFactories()
222+
public static function provideExecutionIsSerializedWhenLockedCases(): iterable
223223
{
224224
$filename = tempnam(sys_get_temp_dir(), 'mutex-concurrency-test');
225225

@@ -250,10 +250,10 @@ public function provideMutexFactories()
250250

251251
'semaphore' => [function ($timeout = 3) use ($filename): Mutex {
252252
$semaphore = sem_get(ftok($filename, 'b'));
253-
$this->assertThat(
253+
self::assertThat(
254254
$semaphore,
255-
$this->logicalOr(
256-
$this->isInstanceOf(\SysvSemaphore::class),
255+
self::logicalOr(
256+
self::isInstanceOf(\SysvSemaphore::class),
257257
new IsType(IsType::TYPE_RESOURCE)
258258
)
259259
);

tests/mutex/MutexTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static function setUpBeforeClass(): void
3131
*
3232
* @return callable[][] the mutex factories
3333
*/
34-
public function provideMutexFactories()
34+
public function provideMutexFactoriesCases(): iterable
3535
{
3636
$cases = [
3737
'NoMutex' => [function (): Mutex {
@@ -73,11 +73,11 @@ public function provideMutexFactories()
7373

7474
'SpinlockMutex' => [function (): Mutex {
7575
$mock = $this->getMockForAbstractClass(SpinlockMutex::class, ['test']);
76-
$mock->expects($this->atLeastOnce())
76+
$mock->expects(self::atLeastOnce())
7777
->method('acquire')
7878
->willReturn(true);
7979

80-
$mock->expects($this->atLeastOnce())
80+
$mock->expects(self::atLeastOnce())
8181
->method('release')
8282
->willReturn(true);
8383

@@ -86,10 +86,10 @@ public function provideMutexFactories()
8686

8787
'LockMutex' => [function (): Mutex {
8888
$mock = $this->getMockForAbstractClass(LockMutex::class);
89-
$mock->expects($this->atLeastOnce())
89+
$mock->expects(self::atLeastOnce())
9090
->method('lock');
9191

92-
$mock->expects($this->atLeastOnce())
92+
$mock->expects(self::atLeastOnce())
9393
->method('unlock');
9494

9595
return $mock;
@@ -174,7 +174,7 @@ function ($uri) {
174174
*
175175
* @param callable $mutexFactory the Mutex factory
176176
*
177-
* @dataProvider provideMutexFactories
177+
* @dataProvider provideMutexFactoriesCases
178178
*/
179179
public function testSynchronizedDelegates(callable $mutexFactory)
180180
{
@@ -183,15 +183,15 @@ public function testSynchronizedDelegates(callable $mutexFactory)
183183
$result = $mutex->synchronized(function (): string {
184184
return 'test';
185185
});
186-
$this->assertSame('test', $result);
186+
self::assertSame('test', $result);
187187
}
188188

189189
/**
190190
* Tests that synchronized() released the lock.
191191
*
192192
* @param callable $mutexFactory the Mutex factory
193193
*
194-
* @dataProvider provideMutexFactories
194+
* @dataProvider provideMutexFactoriesCases
195195
*/
196196
public function testRelease(callable $mutexFactory)
197197
{
@@ -207,7 +207,7 @@ public function testRelease(callable $mutexFactory)
207207
*
208208
* @param callable $mutexFactory the Mutex factory
209209
*
210-
* @dataProvider provideMutexFactories
210+
* @dataProvider provideMutexFactoriesCases
211211
*/
212212
public function testSynchronizedPassesExceptionThrough(callable $mutexFactory)
213213
{

0 commit comments

Comments
 (0)