Skip to content

Commit 68aa747

Browse files
authored
chore: cleanup of tests (testing with swoole on 8.3, removed all warnings) (#79)
* chore: cleaned up tests * chore: enabled swoole tests for php 8.3, this extension is available now
1 parent eacdba1 commit 68aa747

File tree

4 files changed

+34
-38
lines changed

4 files changed

+34
-38
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
}
4242
},
4343
"scripts": {
44-
"test": "vendor/bin/phpunit",
44+
"test": "vendor/bin/phpunit --display-incomplete --display-skipped --display-deprecations --display-errors --display-notices --display-warnings",
4545
"phpstan": "vendor/bin/phpstan",
4646
"pint": "vendor/bin/pint --config pint.json"
4747
},

tests/BatchSnowflakeIDTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function test_batch_for_same_instance_with_default_driver(): void
3838
/**
3939
* @throws Throwable
4040
*/
41-
public function test_batch_for_diff_instance_with_redis_driver()
41+
public function test_batch_for_diff_instance_with_redis_driver(): void
4242
{
4343
if (! extension_loaded('redis')
4444
|| ! getenv('REDIS_HOST')
@@ -61,7 +61,7 @@ public function test_batch_for_diff_instance_with_redis_driver()
6161
$this->assertResults($results, 100, 1000);
6262
}
6363

64-
public function test_batch_for_diff_instance_with_predis_driver()
64+
public function test_batch_for_diff_instance_with_predis_driver(): void
6565
{
6666
if (! class_exists('Predis\\Client')
6767
|| ! getenv('REDIS_HOST')
@@ -92,7 +92,7 @@ public function test_batch_for_diff_instance_with_predis_driver()
9292
/**
9393
* @throws Throwable
9494
*/
95-
public function test_batch_for_diff_instance_with_file_driver()
95+
public function test_batch_for_diff_instance_with_file_driver(): void
9696
{
9797
$fileResolver = new FileLockResolver(__DIR__);
9898

tests/FileLockResolverTest.php

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,28 @@
1717

1818
class FileLockResolverTest extends TestCase
1919
{
20+
private static string $mainLockFileDirPath;
21+
private static string $unWriteableFileDirPath;
22+
2023
private FileLockResolver $fileLocker;
2124

22-
/** @var callable */
23-
private $defer;
25+
public static function setUpBeforeClass(): void
26+
{
27+
self::$mainLockFileDirPath = dirname(__DIR__) . '/.locks';
28+
self::$unWriteableFileDirPath = __DIR__ . '/.locks';
29+
}
2430

2531
protected function setUp(): void
2632
{
27-
[$dir, $defer] = $this->prepareLockPath();
33+
mkdir(self::$mainLockFileDirPath, 0777);
34+
mkdir(self::$unWriteableFileDirPath, 0444);
2835

29-
$this->fileLocker = new FileLockResolver($dir);
30-
$this->defer = $defer;
36+
$this->fileLocker = new FileLockResolver(self::$mainLockFileDirPath);
3137
}
3238

3339
protected function tearDown(): void
3440
{
35-
$defer = $this->defer;
36-
$defer();
41+
$this->cleanUpLockFileDirs();
3742
}
3843

3944
public function test_prepare_path(): void
@@ -48,16 +53,9 @@ public function test_prepare_path_not_writable(): void
4853
$resolver = new FileLockResolver('/tmp/');
4954
$this->assertEquals('/tmp/', $this->invokeProperty($resolver, 'lockFileDir'));
5055

51-
$dir = __DIR__.'/.locks/';
52-
if (! is_dir($dir)) {
53-
mkdir($dir, 0444);
54-
}
55-
5656
$this->expectException(\Exception::class);
57-
$this->expectExceptionMessage($dir.' is not writable.');
58-
$resolver = new FileLockResolver($dir);
59-
60-
rmdir($dir);
57+
$this->expectExceptionMessage(self::$unWriteableFileDirPath.' is not writable.');
58+
$resolver = new FileLockResolver(self::$unWriteableFileDirPath);
6159
}
6260

6361
public function test_array_slice(): void
@@ -343,7 +341,7 @@ public function test_preg_match(): void
343341
/**
344342
* @throws SnowflakeException
345343
*/
346-
public function test_can_clean_lock_file()
344+
public function test_can_clean_lock_file(): void
347345
{
348346
FileLockResolver::$shardCount = 1;
349347
$fileResolver = $this->fileLocker;
@@ -360,34 +358,32 @@ public function test_can_clean_lock_file()
360358
$this->assertFileDoesNotExist($path);
361359
}
362360

363-
private function touch($content = '')
361+
private function touch(string $content = ''): string
364362
{
365-
$file = tempnam(dirname(__DIR__).'/.locks', 'snowflake');
363+
$file = tempnam(self::$mainLockFileDirPath, 'snowflake');
366364

367-
if ($content) {
365+
if ($file === false) {
366+
throw new \RuntimeException('Unable to create file');
367+
}
368+
369+
if ($content !== '') {
368370
file_put_contents($file, $content);
369371
}
370372

371373
return $file;
372374
}
373375

374-
private function prepareLockPath(): array
375-
{
376-
$dir = dirname(__DIR__).'/.locks';
377-
rmdir($dir);
378-
mkdir($dir, 0777);
379-
380-
return [$dir, fn () => rmdir($dir)];
381-
}
382-
383-
public static function tearDownAfterClass(): void
376+
private function cleanUpLockFileDirs(): void
384377
{
385-
$glob = dirname(__DIR__).'/.locks/*';
378+
$glob = self::$mainLockFileDirPath . '/*';
386379
$files = glob($glob);
387380
foreach ($files as $file) {
388381
if (is_file($file)) {
389382
unlink($file);
390383
}
391384
}
385+
386+
rmdir(self::$mainLockFileDirPath);
387+
rmdir(self::$unWriteableFileDirPath);
392388
}
393389
}

tests/SwooleSequenceResolverTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class SwooleSequenceResolverTest extends TestCase
1818
{
1919
public function setUp(): void
2020
{
21-
if (version_compare(PHP_VERSION, '8.3') >= 0) {
22-
$this->markTestSkipped('Swoole does not yet support PHP 8.3');
21+
if (version_compare(PHP_VERSION, '8.4') >= 0) {
22+
$this->markTestSkipped('Swoole does not yet support PHP 8.4');
2323
}
2424

2525
if (! extension_loaded('swoole')) {
@@ -59,7 +59,7 @@ public function test_reset_lock(): void
5959
}
6060
}
6161

62-
public function test_real_swoole()
62+
public function test_real_swoole(): void
6363
{
6464
if (! extension_loaded('swoole')) {
6565
$this->markTestSkipped('Swoole extension is not installed.');

0 commit comments

Comments
 (0)