Description
Description
A fairly small issue, but when using the RateLimiter component, it's impossible to build UnitTests as the Symfony\Component\RateLimiter\RateLimiterFactory
class is marked as final
but doesn't implement an interface. This can be mitigated with reflection, but causes a poor developer experience. As there is also no way to inject a new type of limiter into this factory, this becomes non-trivial to implement a unit test, as you have to mock both the StorageInterface
and LockFactory
classes, inspecting how they are used in the standard implementations.
Simple fix: Add a RateLimiterFactoryInterface
More complete fix: Add a method in which to inject new types of rate limiter into the Factory. This would allow for alternative rate limiting strategies such as the Leaky Bucket which currently doesn't have an implementation.
Example
Running this code:
<?php
class RateLimitFactoryTest extends TestCase
{
/** @var RateLimiterFactory|MockObject */
private RateLimiterFactory $globalLimiter;
protected function testLimitFactory()
{
$this->createMock(RateLimiterFactory::class);
}
}
Throws an exception because the class is final
.