resolveDistrictBit('79991234567'))->toBe(0xFF); }); it('Moscow code 495 returns Central district bit (1)', function (): void { $service = new PhonePrefixService; expect($service->resolveDistrictBit('74951234567'))->toBe(1); }); it('Saint-Petersburg code 812 returns Northwest district bit (2)', function (): void { $service = new PhonePrefixService; expect($service->resolveDistrictBit('78121234567'))->toBe(2); }); it('Yekaterinburg code 343 returns Ural district bit (32)', function (): void { $service = new PhonePrefixService; expect($service->resolveDistrictBit('73431234567'))->toBe(32); }); it('unknown code returns all-districts mask (defensive default)', function (): void { $service = new PhonePrefixService; expect($service->resolveDistrictBit('70001234567'))->toBe(0xFF); }); it('rejects invalid phone formats', function (): void { $service = new PhonePrefixService; expect(fn () => $service->resolveDistrictBit('123'))->toThrow(InvalidArgumentException::class); expect(fn () => $service->resolveDistrictBit('+79991234567'))->toThrow(InvalidArgumentException::class); expect(fn () => $service->resolveDistrictBit('89991234567'))->toThrow(InvalidArgumentException::class); }); it('phoneMatchesRegions: include + matching bit', function (): void { $service = new PhonePrefixService; expect($service->phoneMatchesRegions('74951234567', regionMask: 1, regionMode: 'include'))->toBeTrue(); expect($service->phoneMatchesRegions('74951234567', regionMask: 2, regionMode: 'include'))->toBeFalse(); }); it('phoneMatchesRegions: exclude inverts logic', function (): void { $service = new PhonePrefixService; expect($service->phoneMatchesRegions('74951234567', regionMask: 1, regionMode: 'exclude'))->toBeFalse(); expect($service->phoneMatchesRegions('74951234567', regionMask: 2, regionMode: 'exclude'))->toBeTrue(); }); it('mobile (all-districts) always passes include any-bit', function (): void { $service = new PhonePrefixService; expect($service->phoneMatchesRegions('79991234567', regionMask: 1, regionMode: 'include'))->toBeTrue(); expect($service->phoneMatchesRegions('79991234567', regionMask: 255, regionMode: 'include'))->toBeTrue(); });