Skip to content

Commit 1db29ab

Browse files
Add PHPUnit speedtrap, remove slow test that didn't perform any assertions
1 parent 9f45321 commit 1db29ab

File tree

4 files changed

+28
-45
lines changed

4 files changed

+28
-45
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"ext-pdo_mysql": "*",
3636
"ext-pdo_sqlite": "*",
3737
"ext-redis": "*",
38+
"johnkary/phpunit-speedtrap": "^1.0",
3839
"kriswallsmith/spork": "^0.3",
3940
"mikey179/vfsStream": "^1.5.0",
4041
"php-mock/php-mock-phpunit": "^1",

phpunit.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
<testsuite>
66
<directory>tests</directory>
77
</testsuite>
8+
<listeners>
9+
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
10+
</listeners>
811
</phpunit>

tests/mutex/MutexTest.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -160,36 +160,7 @@ public function testRelease(callable $mutexFactory)
160160
$mutex->synchronized(function () {
161161
});
162162
}
163-
164-
/**
165-
* Tests that locks will be released automatically.
166-
*
167-
* @param callable $mutexFactory The Mutex factory.
168-
* @test
169-
* @dataProvider provideMutexFactories
170-
*/
171-
public function testLiveness(callable $mutexFactory)
172-
{
173-
$manager = new ProcessManager();
174-
$manager->setDebug(true);
175-
176-
$manager->fork(function () use ($mutexFactory) {
177-
$mutex = call_user_func($mutexFactory);
178-
$mutex->synchronized(function () {
179-
exit;
180-
});
181-
});
182-
$manager->wait();
183-
184-
sleep(self::TIMEOUT - 1);
185163

186-
$mutex = call_user_func($mutexFactory);
187-
$mutex->synchronized(function () {
188-
});
189-
190-
$manager->check();
191-
}
192-
193164
/**
194165
* Tests synchronized() rethrows the exception of the code.
195166
*

tests/mutex/PredisMutexTest.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
*
1313
* REDIS_URIS - a comma separated list of redis:// URIs.
1414
*
15-
* @author Markus Malkusch <[email protected]>
16-
* @link bitcoin:1P5FAZ4QhXCuwYPnLZdk3PJsqePbu1UDDA Donations
15+
* @author Markus Malkusch <[email protected]>
16+
* @link bitcoin:1P5FAZ4QhXCuwYPnLZdk3PJsqePbu1UDDA Donations
1717
* @license WTFPL
18-
* @see PredisMutex
19-
* @group redis
18+
* @see PredisMutex
19+
* @group redis
2020
*/
2121
class PredisMutexTest extends \PHPUnit_Framework_TestCase
2222
{
@@ -28,12 +28,16 @@ class PredisMutexTest extends \PHPUnit_Framework_TestCase
2828
protected function setUp()
2929
{
3030
parent::setUp();
31-
32-
$this->client = new Client($this->getPredisConfig());
3331

34-
if (count($this->getPredisConfig()) == 1) {
35-
$this->client->flushall(); // Clear any existing locks
32+
$config = $this->getPredisConfig();
33+
34+
if (null === $config) {
35+
$this->markTestSkipped();
36+
return;
3637
}
38+
39+
$this->client = new Client($config);
40+
$this->client->flushall(); // Clear any existing locks
3741
}
3842

3943
private function getPredisConfig()
@@ -44,27 +48,31 @@ private function getPredisConfig()
4448

4549
$servers = explode(",", getenv("REDIS_URIS"));
4650

47-
return array_map(function ($redisUri) {
48-
return str_replace("redis://", "tcp://", $redisUri);
49-
}, $servers);
51+
return array_map(
52+
function ($redisUri) {
53+
return str_replace("redis://", "tcp://", $redisUri);
54+
}, $servers
55+
);
5056
}
5157

5258
/**
5359
* Tests add() fails.
5460
*
5561
* @test
56-
* @expectedException \malkusch\lock\exception\LockAcquireException
62+
* @expectedException \malkusch\lock\exception\LockAcquireException
5763
* @expectedExceptionCode \malkusch\lock\exception\MutexException::REDIS_NOT_ENOUGH_SERVERS
5864
*/
5965
public function testAddFails()
6066
{
6167
$client = new Client("redis://127.0.0.1:12345");
6268

6369
$mutex = new PredisMutex([$client], "test");
64-
65-
$mutex->synchronized(function () {
66-
$this->fail("Code execution is not expected");
67-
});
70+
71+
$mutex->synchronized(
72+
function () {
73+
$this->fail("Code execution is not expected");
74+
}
75+
);
6876
}
6977

7078
/**

0 commit comments

Comments
 (0)