diff --git a/appinfo/app.php b/appinfo/app.php index 189984f5..7358889b 100755 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -72,9 +72,8 @@ // only load notification JS code in the logged in layout page (not public links not login page) $request = \OC::$server->getRequest(); if (\OC::$server->getUserSession() !== null && \OC::$server->getUserSession()->getUser() !== null - && substr($request->getScriptName(), 0 - strlen('/index.php')) === '/index.php' - && substr($request->getPathInfo(), 0, strlen('/s/')) !== '/s/' - && substr($request->getPathInfo(), 0, strlen('/login')) !== '/login') { - + && \substr($request->getScriptName(), 0 - \strlen('/index.php')) === '/index.php' + && \substr($request->getPathInfo(), 0, \strlen('/s/')) !== '/s/' + && \substr($request->getPathInfo(), 0, \strlen('/login')) !== '/login') { \OCP\Util::addScript('password_policy', 'notification'); } diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index c47a56bc..fef9b492 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -25,8 +25,7 @@ use OCA\PasswordPolicy\Notifier; class Application extends App { - - public function __construct (array $urlParams = []) { + public function __construct(array $urlParams = []) { parent::__construct('password_policy', $urlParams); } diff --git a/lib/Authentication/AccountModule.php b/lib/Authentication/AccountModule.php index d6c291e8..232177ab 100644 --- a/lib/Authentication/AccountModule.php +++ b/lib/Authentication/AccountModule.php @@ -62,7 +62,7 @@ public function check(IUser $user) { if ($forcePasswordChange) { $redirectUrl = $this->request->getRequestUri(); $response = new RedirectResponse( - $this->urlGenerator->linkToRoute( 'password_policy.password.show', [ + $this->urlGenerator->linkToRoute('password_policy.password.show', [ 'redirect_url' => $redirectUrl ]) ); diff --git a/lib/Command/ExpirePassword.php b/lib/Command/ExpirePassword.php index 09af7921..d15ec680 100644 --- a/lib/Command/ExpirePassword.php +++ b/lib/Command/ExpirePassword.php @@ -35,7 +35,6 @@ use Symfony\Component\Console\Output\OutputInterface; use OCP\AppFramework\Utility\ITimeFactory; - class ExpirePassword extends Command { /** * Catchall for general errors @@ -64,7 +63,6 @@ class ExpirePassword extends Command { /** @var OldPasswordMapper */ private $mapper; - /** * ExpirePassword constructor. * @@ -200,7 +198,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { * @param $inputExpireDate * @param IUser $user */ - protected function setPasswordExpiry(\DateTime $expireDate, \DateTime $oldDate, \DateTimeZone $timeZone, $inputExpireDate , IUser $user) { + protected function setPasswordExpiry(\DateTime $expireDate, \DateTime $oldDate, \DateTimeZone $timeZone, $inputExpireDate, IUser $user) { $expireDate->setTimezone($timeZone); $expireDate->setTimestamp($this->timeFactory->getTime()); $expireDate->modify($inputExpireDate); diff --git a/lib/Controller/PasswordController.php b/lib/Controller/PasswordController.php index 23934026..7376aa2d 100644 --- a/lib/Controller/PasswordController.php +++ b/lib/Controller/PasswordController.php @@ -146,7 +146,7 @@ public function show($redirect_url) { */ public function update($current_password, $new_password, $confirm_password, $redirect_url) { $user = $this->userSession->getUser(); - if(($user !== null) && !$this->userManager->checkPassword($user->getUID(), $current_password)) { + if (($user !== null) && !$this->userManager->checkPassword($user->getUID(), $current_password)) { return $this->createPasswordTemplateResponse( $redirect_url, $this->l10n->t('Old password is wrong.') diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 70eeb2a1..7877576b 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -109,7 +109,7 @@ public function getPriority() { public function getPanel() { $template = new Template('password_policy', 'admin'); - foreach(self::DEFAULTS as $key => $default) { + foreach (self::DEFAULTS as $key => $default) { $value = $this->config->getAppValue('password_policy', $key, $default); if (isset(self::CONVERSIONS[$key]['out'])) { $convertFuncName = self::CONVERSIONS[$key]['out']; diff --git a/lib/Db/OldPassword.php b/lib/Db/OldPassword.php index a4cc2ebc..bd28f7ac 100644 --- a/lib/Db/OldPassword.php +++ b/lib/Db/OldPassword.php @@ -23,6 +23,7 @@ namespace OCA\PasswordPolicy\Db; use OCP\AppFramework\Db\Entity; + /** * @method int getId() * @method void setId(\int $id) @@ -33,7 +34,6 @@ * @method void setChangeTime(\int $changeTime) */ class OldPassword extends Entity { - const EXPIRED = 'expired'; /** @var string $uid */ @@ -48,4 +48,4 @@ class OldPassword extends Entity { public function getPassword() { return $this->password; } -} \ No newline at end of file +} diff --git a/lib/Db/OldPasswordMapper.php b/lib/Db/OldPasswordMapper.php index 15dff7df..5073933d 100644 --- a/lib/Db/OldPasswordMapper.php +++ b/lib/Db/OldPasswordMapper.php @@ -27,7 +27,6 @@ use OCP\IDBConnection; class OldPasswordMapper extends Mapper { - public function __construct(IDBConnection $db) { parent::__construct($db, 'user_password_history'); } diff --git a/lib/HooksHandler.php b/lib/HooksHandler.php index 9f6ec5ec..482174f3 100644 --- a/lib/HooksHandler.php +++ b/lib/HooksHandler.php @@ -188,7 +188,7 @@ public function updateLinkExpiry($params) { if ($days !== null) { $date = new \DateTime(); - $date->setTime(0,0,0); + $date->setTime(0, 0, 0); $date->add(new \DateInterval('P'.$days.'D')); if ($params['expirationDate'] === null) { @@ -272,7 +272,7 @@ protected function forcePasswordChange($firstLogin = null, IUser $user = null) { */ private function getUser(GenericEvent $event) { $user = $event->getArgument('user'); - if(!$user instanceof IUser) { + if (!$user instanceof IUser) { throw new \UnexpectedValueException("'$user' is not an instance of IUser."); } return $user; @@ -319,7 +319,7 @@ public function checkAdminRequestedPasswordChange(GenericEvent $event) { public function checkForcePasswordChangeOnFirstLogin(GenericEvent $event) { $this->fixDI(); $user = $event->getSubject(); - if(!$user instanceof IUser) { + if (!$user instanceof IUser) { throw new \UnexpectedValueException("'$user' is not an instance of IUser."); } // If option is enabled in security settings check first login diff --git a/lib/Rules/Base.php b/lib/Rules/Base.php index 0bc60999..b1ef04ee 100644 --- a/lib/Rules/Base.php +++ b/lib/Rules/Base.php @@ -34,6 +34,4 @@ class Base { public function __construct(IL10N $l10n) { $this->l10n = $l10n; } - } - diff --git a/lib/Rules/Length.php b/lib/Rules/Length.php index 6d7530ee..03cf9b0b 100644 --- a/lib/Rules/Length.php +++ b/lib/Rules/Length.php @@ -34,5 +34,4 @@ public function verify($password, $val) { $this->l10n->t('The password is too short. At least %d characters are required.', [$val])); } } - } diff --git a/lib/Rules/Lowercase.php b/lib/Rules/Lowercase.php index 951b53e8..738b8219 100644 --- a/lib/Rules/Lowercase.php +++ b/lib/Rules/Lowercase.php @@ -51,5 +51,4 @@ private function countLowercase($s) { } return $count; } - } diff --git a/lib/Rules/Numbers.php b/lib/Rules/Numbers.php index 34cc3119..dab81a6b 100644 --- a/lib/Rules/Numbers.php +++ b/lib/Rules/Numbers.php @@ -40,7 +40,7 @@ public function verify($password, $val) { } } - private function countDigits( $str ) { - return \preg_match_all( '/[0-9]/', $str ); + private function countDigits($str) { + return \preg_match_all('/[0-9]/', $str); } } diff --git a/lib/Rules/PasswordHistory.php b/lib/Rules/PasswordHistory.php index c7f1e55c..23bd5d7a 100644 --- a/lib/Rules/PasswordHistory.php +++ b/lib/Rules/PasswordHistory.php @@ -55,14 +55,14 @@ public function __construct( * @throws PolicyException */ public function verify($password, $val, $uid) { - if(empty($uid)) { + if (empty($uid)) { return; } $oldPasswords = $this->mapper->getOldPasswords( $uid, $val ); - foreach($oldPasswords as $oldPassword) { + foreach ($oldPasswords as $oldPassword) { if ($this->hasher->verify($password, $oldPassword->getPassword())) { throw new PolicyException( $this->l10n->t('The password must be different than your previous %d passwords.', [$val]) diff --git a/lib/Rules/Special.php b/lib/Rules/Special.php index f313ab05..0aaf90ff 100644 --- a/lib/Rules/Special.php +++ b/lib/Rules/Special.php @@ -33,7 +33,7 @@ public function verify($password, $val, $allowedSpecialChars) { $special = $this->stripAlphaNumeric($password); if (!empty($allowedSpecialChars) && !empty($special)) { $allowedSpecialCharsAsArray = \str_split($allowedSpecialChars); - $s = \array_filter(\str_split($special), function($char) use ($allowedSpecialCharsAsArray){ + $s = \array_filter(\str_split($special), function ($char) use ($allowedSpecialCharsAsArray) { return !\in_array($char, $allowedSpecialCharsAsArray, true); }); if (\count($s) > 0) { @@ -63,9 +63,7 @@ public function verify($password, $val, $allowedSpecialChars) { } } - private function stripAlphaNumeric( $string ) { - return \preg_replace( '/[a-z0-9]/i', '', $string ); + private function stripAlphaNumeric($string) { + return \preg_replace('/[a-z0-9]/i', '', $string); } - } - diff --git a/lib/Rules/Uppercase.php b/lib/Rules/Uppercase.php index 8d314e45..741db0f2 100644 --- a/lib/Rules/Uppercase.php +++ b/lib/Rules/Uppercase.php @@ -51,5 +51,4 @@ private function countUppercase($s) { } return $count; } - } diff --git a/templates/password.php b/templates/password.php index 9d9940f8..25c14949 100644 --- a/templates/password.php +++ b/templates/password.php @@ -50,7 +50,9 @@ ?> -
+ diff --git a/tests/Command/ExpirePasswordTest.php b/tests/Command/ExpirePasswordTest.php index 7f25d12e..cf32f063 100644 --- a/tests/Command/ExpirePasswordTest.php +++ b/tests/Command/ExpirePasswordTest.php @@ -225,7 +225,7 @@ public function testExpirePassword( $oldPassword = null; $this->mapper->expects($this->once()) ->method('insert') - ->will($this->returnCallback(function($obj) use (&$oldPassword) { + ->will($this->returnCallback(function ($obj) use (&$oldPassword) { $oldPassword = $obj; })); diff --git a/tests/Controller/PasswordControllerTest.php b/tests/Controller/PasswordControllerTest.php index 131413aa..1d927775 100644 --- a/tests/Controller/PasswordControllerTest.php +++ b/tests/Controller/PasswordControllerTest.php @@ -68,8 +68,8 @@ public function setUp() { $this->l10n = $this->createMock(IL10N::class); $this->l10n ->method('t') - ->will($this->returnCallback(function($text, $parameters = array()) { - return vsprintf($text, $parameters); + ->will($this->returnCallback(function ($text, $parameters = []) { + return \vsprintf($text, $parameters); })); $this->c = $this->getMockBuilder(PasswordController::class) ->setConstructorArgs([ diff --git a/tests/EngineTest.php b/tests/EngineTest.php index b617017e..7dea0bd4 100644 --- a/tests/EngineTest.php +++ b/tests/EngineTest.php @@ -31,7 +31,6 @@ use Test\TestCase; class EngineTest extends TestCase { - private $defaults = [ 'spv_min_chars_checked' => false, 'spv_min_chars_value' => 8, @@ -62,7 +61,7 @@ protected function setUp() { $this->l10n = $this->createMock(IL10N::class); $this->l10n ->method('t') - ->will($this->returnCallback(function($text, $parameters = []) { + ->will($this->returnCallback(function ($text, $parameters = []) { return \vsprintf($text, $parameters); })); diff --git a/tests/HooksHandlerTest.php b/tests/HooksHandlerTest.php index 28305a81..a0a67e2a 100644 --- a/tests/HooksHandlerTest.php +++ b/tests/HooksHandlerTest.php @@ -75,7 +75,7 @@ protected function setUp() { $this->l10n = $this->createMock(IL10N::class); $this->l10n ->method('t') - ->will($this->returnCallback(function($text, $parameters = []) { + ->will($this->returnCallback(function ($text, $parameters = []) { return \vsprintf($text, $parameters); })); $this->passwordExpiredRule = $this->createMock(PasswordExpired::class); @@ -98,31 +98,31 @@ protected function setUp() { ); $this->manager->method('createNotification') - ->will($this->returnCallback(function() { + ->will($this->returnCallback(function () { $holder = []; $mock = $this->createMock(INotification::class); - $mock->method('setApp')->will($this->returnCallback(function($app) use (&$holder, $mock) { + $mock->method('setApp')->will($this->returnCallback(function ($app) use (&$holder, $mock) { $holder['app'] = $app; return $mock; })); - $mock->method('setUser')->will($this->returnCallback(function($user) use (&$holder, $mock) { + $mock->method('setUser')->will($this->returnCallback(function ($user) use (&$holder, $mock) { $holder['user'] = $user; return $mock; })); - $mock->method('setObject')->will($this->returnCallback(function($obj, $id) use (&$holder, $mock) { + $mock->method('setObject')->will($this->returnCallback(function ($obj, $id) use (&$holder, $mock) { $holder['object'] = [$obj, $id]; return $mock; })); - $mock->method('getApp')->will($this->returnCallback(function() use (&$holder) { + $mock->method('getApp')->will($this->returnCallback(function () use (&$holder) { return $holder['app']; })); - $mock->method('getUser')->will($this->returnCallback(function() use (&$holder) { + $mock->method('getUser')->will($this->returnCallback(function () use (&$holder) { return $holder['user']; })); - $mock->method('getObjectType')->will($this->returnCallback(function() use (&$holder) { + $mock->method('getObjectType')->will($this->returnCallback(function () use (&$holder) { return $holder['object'][0]; })); - $mock->method('getObjectId')->will($this->returnCallback(function() use (&$holder) { + $mock->method('getObjectId')->will($this->returnCallback(function () use (&$holder) { return $holder['object'][1]; })); return $mock; @@ -176,10 +176,10 @@ public function testVerifyPublicPassword() { public function updateLinkExpiryProvider() { $tomorrow = new \DateTime(); - $tomorrow->setTime(0,0,0); + $tomorrow->setTime(0, 0, 0); $tomorrow->add(new \DateInterval('P1D')); // tomorrow $in5days = new \DateTime(); - $in5days->setTime(0,0,0); + $in5days->setTime(0, 0, 0); $in5days->add(new \DateInterval('P5D')); // in 5 days $accepted = true; // needs to be reset on every test set @@ -209,7 +209,6 @@ public function testUpdateLinkExpiry($params, $expected) { $params['accepted'] = true; // needs to be reset on every test set $this->handler->updateLinkExpiry($params); self::assertSame($expected, $params['accepted']); - } public function testSaveOldPassword() { @@ -228,7 +227,7 @@ public function testSaveOldPassword() { $this->oldPasswordMapper->expects($this->once()) ->method('insert') - ->with($this->callback(function(OldPassword $oldPassword){ + ->with($this->callback(function (OldPassword $oldPassword) { return $oldPassword->getPassword() === 'somehash' && $oldPassword->getUid() === 'testuid' && $oldPassword->getChangeTime() === 12345; @@ -256,7 +255,7 @@ public function testSavePasswordForCreatedUser() { $this->oldPasswordMapper->expects($this->once()) ->method('insert') - ->with($this->callback(function(OldPassword $oldPassword){ + ->with($this->callback(function (OldPassword $oldPassword) { return $oldPassword->getPassword() === 'somehash' && $oldPassword->getUid() === 'testuid' && $oldPassword->getChangeTime() === 12345; @@ -285,7 +284,7 @@ public function testSaveOldPasswordClearingNotifications() { $this->oldPasswordMapper->expects($this->once()) ->method('insert') - ->with($this->callback(function(OldPassword $oldPassword){ + ->with($this->callback(function (OldPassword $oldPassword) { return $oldPassword->getPassword() === 'somehash' && $oldPassword->getUid() === 'testuid' && $oldPassword->getChangeTime() === 12345; @@ -303,7 +302,7 @@ public function testSaveOldPasswordClearingNotifications() { ->method('markProcessed') ->withConsecutive( [ - $this->callback(function($notif) { + $this->callback(function ($notif) { return $notif->getApp() === 'password_policy' && $notif->getUser() === 'testuid' && $notif->getObjectType() === 'about_to_expire' && @@ -311,7 +310,7 @@ public function testSaveOldPasswordClearingNotifications() { }) ], [ - $this->callback(function($notif) { + $this->callback(function ($notif) { return $notif->getApp() === 'password_policy' && $notif->getUser() === 'testuid' && $notif->getObjectType() === 'expired' && diff --git a/tests/Jobs/PasswordExpirationNotifierJobTest.php b/tests/Jobs/PasswordExpirationNotifierJobTest.php index 6bcdab0f..731f1087 100644 --- a/tests/Jobs/PasswordExpirationNotifierJobTest.php +++ b/tests/Jobs/PasswordExpirationNotifierJobTest.php @@ -102,50 +102,50 @@ protected function setUp() { ); $this->manager->method('createNotification') - ->will($this->returnCallback(function() { + ->will($this->returnCallback(function () { $holder = []; $mock = $this->createMock(INotification::class); - $mock->method('setApp')->will($this->returnCallback(function($app) use (&$holder, $mock) { + $mock->method('setApp')->will($this->returnCallback(function ($app) use (&$holder, $mock) { $holder['app'] = $app; return $mock; })); - $mock->method('setUser')->will($this->returnCallback(function($user) use (&$holder, $mock) { + $mock->method('setUser')->will($this->returnCallback(function ($user) use (&$holder, $mock) { $holder['user'] = $user; return $mock; })); - $mock->method('setObject')->will($this->returnCallback(function($obj, $id) use (&$holder, $mock) { + $mock->method('setObject')->will($this->returnCallback(function ($obj, $id) use (&$holder, $mock) { $holder['object'] = [$obj, $id]; return $mock; })); - $mock->method('setDateTime')->will($this->returnCallback(function($time) use (&$holder, $mock) { + $mock->method('setDateTime')->will($this->returnCallback(function ($time) use (&$holder, $mock) { $holder['datetime'] = $time; return $mock; })); - $mock->method('setSubject')->will($this->returnCallback(function($subject) use (&$holder, $mock) { + $mock->method('setSubject')->will($this->returnCallback(function ($subject) use (&$holder, $mock) { $holder['subject'] = $subject; return $mock; })); - $mock->method('setMessage')->will($this->returnCallback(function($message) use (&$holder, $mock) { + $mock->method('setMessage')->will($this->returnCallback(function ($message) use (&$holder, $mock) { $holder['message'] = $message; return $mock; })); - $mock->method('setLink')->will($this->returnCallback(function($link) use (&$holder, $mock) { + $mock->method('setLink')->will($this->returnCallback(function ($link) use (&$holder, $mock) { $holder['link'] = $link; return $mock; })); - $mock->method('getApp')->will($this->returnCallback(function() use (&$holder) { + $mock->method('getApp')->will($this->returnCallback(function () use (&$holder) { return $holder['app']; })); - $mock->method('getUser')->will($this->returnCallback(function() use (&$holder) { + $mock->method('getUser')->will($this->returnCallback(function () use (&$holder) { return $holder['user']; })); - $mock->method('getObjectType')->will($this->returnCallback(function() use (&$holder) { + $mock->method('getObjectType')->will($this->returnCallback(function () use (&$holder) { return $holder['object'][0]; })); - $mock->method('getObjectId')->will($this->returnCallback(function() use (&$holder) { + $mock->method('getObjectId')->will($this->returnCallback(function () use (&$holder) { return $holder['object'][1]; })); - $mock->method('createAction')->will($this->returnCallback(function() { + $mock->method('createAction')->will($this->returnCallback(function () { $actionMock = $this->createMock(IAction::class); $actionMock->method('setLabel')->will($this->returnSelf()); $actionMock->method('setLink')->will($this->returnSelf()); @@ -320,7 +320,7 @@ public function testRunExpiredMissingUser() { public function providesExpirePassword() { return [ - [md5('password')], + [\md5('password')], // special password [OldPassword::EXPIRED], ]; diff --git a/tests/Rules/LengthTest.php b/tests/Rules/LengthTest.php index 3c35c2bc..7784cf76 100644 --- a/tests/Rules/LengthTest.php +++ b/tests/Rules/LengthTest.php @@ -39,8 +39,8 @@ public function setUp() { $l10n = $this->createMock(IL10N::class); $l10n ->method('t') - ->will($this->returnCallback(function($text, $parameters = array()) { - return vsprintf($text, $parameters); + ->will($this->returnCallback(function ($text, $parameters = []) { + return \vsprintf($text, $parameters); })); $this->r = new Length($l10n); @@ -75,5 +75,4 @@ public function testSpecialCharsTooShort() { public function testSpecialCharsOkay() { $this->r->verify('çççççç', 5); } - } diff --git a/tests/Rules/LowercaseTest.php b/tests/Rules/LowercaseTest.php index 15e22a74..6b311af6 100644 --- a/tests/Rules/LowercaseTest.php +++ b/tests/Rules/LowercaseTest.php @@ -38,16 +38,16 @@ public function setUp() { $l10n = $this->createMock(IL10N::class); $l10n ->method('t') - ->will($this->returnCallback(function($text, $parameters = array()) { - return vsprintf($text, $parameters); + ->will($this->returnCallback(function ($text, $parameters = []) { + return \vsprintf($text, $parameters); })); $l10n ->method('n') - ->will($this->returnCallback(function($text_singular, $text_plural, $count, $parameters = array()) { + ->will($this->returnCallback(function ($text_singular, $text_plural, $count, $parameters = []) { if ($count === 1) { - return (string) vsprintf(str_replace('%n', $count, $text_singular), $parameters); + return (string) \vsprintf(\str_replace('%n', $count, $text_singular), $parameters); } else { - return (string) vsprintf(str_replace('%n', $count, $text_plural), $parameters); + return (string) \vsprintf(\str_replace('%n', $count, $text_plural), $parameters); } })); @@ -107,5 +107,4 @@ public function testNumericOnlyTooShort() { public function testSpecialOnlyTooShort() { $this->r->verify('#+?@#+?@', 5); } - } diff --git a/tests/Rules/NumbersTest.php b/tests/Rules/NumbersTest.php index b9f9cab0..3506d8cc 100644 --- a/tests/Rules/NumbersTest.php +++ b/tests/Rules/NumbersTest.php @@ -37,16 +37,16 @@ public function setUp() { $l10n = $this->createMock(IL10N::class); $l10n ->method('t') - ->will($this->returnCallback(function($text, $parameters = array()) { - return vsprintf($text, $parameters); + ->will($this->returnCallback(function ($text, $parameters = []) { + return \vsprintf($text, $parameters); })); $l10n ->method('n') - ->will($this->returnCallback(function($text_singular, $text_plural, $count, $parameters = array()) { + ->will($this->returnCallback(function ($text_singular, $text_plural, $count, $parameters = []) { if ($count === 1) { - return (string) vsprintf(str_replace('%n', $count, $text_singular), $parameters); + return (string) \vsprintf(\str_replace('%n', $count, $text_singular), $parameters); } else { - return (string) vsprintf(str_replace('%n', $count, $text_plural), $parameters); + return (string) \vsprintf(\str_replace('%n', $count, $text_plural), $parameters); } })); @@ -75,5 +75,4 @@ public function testTooShort() { public function testOkay() { $this->r->verify('1234567890', 6); } - } diff --git a/tests/Rules/PasswordExpiredTest.php b/tests/Rules/PasswordExpiredTest.php index fcbaf165..4856d34d 100644 --- a/tests/Rules/PasswordExpiredTest.php +++ b/tests/Rules/PasswordExpiredTest.php @@ -51,8 +51,8 @@ public function setUp() { $l10n = $this->createMock(IL10N::class); $l10n ->method('t') - ->will($this->returnCallback(function($text, $parameters = array()) { - return vsprintf($text, $parameters); + ->will($this->returnCallback(function ($text, $parameters = []) { + return \vsprintf($text, $parameters); })); $this->logger = $this->createMock(ILogger::class); $this->mapper = $this->createMock(OldPasswordMapper::class); diff --git a/tests/Rules/PasswordHistoryTest.php b/tests/Rules/PasswordHistoryTest.php index 2889f983..3e719288 100644 --- a/tests/Rules/PasswordHistoryTest.php +++ b/tests/Rules/PasswordHistoryTest.php @@ -39,11 +39,10 @@ public function setUp() { $l10n = $this->createMock(IL10N::class); $l10n ->method('t') - ->will($this->returnCallback(function($text, $parameters = array()) { - return vsprintf($text, $parameters); + ->will($this->returnCallback(function ($text, $parameters = []) { + return \vsprintf($text, $parameters); })); - /** @var \OCA\PasswordPolicy\Db\OldPasswordMapper | \PHPUnit_Framework_MockObject_MockObject $mapper */ $mapper = $this->getMockBuilder(OldPasswordMapper::class) ->disableOriginalConstructor()->getMock(); diff --git a/tests/Rules/SpecialTest.php b/tests/Rules/SpecialTest.php index 446ad7cc..a8dccc80 100644 --- a/tests/Rules/SpecialTest.php +++ b/tests/Rules/SpecialTest.php @@ -38,16 +38,16 @@ public function setUp() { $l10n = $this->createMock(IL10N::class); $l10n ->method('t') - ->will($this->returnCallback(function($text, $parameters = array()) { + ->will($this->returnCallback(function ($text, $parameters = []) { return \vsprintf($text, $parameters); })); $l10n ->method('n') - ->will($this->returnCallback(function($text_singular, $text_plural, $count, $parameters = array()) { + ->will($this->returnCallback(function ($text_singular, $text_plural, $count, $parameters = []) { if ($count === 1) { - return (string) vsprintf(str_replace('%n', $count, $text_singular), $parameters); + return (string) \vsprintf(\str_replace('%n', $count, $text_singular), $parameters); } else { - return (string) vsprintf(str_replace('%n', $count, $text_plural), $parameters); + return (string) \vsprintf(\str_replace('%n', $count, $text_plural), $parameters); } })); @@ -89,7 +89,7 @@ public function testInvalidSpecial($expectedMessage, $password, $val, $allowedSp } } - function providesExceptionalData() { + public function providesExceptionalData() { return [ ['The password contains invalid special characters. Only #+ are allowed.', '#+?@#+?@', 4, '#+'], ['The password contains too few special characters. At least one special character is required.', 'Abc123', 1, []], @@ -100,7 +100,7 @@ function providesExceptionalData() { ]; } - function providesTestData() { + public function providesTestData() { return [ ['#+?@#+?@', 6, []], ['#+?@#+?@', 6, '#+?@'], diff --git a/tests/Rules/UppercaseTest.php b/tests/Rules/UppercaseTest.php index 2c5f9c4c..ca6ec2d1 100644 --- a/tests/Rules/UppercaseTest.php +++ b/tests/Rules/UppercaseTest.php @@ -38,16 +38,16 @@ public function setUp() { $l10n = $this->createMock(IL10N::class); $l10n ->method('t') - ->will($this->returnCallback(function($text, $parameters = array()) { - return vsprintf($text, $parameters); + ->will($this->returnCallback(function ($text, $parameters = []) { + return \vsprintf($text, $parameters); })); $l10n ->method('n') - ->will($this->returnCallback(function($text_singular, $text_plural, $count, $parameters = array()) { + ->will($this->returnCallback(function ($text_singular, $text_plural, $count, $parameters = []) { if ($count === 1) { - return (string) vsprintf(str_replace('%n', $count, $text_singular), $parameters); + return (string) \vsprintf(\str_replace('%n', $count, $text_singular), $parameters); } else { - return (string) vsprintf(str_replace('%n', $count, $text_plural), $parameters); + return (string) \vsprintf(\str_replace('%n', $count, $text_plural), $parameters); } })); @@ -107,5 +107,4 @@ public function testNumericOnlyTooShort() { public function testSpecialOnlyTooShort() { $this->r->verify('#+?@#+?@', 5); } - } diff --git a/tests/UserNotificationConfigHandlerTest.php b/tests/UserNotificationConfigHandlerTest.php index 1594b5bf..3e9c59d8 100644 --- a/tests/UserNotificationConfigHandlerTest.php +++ b/tests/UserNotificationConfigHandlerTest.php @@ -266,4 +266,4 @@ public function testResetExpirationMarks() { ); $this->unConfigHandler->resetExpirationMarks('usertest1'); } -} \ No newline at end of file +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e81bfda5..d07649d4 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -19,14 +19,13 @@ * */ - -define('PHPUNIT_RUN', 1); +\define('PHPUNIT_RUN', 1); require_once __DIR__.'/../../../lib/base.php'; OC::$composerAutoloader->addPsr4('Test\\', OC::$SERVERROOT . '/tests/lib', true); -if(!class_exists('PHPUnit_Framework_TestCase')) { +if (!\class_exists('PHPUnit_Framework_TestCase')) { require_once('PHPUnit/Autoload.php'); }