Closed
Description
Symfony version(s) affected
7.0+
Description
As part of #50852 the return types for both methods in Symfony\Component\Lock\LockFactory
were narrowed from the base LockInterface
to the SharedLockInterface
. In some test cases, we are mocking the lock factory and the mock provides a NoLock
instance to disable locks in the context of those tests. Since NoLock
does not implement SharedLockInterface
, using it with the LockFactory
is no longer possible.
How to reproduce
$lockFactory = $this->createMock(LockFactory::class);
$lockFactory->method('createLock')
->willReturnCallback(static fn () => new NoLock());
// Test fails with:
// TypeError : Mock_LockFactory_a4c266f2::createLock(): Return value must be of type Symfony\Component\Lock\SharedLockInterface, Symfony\Component\Lock\NoLock returned
Possible Solution
One of:
- Restore the return type of the
LockFactory
methods to the baseLockInterface
- Implement
SharedLockInterface
in theNoLock
class
Additional Context
No response