fix: PHPStan and test strictness improvements
Add bin/ scripts to PHPStan scanFiles, suppress property.onlyWritten for by-ref test properties, add exhaustive default match arm, use explicit expects() on mock stubs, fix data provider return type, and simplify redundant null check in NotificationServiceTest. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -42,7 +42,7 @@ class ModuleI18nContractTest extends TestCase
|
||||
$modules[$moduleId] = [$moduleId, $resolvedPath];
|
||||
}
|
||||
|
||||
return $modules;
|
||||
return array_values($modules);
|
||||
}
|
||||
|
||||
#[DataProvider('moduleProvider')]
|
||||
|
||||
@@ -28,6 +28,7 @@ class SettingsDefaultsGatewayTest extends TestCase
|
||||
'setDefaultTenantId' => $tenantRepository->expects($this->once())->method('find')->with($id)->willReturn(null),
|
||||
'setDefaultRoleId' => $roleRepository->expects($this->once())->method('find')->with($id)->willReturn(null),
|
||||
'setDefaultDepartmentId' => $departmentRepository->expects($this->once())->method('find')->with($id)->willReturn(null),
|
||||
default => throw new \LogicException("Unknown setter: {$setter}"),
|
||||
};
|
||||
|
||||
$this->assertFalse($gateway->$setter($id));
|
||||
|
||||
@@ -59,7 +59,7 @@ final class SettingsSessionPolicyGatewayTest extends TestCase
|
||||
self::assertFalse($gateway->isMicrosoftAutoRememberDefault());
|
||||
|
||||
$metadataTrue = $this->createMock(SettingsMetadataGateway::class);
|
||||
$metadataTrue->method('getValue')->with('microsoft_auto_remember_default')->willReturn('1');
|
||||
$metadataTrue->expects($this->any())->method('getValue')->with('microsoft_auto_remember_default')->willReturn('1');
|
||||
$gatewayTrue = new SettingsLoginPersistenceGateway($metadataTrue);
|
||||
self::assertTrue($gatewayTrue->isMicrosoftAutoRememberDefault());
|
||||
}
|
||||
@@ -82,13 +82,13 @@ final class SettingsSessionPolicyGatewayTest extends TestCase
|
||||
public function testRememberTokenLifetimeUsesFallbackWhenMissingOrInvalid(): void
|
||||
{
|
||||
$metadataMissing = $this->createMock(SettingsMetadataGateway::class);
|
||||
$metadataMissing->method('getInt')->with('remember_token_lifetime_days')->willReturn(null);
|
||||
$metadataMissing->expects($this->any())->method('getInt')->with('remember_token_lifetime_days')->willReturn(null);
|
||||
$gatewayMissing = new SettingsLoginPersistenceGateway($metadataMissing);
|
||||
self::assertSame(30, $gatewayMissing->getRememberTokenLifetimeDays());
|
||||
self::assertSame(30 * 86400, $gatewayMissing->getRememberTokenLifetimeSeconds());
|
||||
|
||||
$metadataInvalid = $this->createMock(SettingsMetadataGateway::class);
|
||||
$metadataInvalid->method('getInt')->with('remember_token_lifetime_days')->willReturn(500);
|
||||
$metadataInvalid->expects($this->any())->method('getInt')->with('remember_token_lifetime_days')->willReturn(500);
|
||||
$gatewayInvalid = new SettingsLoginPersistenceGateway($metadataInvalid);
|
||||
self::assertSame(30, $gatewayInvalid->getRememberTokenLifetimeDays());
|
||||
}
|
||||
@@ -96,7 +96,7 @@ final class SettingsSessionPolicyGatewayTest extends TestCase
|
||||
public function testRememberTokenLifetimeAcceptsValidRangeAndComputesSeconds(): void
|
||||
{
|
||||
$metadata = $this->createMock(SettingsMetadataGateway::class);
|
||||
$metadata->method('getInt')->with('remember_token_lifetime_days')->willReturn(7);
|
||||
$metadata->expects($this->any())->method('getInt')->with('remember_token_lifetime_days')->willReturn(7);
|
||||
$metadata->expects($this->once())
|
||||
->method('set')
|
||||
->with('remember_token_lifetime_days', '14', $this->anything())
|
||||
|
||||
@@ -17,8 +17,11 @@ final class ModuleEventDispatcherTest extends TestCase
|
||||
|
||||
$listener = new class ($called, $capturedEvent, $capturedPayload) implements EventListener {
|
||||
public function __construct(
|
||||
/** @phpstan-ignore property.onlyWritten */
|
||||
private bool &$called,
|
||||
/** @phpstan-ignore property.onlyWritten */
|
||||
private string &$capturedEvent,
|
||||
/** @phpstan-ignore property.onlyWritten */
|
||||
private array &$capturedPayload
|
||||
) {
|
||||
}
|
||||
@@ -69,7 +72,7 @@ final class ModuleEventDispatcherTest extends TestCase
|
||||
};
|
||||
|
||||
$successListener = new class ($secondCalled) implements EventListener {
|
||||
public function __construct(private bool &$called)
|
||||
public function __construct(/** @phpstan-ignore property.onlyWritten */ private bool &$called)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user