Skip to content

Upgrade "php-mock/php-mock-phpunit" dev package #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
"ergebnis/phpunit-slow-test-detector": "^2.9",
"friendsofphp/php-cs-fixer": "^3.0",
"mikey179/vfsstream": "^1.6.11",
"php-mock/php-mock-phpunit": "^2.1",
"php-mock/php-mock-phpunit": "^2.12",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^9.5.25 || ^10.0 || ^11.0",
"predis/predis": "^1.1.8",
"predis/predis": "^1.1.8 || ^2.0",
"spatie/async": "^1.5"
},
"suggest": {
Expand Down
30 changes: 15 additions & 15 deletions tests/Mutex/DistributedMutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ public function testAcquireWithMajority(int $count, int $available): void
$mutex->synchronized(static function () {});
}

/**
* Provides test cases with enough.
*
* @return iterable<list<mixed>>
*/
public static function provideMajorityCases(): iterable
{
yield [1, 1];
yield [2, 2];
yield [3, 2];
yield [3, 3];
yield [4, 3];
yield [5, 3];
}

/**
* Tests releasing fails because too few servers are available.
*
Expand Down Expand Up @@ -312,21 +327,6 @@ public static function provideMinorityCases(): iterable
yield [6, 3];
}

/**
* Provides test cases with enough.
*
* @return iterable<list<mixed>>
*/
public static function provideMajorityCases(): iterable
{
yield [1, 1];
yield [2, 2];
yield [3, 2];
yield [3, 3];
yield [4, 3];
yield [5, 3];
}

public function testAcquireMutexLogger(): void
{
$mutex = $this->createDistributedMutexMock(3);
Expand Down
108 changes: 54 additions & 54 deletions tests/Mutex/MutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,60 @@ public static function setUpBeforeClass(): void
vfsStream::setup('test');
}

/**
* Tests synchronized() executes the code and returns its result.
*
* @param \Closure(): Mutex $mutexFactory
*
* @dataProvider provideMutexFactoriesCases
*/
#[DataProvider('provideMutexFactoriesCases')]
public function testSynchronizedDelegates(\Closure $mutexFactory): void
{
$mutex = $mutexFactory();
$result = $mutex->synchronized(static function () {
return 'test';
});
self::assertSame('test', $result);
}

/**
* Tests that synchronized() released the lock.
*
* @param \Closure(): Mutex $mutexFactory
*
* @doesNotPerformAssertions
*
* @dataProvider provideMutexFactoriesCases
*/
#[DoesNotPerformAssertions]
#[DataProvider('provideMutexFactoriesCases')]
public function testRelease(\Closure $mutexFactory): void
{
$mutex = $mutexFactory();
$mutex->synchronized(static function () {});

$mutex->synchronized(static function () {});
}

/**
* Tests synchronized() rethrows the exception of the code.
*
* @param \Closure(): Mutex $mutexFactory
*
* @dataProvider provideMutexFactoriesCases
*/
#[DataProvider('provideMutexFactoriesCases')]
public function testSynchronizedPassesExceptionThrough(\Closure $mutexFactory): void
{
$mutex = $mutexFactory();

$this->expectException(\DomainException::class);
$mutex->synchronized(static function () {
throw new \DomainException();
});
}

/**
* Provides Mutex factories.
*
Expand Down Expand Up @@ -188,58 +242,4 @@ static function ($uri) {
}];
}
}

/**
* Tests synchronized() executes the code and returns its result.
*
* @param \Closure(): Mutex $mutexFactory
*
* @dataProvider provideMutexFactoriesCases
*/
#[DataProvider('provideMutexFactoriesCases')]
public function testSynchronizedDelegates(\Closure $mutexFactory): void
{
$mutex = $mutexFactory();
$result = $mutex->synchronized(static function () {
return 'test';
});
self::assertSame('test', $result);
}

/**
* Tests that synchronized() released the lock.
*
* @param \Closure(): Mutex $mutexFactory
*
* @doesNotPerformAssertions
*
* @dataProvider provideMutexFactoriesCases
*/
#[DoesNotPerformAssertions]
#[DataProvider('provideMutexFactoriesCases')]
public function testRelease(\Closure $mutexFactory): void
{
$mutex = $mutexFactory();
$mutex->synchronized(static function () {});

$mutex->synchronized(static function () {});
}

/**
* Tests synchronized() rethrows the exception of the code.
*
* @param \Closure(): Mutex $mutexFactory
*
* @dataProvider provideMutexFactoriesCases
*/
#[DataProvider('provideMutexFactoriesCases')]
public function testSynchronizedPassesExceptionThrough(\Closure $mutexFactory): void
{
$mutex = $mutexFactory();

$this->expectException(\DomainException::class);
$mutex->synchronized(static function () {
throw new \DomainException();
});
}
}
36 changes: 18 additions & 18 deletions tests/Mutex/RedisMutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,24 +258,6 @@ public function testSerializersAndCompressors(int $serializer, int $compressor):
}));
}

public function testResistantToPartialClusterFailuresForAcquiringLock(): void
{
$this->closeMinorityConnections();

self::assertSame('test', $this->mutex->synchronized(static function () {
return 'test';
}));
}

public function testResistantToPartialClusterFailuresForReleasingLock(): void
{
self::assertNull($this->mutex->synchronized(function () { // @phpstan-ignore staticMethod.alreadyNarrowedType
$this->closeMinorityConnections();

return null;
}));
}

/**
* @return iterable<list<mixed>>
*/
Expand Down Expand Up @@ -313,4 +295,22 @@ public static function provideSerializersAndCompressorsCases(): iterable
}
}
}

public function testResistantToPartialClusterFailuresForAcquiringLock(): void
{
$this->closeMinorityConnections();

self::assertSame('test', $this->mutex->synchronized(static function () {
return 'test';
}));
}

public function testResistantToPartialClusterFailuresForReleasingLock(): void
{
self::assertNull($this->mutex->synchronized(function () { // @phpstan-ignore staticMethod.alreadyNarrowedType
$this->closeMinorityConnections();

return null;
}));
}
}