remove default values from user constructors

Forcing every call site to be explicit about admin status and
password eliminates a class of bugs where an unintended
isAdmin=false or empty passwordHash could silently slip through.
The CreateUserTest case that asserted the isAdmin default is
dropped since the default no longer exists.
This commit is contained in:
Yisroel Baum 2026-04-26 10:46:07 +03:00
parent f95adddaaf
commit cd40483cd4
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
7 changed files with 21 additions and 14 deletions

View file

@ -36,6 +36,8 @@ class CreateSessionTest extends TestCase
$this->user = new User(
id: 7,
email: new EmailAddress('test@test.com'),
passwordHash: 'hashed:password1',
isAdmin: false,
);
}

View file

@ -30,7 +30,12 @@ class CreateScheduledNodeTest extends TestCase
$this->planRepo = new FakePlanRepository();
$this->planRepo->create(new CreatePlanDto(
name: 'testplan',
user: new User(0, new EmailAddress('test@test.com')),
user: new User(
id: 0,
email: new EmailAddress('test@test.com'),
passwordHash: 'hashed:password1',
isAdmin: false,
),
));
$this->useCase = new CreateScheduledNode(
$this->scheduledNodeRepo,

View file

@ -30,6 +30,7 @@ class AuthenticateUserTest extends TestCase
$createUser->execute(new CreateUserRequest(
email: 'test@test.com',
password: 'password1',
isAdmin: false,
));
$this->useCase = new AuthenticateUser(
$this->userRepo,

View file

@ -31,6 +31,7 @@ class CreateUserTest extends TestCase
$this->useCase->execute(new CreateUserRequest(
email: 'test@test.com',
password: 'password1',
isAdmin: false,
));
$user = $this->userRepo->find(0);
$this->assertInstanceOf(User::class, $user);
@ -44,17 +45,9 @@ class CreateUserTest extends TestCase
$this->useCase->execute(new CreateUserRequest(
email: null,
));
}
public function test_is_admin_defaults_to_false(): void
{
$this->useCase->execute(new CreateUserRequest(
email: 'test@test.com',
password: 'password1',
isAdmin: false,
));
$user = $this->userRepo->find(0);
$this->assertFalse($user->isAdmin());
}
public function test_is_admin_can_be_set_true(): void
@ -73,6 +66,7 @@ class CreateUserTest extends TestCase
$this->useCase->execute(new CreateUserRequest(
email: 'test@test.com',
password: 'password1',
isAdmin: false,
));
$this->expectException(BadRequestException::class);
@ -81,6 +75,7 @@ class CreateUserTest extends TestCase
$this->useCase->execute(new CreateUserRequest(
email: 'test@test.com',
password: 'password1',
isAdmin: false
));
}
@ -92,6 +87,7 @@ class CreateUserTest extends TestCase
$this->useCase->execute(new CreateUserRequest(
email: 'test@test.com',
password: null,
isAdmin: false,
));
}
@ -105,6 +101,7 @@ class CreateUserTest extends TestCase
$this->useCase->execute(new CreateUserRequest(
email: 'test@test.com',
password: 'short',
isAdmin: false,
));
}
@ -113,6 +110,7 @@ class CreateUserTest extends TestCase
$this->useCase->execute(new CreateUserRequest(
email: 'test@test.com',
password: 'password1',
isAdmin: false,
));
$user = $this->userRepo->find(0);
$this->assertNotEquals('password1', $user->getPasswordHash());