mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-06 16:36:59 +01:00
chore: Fix tests and PHPStan warnings
Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
@@ -22,7 +22,11 @@
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP;
|
||||
|
||||
use Exception;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* [type] [caller] data
|
||||
@@ -145,7 +149,7 @@ function formatStackTrace(Throwable $e): string
|
||||
/**
|
||||
* Process an exception and log into the error log
|
||||
*
|
||||
* @param \Exception $exception
|
||||
* @param Exception $exception
|
||||
*/
|
||||
function processException(Exception $exception): void
|
||||
{
|
||||
|
||||
@@ -38,6 +38,7 @@ use SP\Infrastructure\File\FileCacheInterface;
|
||||
use SP\Infrastructure\File\FileException;
|
||||
use SP\Infrastructure\File\XmlFileStorageInterface;
|
||||
use SP\Util\PasswordUtil;
|
||||
use function SP\logger;
|
||||
|
||||
defined('APP_ROOT') || die();
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ use SP\Infrastructure\Common\Repositories\RepositoryItemTrait;
|
||||
use SP\Infrastructure\Database\DatabaseInterface;
|
||||
use SP\Infrastructure\Database\QueryData;
|
||||
use SP\Infrastructure\Database\QueryResult;
|
||||
use function SP\__u;
|
||||
use function SP\logger;
|
||||
|
||||
/**
|
||||
* Class AccountRepository
|
||||
@@ -96,7 +98,8 @@ final class AccountRepository extends Repository implements AccountRepositoryInt
|
||||
'Account.key',
|
||||
'Account.parentId',
|
||||
])
|
||||
->where('Account.id = :id', ['id' => $id])
|
||||
->where('Account.id = :id')
|
||||
->bindValues(['id' => $id])
|
||||
->limit(1);
|
||||
|
||||
return $this->db->doSelect(QueryData::build($query));
|
||||
@@ -120,7 +123,8 @@ final class AccountRepository extends Repository implements AccountRepositoryInt
|
||||
'AccountHistory.parentId',
|
||||
'AccountHistory.mPassHash',
|
||||
])
|
||||
->where('AccountHistory.id = :id', ['id' => $id]);
|
||||
->where('AccountHistory.id = :id')
|
||||
->bindValues(['id' => $id]);
|
||||
|
||||
return $this->db->doSelect(QueryData::build($query));
|
||||
}
|
||||
@@ -314,7 +318,7 @@ final class AccountRepository extends Repository implements AccountRepositoryInt
|
||||
$query = $this->queryFactory
|
||||
->newUpdate()
|
||||
->table('Account')
|
||||
->where('id = :id', ['id' => $accountRequest->id])
|
||||
->where('id = :id')
|
||||
->cols([
|
||||
'clientId' => $accountRequest->clientId,
|
||||
'categoryId' => $accountRequest->categoryId,
|
||||
@@ -328,7 +332,8 @@ final class AccountRepository extends Repository implements AccountRepositoryInt
|
||||
'isPrivateGroup' => $accountRequest->isPrivateGroup,
|
||||
'parentId' => $accountRequest->parentId,
|
||||
])
|
||||
->set('dateEdit', 'NOW()');
|
||||
->set('dateEdit', 'NOW()')
|
||||
->bindValues(['id' => $accountRequest->id]);
|
||||
|
||||
if ($accountRequest->changeUserGroup) {
|
||||
$query->col('userGroupId', $accountRequest->userGroupId);
|
||||
|
||||
3
phpstan.neon
Normal file
3
phpstan.neon
Normal file
@@ -0,0 +1,3 @@
|
||||
parameters:
|
||||
bootstrapFiles:
|
||||
- lib/BaseFunctions.php
|
||||
@@ -96,7 +96,12 @@ class AccountRepositoryTest extends UnitaryTestCase
|
||||
{
|
||||
$callback = new Callback(
|
||||
static function (QueryData $arg) {
|
||||
return $arg->getMapClassName() === SimpleModel::class && !empty($arg->getQuery()->getStatement());
|
||||
$query = $arg->getQuery();
|
||||
|
||||
return
|
||||
$query->getBindValues()['id'] === 1
|
||||
&& $arg->getMapClassName() === SimpleModel::class
|
||||
&& !empty($query->getStatement());
|
||||
}
|
||||
);
|
||||
|
||||
@@ -116,7 +121,12 @@ class AccountRepositoryTest extends UnitaryTestCase
|
||||
{
|
||||
$callback = new Callback(
|
||||
static function (QueryData $arg) {
|
||||
return $arg->getMapClassName() === SimpleModel::class && !empty($arg->getQuery());
|
||||
$query = $arg->getQuery();
|
||||
|
||||
return
|
||||
$query->getBindValues()['id'] === 1
|
||||
&& $arg->getMapClassName() === SimpleModel::class
|
||||
&& !empty($query->getStatement());
|
||||
}
|
||||
);
|
||||
|
||||
@@ -447,6 +457,7 @@ class AccountRepositoryTest extends UnitaryTestCase
|
||||
&& $params['isPrivate'] === $accountRequest->isPrivate
|
||||
&& $params['isPrivateGroup'] === $accountRequest->isPrivateGroup
|
||||
&& $params['parentId'] === $accountRequest->parentId
|
||||
&& $params['id'] === $accountRequest->id
|
||||
&& !empty($arg->getQuery()->getStatement());
|
||||
}
|
||||
);
|
||||
@@ -486,6 +497,7 @@ class AccountRepositoryTest extends UnitaryTestCase
|
||||
&& $params['isPrivateGroup'] === $accountRequest->isPrivateGroup
|
||||
&& $params['parentId'] === $accountRequest->parentId
|
||||
&& $params['userGroupId'] === $accountRequest->userGroupId
|
||||
&& $params['id'] === $accountRequest->id
|
||||
&& !empty($arg->getQuery()->getStatement());
|
||||
}
|
||||
);
|
||||
@@ -525,6 +537,7 @@ class AccountRepositoryTest extends UnitaryTestCase
|
||||
&& $params['isPrivateGroup'] === $accountRequest->isPrivateGroup
|
||||
&& $params['parentId'] === $accountRequest->parentId
|
||||
&& $params['userId'] === $accountRequest->userId
|
||||
&& $params['id'] === $accountRequest->id
|
||||
&& !empty($arg->getQuery()->getStatement());
|
||||
}
|
||||
);
|
||||
|
||||
@@ -37,16 +37,18 @@ use SP\Infrastructure\Database\DatabaseConnectionData;
|
||||
use SP\Infrastructure\Database\DbStorageInterface;
|
||||
use SP\Infrastructure\Database\MysqlHandler;
|
||||
use SP\Util\FileUtil;
|
||||
use function SP\logger;
|
||||
use function SP\processException;
|
||||
|
||||
define('DEBUG', true);
|
||||
define('IS_TESTING', true);
|
||||
define('APP_ROOT', dirname(__DIR__, 2));
|
||||
define('TEST_ROOT', dirname(__DIR__));
|
||||
|
||||
const APP_DEFINITIONS_FILE = APP_ROOT . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'Definitions.php';
|
||||
const APP_DEFINITIONS_FILE = APP_ROOT.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'Definitions.php';
|
||||
|
||||
define('RESOURCE_PATH', TEST_ROOT . DIRECTORY_SEPARATOR . 'res');
|
||||
define('CONFIG_PATH', RESOURCE_PATH . DIRECTORY_SEPARATOR . 'config');
|
||||
define('RESOURCE_PATH', TEST_ROOT.DIRECTORY_SEPARATOR.'res');
|
||||
define('CONFIG_PATH', RESOURCE_PATH.DIRECTORY_SEPARATOR.'config');
|
||||
define('CONFIG_FILE', CONFIG_PATH . DIRECTORY_SEPARATOR . 'config.xml');
|
||||
define('ACTIONS_FILE', CONFIG_PATH . DIRECTORY_SEPARATOR . 'actions.xml');
|
||||
define('LOCALES_PATH', APP_ROOT . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'locales');
|
||||
@@ -73,8 +75,12 @@ logger('TEST_ROOT=' . TEST_ROOT);
|
||||
logger('SELF_IP_ADDRESS=' . SELF_IP_ADDRESS);
|
||||
|
||||
// Setup directories
|
||||
recreateDir(TMP_PATH);
|
||||
recreateDir(CACHE_PATH);
|
||||
try {
|
||||
recreateDir(TMP_PATH);
|
||||
recreateDir(CACHE_PATH);
|
||||
} catch (FileNotFoundException $e) {
|
||||
processException($e);
|
||||
}
|
||||
|
||||
if (is_dir(CONFIG_PATH)
|
||||
&& decoct(fileperms(CONFIG_PATH) & 0777) !== '750'
|
||||
@@ -153,23 +159,23 @@ function getResource(string $dir, string $file): string
|
||||
return file_get_contents(RESOURCE_PATH . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $file) ?: '';
|
||||
}
|
||||
|
||||
function saveResource(string $dir, string $file, string $data): string
|
||||
function saveResource(string $dir, string $file, string $data): bool|int
|
||||
{
|
||||
return file_put_contents(RESOURCE_PATH . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $file, $data);
|
||||
return file_put_contents(RESOURCE_PATH.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$file, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FileNotFoundException
|
||||
* @throws \SP\Core\Exceptions\FileNotFoundException
|
||||
*/
|
||||
function recreateDir(string $dir)
|
||||
function recreateDir(string $dir): void
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
logger('Deleting ' . $dir);
|
||||
logger('Deleting '.$dir);
|
||||
|
||||
FileUtil::rmdir_recursive($dir);
|
||||
}
|
||||
|
||||
logger('Creating ' . $dir . PHP_EOL);
|
||||
logger('Creating '.$dir.PHP_EOL);
|
||||
|
||||
if (!mkdir($dir) && !is_dir($dir)) {
|
||||
throw new RuntimeException(sprintf('Directory "%s" was not created', $dir));
|
||||
|
||||
Reference in New Issue
Block a user