Skip to content

Commit

Permalink
Namespace test files
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Dec 3, 2024
1 parent a11ae4e commit 62577c7
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: "Run tests (only for Phpunit)"
if: startsWith(matrix.type, 'Phpunit')
run: |
vendor/bin/phpunit --exclude-group none --no-coverage --fail-on-warning --fail-on-risky $(if vendor/bin/phpunit --version | grep -q '^PHPUnit 9\.'; then echo -v; else echo --fail-on-notice --fail-on-deprecation --display-notices --display-deprecations --display-warnings --display-errors --display-incomplete --display-skipped; fi) --filter '^(?!malkusch\\lock\\mutex\\PHPRedisMutexTest::)'
vendor/bin/phpunit --exclude-group none --no-coverage --fail-on-warning --fail-on-risky $(if vendor/bin/phpunit --version | grep -q '^PHPUnit 9\.'; then echo -v; else echo --fail-on-notice --fail-on-deprecation --display-notices --display-deprecations --display-warnings --display-errors --display-incomplete --display-skipped; fi) --filter '^(?!malkusch\\lock\\Tests\\mutex\\PHPRedisMutexTest::)'
- name: Check Coding Style (only for CodingStyle)
if: matrix.type == 'CodingStyle'
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,16 @@ $mutex->synchronized(function () use ($bankAccount, $amount) {

This project is free and is licensed under the MIT.

[1]: http://semver.org
[1]: http://semver.org/
[2]: https://github.com/nrk/predis
[3]: http://php.net/manual/en/book.pcntl.php
[4]: https://getcomposer.org
[5]: https://github.com/php-lock/lock/blob/master/src/mutex/Mutex.php
[6]: https://github.com/php-lock/lock/blob/master/src/mutex/Mutex.php#L38
[7]: https://github.com/php-lock/lock/blob/master/src/mutex/Mutex.php#L57
[8]: https://github.com/php-lock/lock/blob/master/src/util/DoubleCheckedLocking.php#L72
[4]: https://getcomposer.org/
[5]: https://github.com/php-lock/lock/blob/35526aee28/src/mutex/Mutex.php#L15
[6]: https://github.com/php-lock/lock/blob/35526aee28/src/mutex/Mutex.php#L38
[7]: https://github.com/php-lock/lock/blob/35526aee28/src/mutex/Mutex.php#L60
[8]: https://github.com/php-lock/lock/blob/35526aee28/src/util/DoubleCheckedLocking.php#L63
[9]: https://en.wikipedia.org/wiki/Double-checked_locking
[10]: https://en.wikipedia.org/wiki/Compare-and-swap
[11]: https://github.com/php-lock/lock/blob/master/src/mutex/CASMutex.php#L44
[12]: https://github.com/php-lock/lock/blob/master/src/mutex/LockMutex.php
[13]: https://github.com/php-lock/lock/blob/master/src/exception/LockReleaseException.php
[11]: https://github.com/php-lock/lock/blob/35526aee28/src/mutex/CASMutex.php#L42
[12]: https://github.com/php-lock/lock/blob/35526aee28/src/mutex/LockMutex.php
[13]: https://github.com/php-lock/lock/blob/35526aee28/src/exception/LockReleaseException.php
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
"autoload-dev": {
"psr-4": {
"malkusch\\lock\\": "tests/"
"malkusch\\lock\\Tests\\": "tests/"
}
},
"config": {
Expand Down
4 changes: 3 additions & 1 deletion tests/mutex/CASMutexTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace malkusch\lock\mutex;
namespace malkusch\lock\Tests\mutex;

use malkusch\lock\exception\LockAcquireException;
use malkusch\lock\mutex\CASMutex;
use phpmock\environment\SleepEnvironmentBuilder;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\TestCase;
Expand All @@ -18,6 +19,7 @@ protected function setUp(): void

$builder = new SleepEnvironmentBuilder();
$builder->addNamespace(__NAMESPACE__);
$builder->addNamespace('malkusch\lock\mutex');
$builder->addNamespace('malkusch\lock\util');
$sleep = $builder->build();
$sleep->enable();
Expand Down
3 changes: 2 additions & 1 deletion tests/mutex/FlockMutexTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

namespace malkusch\lock\mutex;
namespace malkusch\lock\Tests\mutex;

use Eloquent\Liberator\Liberator;
use malkusch\lock\exception\DeadlineException;
use malkusch\lock\exception\TimeoutException;
use malkusch\lock\mutex\FlockMutex;
use malkusch\lock\util\PcntlTimeout;
use PHPUnit\Framework\TestCase;

Expand Down
3 changes: 2 additions & 1 deletion tests/mutex/LockMutexTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

namespace malkusch\lock\mutex;
namespace malkusch\lock\Tests\mutex;

use malkusch\lock\exception\LockAcquireException;
use malkusch\lock\exception\LockReleaseException;
use malkusch\lock\mutex\LockMutex;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand Down
5 changes: 2 additions & 3 deletions tests/mutex/MemcachedMutexTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

namespace malkusch\lock\mutex;
namespace malkusch\lock\Tests\mutex;

use malkusch\lock\exception\LockReleaseException;
use malkusch\lock\exception\TimeoutException;
use malkusch\lock\mutex\MemcachedMutex;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Tests for MemcachedMutex.
*
* Please provide the environment variable MEMCACHE_HOST.
*
* @requires extension memcached
Expand Down
13 changes: 10 additions & 3 deletions tests/mutex/MutexConcurrencyTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<?php

namespace malkusch\lock\mutex;
namespace malkusch\lock\Tests\mutex;

use Eloquent\Liberator\Liberator;
use malkusch\lock\mutex\FlockMutex;
use malkusch\lock\mutex\MemcachedMutex;
use malkusch\lock\mutex\Mutex;
use malkusch\lock\mutex\MySQLMutex;
use malkusch\lock\mutex\PgAdvisoryLockMutex;
use malkusch\lock\mutex\PHPRedisMutex;
use malkusch\lock\mutex\PredisMutex;
use malkusch\lock\mutex\SemaphoreMutex;
use malkusch\lock\mutex\TransactionalMutex;
use PHPUnit\Framework\Constraint\IsType;
use PHPUnit\Framework\TestCase;
use Predis\Client;
use Spatie\Async\Pool;

/**
* Concurrency Tests for Mutex.
*
* If you want to run integration tests you should provide these environment variables:
*
* - MEMCACHE_HOST
Expand Down
16 changes: 13 additions & 3 deletions tests/mutex/MutexTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
<?php

namespace malkusch\lock\mutex;
namespace malkusch\lock\Tests\mutex;

use Eloquent\Liberator\Liberator;
use malkusch\lock\mutex\FlockMutex;
use malkusch\lock\mutex\LockMutex;
use malkusch\lock\mutex\MemcachedMutex;
use malkusch\lock\mutex\Mutex;
use malkusch\lock\mutex\MySQLMutex;
use malkusch\lock\mutex\NoMutex;
use malkusch\lock\mutex\PgAdvisoryLockMutex;
use malkusch\lock\mutex\PHPRedisMutex;
use malkusch\lock\mutex\PredisMutex;
use malkusch\lock\mutex\SemaphoreMutex;
use malkusch\lock\mutex\SpinlockMutex;
use malkusch\lock\mutex\TransactionalMutex;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
use Predis\Client;

/**
* Tests for Mutex.
*
* If you want to run integrations tests you should provide these environment variables:
*
* - MEMCACHE_HOST
Expand Down
5 changes: 2 additions & 3 deletions tests/mutex/PHPRedisMutexTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

namespace malkusch\lock\mutex;
namespace malkusch\lock\Tests\mutex;

use malkusch\lock\exception\LockAcquireException;
use malkusch\lock\exception\LockReleaseException;
use malkusch\lock\exception\MutexException;
use malkusch\lock\mutex\PHPRedisMutex;
use PHPUnit\Framework\TestCase;

if (\PHP_MAJOR_VERSION >= 8) {
Expand Down Expand Up @@ -52,8 +53,6 @@ public function set($key, $value, $options = null)
}

/**
* Tests for PHPRedisMutex.
*
* These tests require the environment variable:
*
* REDIS_URIS - a comma separated list of redis:// URIs.
Expand Down
3 changes: 2 additions & 1 deletion tests/mutex/PgAdvisoryLockMutexTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace malkusch\lock\mutex;
namespace malkusch\lock\Tests\mutex;

use malkusch\lock\mutex\PgAdvisoryLockMutex;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand Down
5 changes: 2 additions & 3 deletions tests/mutex/PredisMutexTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?php

namespace malkusch\lock\mutex;
namespace malkusch\lock\Tests\mutex;

use malkusch\lock\exception\LockAcquireException;
use malkusch\lock\exception\LockReleaseException;
use malkusch\lock\mutex\PredisMutex;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Predis\ClientInterface;
use Predis\PredisException;
use Psr\Log\LoggerInterface;

/**
* Tests for PredisMutex.
*
* @group redis
*/
class PredisMutexTest extends TestCase
Expand Down
6 changes: 3 additions & 3 deletions tests/mutex/RedisMutexTest.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<?php

namespace malkusch\lock\mutex;
namespace malkusch\lock\Tests\mutex;

use malkusch\lock\exception\LockAcquireException;
use malkusch\lock\exception\LockReleaseException;
use malkusch\lock\exception\MutexException;
use malkusch\lock\exception\TimeoutException;
use malkusch\lock\mutex\RedisMutex;
use phpmock\environment\SleepEnvironmentBuilder;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Tests for RedisMutex.
*
* @group redis
*/
class RedisMutexTest extends TestCase
Expand All @@ -27,6 +26,7 @@ protected function setUp(): void

$sleepBuilder = new SleepEnvironmentBuilder();
$sleepBuilder->addNamespace(__NAMESPACE__);
$sleepBuilder->addNamespace('malkusch\lock\mutex');
$sleepBuilder->addNamespace('malkusch\lock\util');
$sleep = $sleepBuilder->build();

Expand Down
4 changes: 3 additions & 1 deletion tests/mutex/SpinlockMutexTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

namespace malkusch\lock\mutex;
namespace malkusch\lock\Tests\mutex;

use malkusch\lock\exception\ExecutionOutsideLockException;
use malkusch\lock\exception\LockAcquireException;
use malkusch\lock\exception\LockReleaseException;
use malkusch\lock\exception\TimeoutException;
use malkusch\lock\mutex\SpinlockMutex;
use phpmock\environment\SleepEnvironmentBuilder;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -22,6 +23,7 @@ protected function setUp(): void

$builder = new SleepEnvironmentBuilder();
$builder->addNamespace(__NAMESPACE__);
$builder->addNamespace('malkusch\lock\mutex');
$builder->addNamespace('malkusch\lock\util');
$sleep = $builder->build();
$sleep->enable();
Expand Down
5 changes: 2 additions & 3 deletions tests/mutex/TransactionalMutexTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

namespace malkusch\lock\mutex;
namespace malkusch\lock\Tests\mutex;

use malkusch\lock\exception\LockAcquireException;
use malkusch\lock\mutex\TransactionalMutex;
use PHPUnit\Framework\TestCase;

/**
* Tests for TransactionalMutex.
*
* Set the environment variables MYSQL_DSN, MYSQL_USER for this test.
*/
class TransactionalMutexTest extends TestCase
Expand Down
3 changes: 2 additions & 1 deletion tests/util/DoubleCheckedLockingTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace malkusch\lock\util;
namespace malkusch\lock\Tests\util;

use malkusch\lock\mutex\Mutex;
use malkusch\lock\util\DoubleCheckedLocking;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand Down
4 changes: 3 additions & 1 deletion tests/util/LoopTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace malkusch\lock\util;
namespace malkusch\lock\Tests\util;

use malkusch\lock\exception\TimeoutException;
use malkusch\lock\util\Loop;
use phpmock\environment\SleepEnvironmentBuilder;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\TestCase;
Expand All @@ -18,6 +19,7 @@ protected function setUp(): void

$builder = new SleepEnvironmentBuilder();
$builder->addNamespace(__NAMESPACE__);
$builder->addNamespace('malkusch\lock\util');
$sleep = $builder->build();
$sleep->enable();

Expand Down
5 changes: 2 additions & 3 deletions tests/util/PcntlTimeoutTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

namespace malkusch\lock\util;
namespace malkusch\lock\Tests\util;

use malkusch\lock\exception\DeadlineException;
use malkusch\lock\exception\LockAcquireException;
use malkusch\lock\util\PcntlTimeout;
use PHPUnit\Framework\TestCase;

/**
* Tests for PcntlTimeout.
*
* @requires pcntl
*/
class PcntlTimeoutTest extends TestCase
Expand Down

0 comments on commit 62577c7

Please sign in to comment.