public function testRun()
{
$this->resetDb();
$app = $this->getApp();
/** @var Repository\UsersRepository $repo */
$repo = $app['storage']->getRepository('Bolt\\Storage\\Entity\\Users');
$user = new Entity\Users(['username' => 'koala', 'password' => 'GumL3@ve$', 'email' => '[email protected]', 'displayname' => 'Drop Bear', 'roles' => ['root']]);
$repo->save($user);
$command = new UserResetPassword($app);
$tester = new CommandTester($command);
$helper = $this->getMockBuilder(QuestionHelper::class)->setMethods(['ask'])->getMock();
$helper->expects($this->once())->method('ask')->will($this->returnValue(true));
$set = new HelperSet(['question' => $helper]);
$command->setHelperSet($set);
$tester->execute(['username' => 'koala'], ['interactive' => false]);
$result = $tester->getDisplay();
$this->assertRegExp('#New password for koala is #', trim($result));
$this->assertSame(38, strlen(trim($result)));
// Test that the saved value matches the hash
$repo = $app['storage']->getRepository('Bolt\\Storage\\Entity\\Users');
$userEntity = $repo->getUser('koala');
$userAuth = $repo->getUserAuthData($userEntity->getId());
$crypt = new PasswordLib();
// Check the old password isn't valid
$auth = $crypt->verifyPasswordHash('GumL3@ve$', $userAuth->getPassword());
$this->assertFalse($auth);
// Check the new password is valid
$bits = explode(' ', trim($result));
$auth = $crypt->verifyPasswordHash($bits[5], $userAuth->getPassword());
$this->assertTrue($auth);
}