@@ -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}
0 commit comments