justReturn(''); self::assertFalse((new InstructorNotificationPref())->wants(7)); } public function testReadsAStoredOptIn(): void { Functions\when('get_user_meta')->alias( static fn (int $id, string $key): string => 7 === $id && InstructorNotificationPref::META_NOTIFY === $key ? '1' : '' ); self::assertTrue((new InstructorNotificationPref())->wants(7)); } public function testAStoredNoReadsAsOff(): void { Functions\when('get_user_meta')->justReturn('0'); self::assertFalse((new InstructorNotificationPref())->wants(7)); } public function testNobodyWantsNothing(): void { // A zero id is not a user; it must never read as opted-in. Functions\expect('get_user_meta')->never(); self::assertFalse((new InstructorNotificationPref())->wants(0)); } public function testSetStoresTheChoiceAsAStringBoolean(): void { Functions\expect('update_user_meta')->once()->with(7, InstructorNotificationPref::META_NOTIFY, '1')->andReturn(true); (new InstructorNotificationPref())->set(7, true); } public function testSetStoresADeliberateNoRatherThanDeleting(): void { Functions\expect('update_user_meta')->once()->with(7, InstructorNotificationPref::META_NOTIFY, '0')->andReturn(true); (new InstructorNotificationPref())->set(7, false); } public function testSetIgnoresANonUser(): void { Functions\expect('update_user_meta')->never(); (new InstructorNotificationPref())->set(0, true); } }