Skip to content

Commit 495b3ac

Browse files
committed
updates
1 parent 6818a25 commit 495b3ac

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

src/Cms/Cli/Commands/User/ResetPasswordCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,13 @@ public function execute( array $parameters = [] ): int
163163
$user->setFailedLoginAttempts( 0 );
164164
$user->setLockedUntil( null );
165165

166-
$repository->update( $user );
166+
$success = $repository->update( $user );
167+
168+
if( !$success )
169+
{
170+
$this->output->error( "Failed to update password in database" );
171+
return 1;
172+
}
167173

168174
$this->output->success( "Password reset successfully for user: " . $user->getUsername() );
169175
$this->output->writeln( "" );

tests/Unit/Cms/Cli/Commands/User/ResetPasswordCommandTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,4 +458,49 @@ public function testExecuteWithEmailOption(): void
458458
$prompts = $this->inputReader->getPromptHistory();
459459
$this->assertCount(3, $prompts);
460460
}
461+
462+
public function testExecuteFailsWhenDatabaseUpdateFails(): void
463+
{
464+
$this->inputReader->addResponses([
465+
'testuser',
466+
'yes',
467+
'NewSecurePass123!',
468+
'NewSecurePass123!'
469+
]);
470+
471+
$user = new User();
472+
$user->setId(1);
473+
$user->setUsername('testuser');
474+
$user->setEmail('test@example.com');
475+
$user->setRole('admin');
476+
477+
$repository = $this->createMock(DatabaseUserRepository::class);
478+
$repository->expects($this->once())
479+
->method('findByUsername')
480+
->willReturn($user);
481+
482+
// update() returns false, simulating database failure
483+
$repository->expects($this->once())
484+
->method('update')
485+
->willReturn(false);
486+
487+
$settings = $this->createMock(SettingManager::class);
488+
Registry::getInstance()->set('Settings', $settings);
489+
490+
$command = $this->getMockBuilder(ResetPasswordCommand::class)
491+
->onlyMethods(['getUserRepository'])
492+
->getMock();
493+
$command->expects($this->once())
494+
->method('getUserRepository')
495+
->willReturn($repository);
496+
497+
$command->setInput($this->input);
498+
$command->setOutput($this->output);
499+
$command->setInputReader($this->inputReader);
500+
501+
$exitCode = $command->execute();
502+
503+
// Should fail with exit code 1
504+
$this->assertEquals(1, $exitCode);
505+
}
461506
}

versionlog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## 0.8.42
2-
* Adds cms:user:password-reset command to reset a user's password from the CLI.
2+
* Adds cms:user:reset-passwordLe command to reset a user's password from the CLI.
33

44
## 0.8.41 2026-01-14
55
* Fix for site name in error pages.

0 commit comments

Comments
 (0)