mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-10 10:24:31 +02:00
Improved code style of tests
This commit is contained in:
parent
5629215ce4
commit
684334ba22
73 changed files with 196 additions and 38 deletions
|
@ -29,6 +29,7 @@ use Symfony\Component\Filesystem\Filesystem;
|
|||
/**
|
||||
* This service converts the relative pathes for attachments saved in database (like %MEDIA%/img.jpg) to real pathes
|
||||
* an vice versa.
|
||||
* @see \App\Tests\Services\Attachments\AttachmentPathResolverTest
|
||||
*/
|
||||
class AttachmentPathResolver
|
||||
{
|
||||
|
|
|
@ -31,6 +31,9 @@ use function strlen;
|
|||
use Symfony\Component\Asset\Packages;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\Attachments\AttachmentURLGeneratorTest
|
||||
*/
|
||||
class AttachmentURLGenerator
|
||||
{
|
||||
protected string $public_path;
|
||||
|
|
|
@ -30,6 +30,7 @@ use Symfony\Contracts\Cache\CacheInterface;
|
|||
|
||||
/**
|
||||
* This service is used to find builtin attachment ressources.
|
||||
* @see \App\Tests\Services\Attachments\BuiltinAttachmentsFinderTest
|
||||
*/
|
||||
class BuiltinAttachmentsFinder
|
||||
{
|
||||
|
@ -57,7 +58,7 @@ class BuiltinAttachmentsFinder
|
|||
foreach($finder as $file) {
|
||||
$folder = $file->getRelativePath();
|
||||
//Normalize path (replace \ with /)
|
||||
$folder = str_replace('\\', '/', $folder);
|
||||
$folder = str_replace('\\', '/', (string) $folder);
|
||||
|
||||
if(!isset($output[$folder])) {
|
||||
$output[$folder] = [];
|
||||
|
|
|
@ -32,6 +32,7 @@ use Symfony\Contracts\Cache\ItemInterface;
|
|||
* A service that helps to work with filetype filters (based on the format <input type=file> accept uses).
|
||||
* See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers for
|
||||
* more details.
|
||||
* @see \App\Tests\Services\Attachments\FileTypeFilterToolsTest
|
||||
*/
|
||||
class FileTypeFilterTools
|
||||
{
|
||||
|
|
|
@ -49,6 +49,9 @@ use Doctrine\ORM\Mapping\Entity;
|
|||
use function get_class;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\ElementTypeNameGeneratorTest
|
||||
*/
|
||||
class ElementTypeNameGenerator
|
||||
{
|
||||
protected array $mapping;
|
||||
|
@ -127,7 +130,7 @@ class ElementTypeNameGenerator
|
|||
{
|
||||
$type = $this->getLocalizedTypeLabel($entity);
|
||||
if ($use_html) {
|
||||
return '<i>'.$type.':</i> '.htmlspecialchars($entity->getName());
|
||||
return '<i>'.$type.':</i> '.htmlspecialchars((string) $entity->getName());
|
||||
}
|
||||
|
||||
return $type.': '.$entity->getName();
|
||||
|
|
|
@ -29,6 +29,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
|
||||
/**
|
||||
* This service formats a part amount using a Measurement Unit.
|
||||
* @see \App\Tests\Services\Formatters\AmountFormatterTest
|
||||
*/
|
||||
class AmountFormatter
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace App\Services\Formatters;
|
|||
|
||||
/**
|
||||
* A service that helps you to format values using the SI prefixes.
|
||||
* @see \App\Tests\Services\Formatters\SIFormatterTest
|
||||
*/
|
||||
class SIFormatter
|
||||
{
|
||||
|
|
|
@ -27,6 +27,9 @@ use League\Csv\Reader;
|
|||
use Symfony\Component\HttpFoundation\File\File;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\ImportExportSystem\BOMImporterTest
|
||||
*/
|
||||
class BOMImporter
|
||||
{
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ use function Symfony\Component\String\u;
|
|||
|
||||
/**
|
||||
* Use this class to export an entity to multiple file formats.
|
||||
* @see \App\Tests\Services\ImportExportSystem\EntityExporterTest
|
||||
*/
|
||||
class EntityExporter
|
||||
{
|
||||
|
|
|
@ -36,6 +36,9 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\ImportExportSystem\EntityImporterTest
|
||||
*/
|
||||
class EntityImporter
|
||||
{
|
||||
public function __construct(protected SerializerInterface $serializer, protected EntityManagerInterface $em, protected ValidatorInterface $validator)
|
||||
|
|
|
@ -48,6 +48,9 @@ use App\Services\LabelSystem\Barcodes\BarcodeContentGenerator;
|
|||
use Com\Tecnick\Barcode\Barcode;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LabelSystem\BarcodeGeneratorTest
|
||||
*/
|
||||
final class BarcodeGenerator
|
||||
{
|
||||
public function __construct(private readonly BarcodeContentGenerator $barcodeContentGenerator)
|
||||
|
|
|
@ -48,6 +48,9 @@ use App\Entity\Parts\Storelocation;
|
|||
use InvalidArgumentException;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LabelSystem\Barcodes\BarcodeContentGeneratorTest
|
||||
*/
|
||||
final class BarcodeContentGenerator
|
||||
{
|
||||
public const PREFIX_MAP = [
|
||||
|
|
|
@ -43,6 +43,9 @@ namespace App\Services\LabelSystem\Barcodes;
|
|||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LabelSystem\Barcodes\BarcodeNormalizerTest
|
||||
*/
|
||||
final class BarcodeNormalizer
|
||||
{
|
||||
private const PREFIX_TYPE_MAP = [
|
||||
|
|
|
@ -47,6 +47,9 @@ use Doctrine\ORM\EntityNotFoundException;
|
|||
use InvalidArgumentException;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LabelSystem\Barcodes\BarcodeRedirectorTest
|
||||
*/
|
||||
final class BarcodeRedirector
|
||||
{
|
||||
public function __construct(private readonly UrlGeneratorInterface $urlGenerator, private readonly EntityManagerInterface $em)
|
||||
|
|
|
@ -48,6 +48,9 @@ use App\Entity\Parts\Storelocation;
|
|||
use Dompdf\Dompdf;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LabelSystem\LabelGeneratorTest
|
||||
*/
|
||||
final class LabelGenerator
|
||||
{
|
||||
public const CLASS_SUPPORT_MAPPING = [
|
||||
|
|
|
@ -46,6 +46,7 @@ use App\Services\LabelSystem\PlaceholderProviders\PlaceholderProviderInterface;
|
|||
/**
|
||||
* This service replaces the Placeholders of the user provided lines with the proper informations.
|
||||
* It uses the PlaceholderProviders provided by PlaceholderProviderInterface classes.
|
||||
* @see \App\Tests\Services\LabelSystem\LabelTextReplacerTest
|
||||
*/
|
||||
final class LabelTextReplacer
|
||||
{
|
||||
|
|
|
@ -50,6 +50,7 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|||
|
||||
/**
|
||||
* Provides Placeholders for infos about global infos like Installation name or datetimes.
|
||||
* @see \App\Tests\Services\LabelSystem\PlaceholderProviders\GlobalProvidersTest
|
||||
*/
|
||||
final class GlobalProviders implements PlaceholderProviderInterface
|
||||
{
|
||||
|
|
|
@ -43,6 +43,9 @@ namespace App\Services\LabelSystem\PlaceholderProviders;
|
|||
|
||||
use App\Entity\Contracts\NamedElementInterface;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LabelSystem\PlaceholderProviders\NamedElementProviderTest
|
||||
*/
|
||||
final class NamedElementProvider implements PlaceholderProviderInterface
|
||||
{
|
||||
public function replace(string $placeholder, object $label_target, array $options = []): ?string
|
||||
|
|
|
@ -49,6 +49,9 @@ use App\Services\LabelSystem\LabelTextReplacer;
|
|||
use IntlDateFormatter;
|
||||
use Locale;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LabelSystem\PlaceholderProviders\PartLotProviderTest
|
||||
*/
|
||||
final class PartLotProvider implements PlaceholderProviderInterface
|
||||
{
|
||||
public function __construct(private readonly LabelTextReplacer $labelTextReplacer, private readonly AmountFormatter $amountFormatter)
|
||||
|
|
|
@ -49,6 +49,9 @@ use App\Services\Formatters\SIFormatter;
|
|||
use Parsedown;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LabelSystem\PlaceholderProviders\PartProviderTest
|
||||
*/
|
||||
final class PartProvider implements PlaceholderProviderInterface
|
||||
{
|
||||
public function __construct(private readonly SIFormatter $siFormatter, private readonly TranslatorInterface $translator)
|
||||
|
|
|
@ -46,6 +46,9 @@ use DateTime;
|
|||
use IntlDateFormatter;
|
||||
use Locale;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LabelSystem\PlaceholderProviders\TimestampableElementProviderTest
|
||||
*/
|
||||
final class TimestampableElementProvider implements PlaceholderProviderInterface
|
||||
{
|
||||
public function replace(string $placeholder, object $label_target, array $options = []): ?string
|
||||
|
|
|
@ -68,6 +68,9 @@ use Twig\Extra\Intl\IntlExtension;
|
|||
use Twig\Loader\ArrayLoader;
|
||||
use Twig\Sandbox\SecurityPolicyInterface;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LabelSystem\SandboxedTwigProviderTest
|
||||
*/
|
||||
final class SandboxedTwigProvider
|
||||
{
|
||||
private const ALLOWED_TAGS = ['apply', 'autoescape', 'do', 'for', 'if', 'set', 'verbatim', 'with'];
|
||||
|
|
|
@ -41,6 +41,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Services\LogSystem;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LogSystem\EventCommentHelperTest
|
||||
*/
|
||||
class EventCommentHelper
|
||||
{
|
||||
protected const MAX_MESSAGE_LENGTH = 255;
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace App\Services\LogSystem;
|
|||
/**
|
||||
* This service is used to check if a log change comment is needed for a given operation type.
|
||||
* It is configured using the "enforce_change_comments_for" config parameter.
|
||||
* @see \App\Tests\Services\LogSystem\EventCommentNeededHelperTest
|
||||
*/
|
||||
class EventCommentNeededHelper
|
||||
{
|
||||
|
|
|
@ -29,6 +29,9 @@ use App\Entity\UserSystem\User;
|
|||
use App\Services\Misc\ConsoleInfoHelper;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LogSystem\EventLoggerTest
|
||||
*/
|
||||
class EventLogger
|
||||
{
|
||||
public function __construct(protected int $minimum_log_level, protected array $blacklist, protected array $whitelist, protected EntityManagerInterface $em, protected Security $security, protected ConsoleInfoHelper $console_info_helper)
|
||||
|
|
|
@ -26,6 +26,9 @@ use App\Entity\Attachments\Attachment;
|
|||
use function in_array;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\Misc\FAIconGeneratorTest
|
||||
*/
|
||||
class FAIconGenerator
|
||||
{
|
||||
protected const EXT_MAPPING = [
|
||||
|
|
|
@ -45,6 +45,7 @@ use InvalidArgumentException;
|
|||
|
||||
/**
|
||||
* This Parser allows to parse number ranges like 1-3, 4, 5.
|
||||
* @see \App\Tests\Services\Misc\RangeParserTest
|
||||
*/
|
||||
class RangeParser
|
||||
{
|
||||
|
|
|
@ -47,6 +47,9 @@ use InvalidArgumentException;
|
|||
|
||||
use function preg_match;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\Parameters\ParameterExtractorTest
|
||||
*/
|
||||
class ParameterExtractor
|
||||
{
|
||||
protected const ALLOWED_PARAM_SEPARATORS = [', ', "\n"];
|
||||
|
|
|
@ -8,6 +8,9 @@ use App\Entity\Parts\PartLot;
|
|||
use App\Services\LogSystem\EventCommentHelper;
|
||||
use App\Services\LogSystem\EventLogger;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\Parts\PartLotWithdrawAddHelperTest
|
||||
*/
|
||||
final class PartLotWithdrawAddHelper
|
||||
{
|
||||
public function __construct(private readonly EventLogger $eventLogger, private readonly EventCommentHelper $eventCommentHelper)
|
||||
|
|
|
@ -32,6 +32,9 @@ use Locale;
|
|||
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\Parts\PricedetailHelperTest
|
||||
*/
|
||||
class PricedetailHelper
|
||||
{
|
||||
protected string $locale;
|
||||
|
@ -54,7 +57,7 @@ class PricedetailHelper
|
|||
foreach ($orderdetails as $orderdetail) {
|
||||
$pricedetails = $orderdetail->getPricedetails();
|
||||
//The orderdetail must have pricedetails, otherwise this will not work!
|
||||
if (0 === count($pricedetails)) {
|
||||
if (0 === (is_countable($pricedetails) ? count($pricedetails) : 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -99,7 +102,7 @@ class PricedetailHelper
|
|||
foreach ($orderdetails as $orderdetail) {
|
||||
$pricedetails = $orderdetail->getPricedetails();
|
||||
//The orderdetail must have pricedetails, otherwise this will not work!
|
||||
if (0 === count($pricedetails)) {
|
||||
if (0 === (is_countable($pricedetails) ? count($pricedetails) : 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,9 @@ use App\Entity\ProjectSystem\ProjectBOMEntry;
|
|||
use App\Helpers\Projects\ProjectBuildRequest;
|
||||
use App\Services\Parts\PartLotWithdrawAddHelper;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\ProjectSystem\ProjectBuildHelperTest
|
||||
*/
|
||||
class ProjectBuildHelper
|
||||
{
|
||||
public function __construct(private readonly PartLotWithdrawAddHelper $withdraw_add_helper)
|
||||
|
|
|
@ -5,6 +5,9 @@ namespace App\Services\ProjectSystem;
|
|||
use App\Entity\Parts\Part;
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\ProjectSystem\ProjectBuildPartHelperTest
|
||||
*/
|
||||
class ProjectBuildPartHelper
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -31,6 +31,7 @@ use Symfony\Contracts\Cache\TagAwareCacheInterface;
|
|||
|
||||
/**
|
||||
* This service gives you a flat list containing all structured entities in the order of the structure.
|
||||
* @see \App\Tests\Services\Trees\NodesListBuilderTest
|
||||
*/
|
||||
class NodesListBuilder
|
||||
{
|
||||
|
|
|
@ -45,6 +45,9 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\Trees\TreeViewGeneratorTest
|
||||
*/
|
||||
class TreeViewGenerator
|
||||
{
|
||||
public function __construct(protected EntityURLGenerator $urlGenerator, protected EntityManagerInterface $em, protected TagAwareCacheInterface $cache, protected UserCacheKeyGenerator $keyGenerator, protected TranslatorInterface $translator, protected bool $rootNodeExpandedByDefault, protected bool $rootNodeEnabled)
|
||||
|
@ -130,43 +133,29 @@ class TreeViewGenerator
|
|||
|
||||
protected function entityClassToRootNodeString(string $class): string
|
||||
{
|
||||
switch ($class) {
|
||||
case Category::class:
|
||||
return $this->translator->trans('category.labelp');
|
||||
case Storelocation::class:
|
||||
return $this->translator->trans('storelocation.labelp');
|
||||
case Footprint::class:
|
||||
return $this->translator->trans('footprint.labelp');
|
||||
case Manufacturer::class:
|
||||
return $this->translator->trans('manufacturer.labelp');
|
||||
case Supplier::class:
|
||||
return $this->translator->trans('supplier.labelp');
|
||||
case Project::class:
|
||||
return $this->translator->trans('project.labelp');
|
||||
default:
|
||||
return $this->translator->trans('tree.root_node.text');
|
||||
}
|
||||
return match ($class) {
|
||||
Category::class => $this->translator->trans('category.labelp'),
|
||||
Storelocation::class => $this->translator->trans('storelocation.labelp'),
|
||||
Footprint::class => $this->translator->trans('footprint.labelp'),
|
||||
Manufacturer::class => $this->translator->trans('manufacturer.labelp'),
|
||||
Supplier::class => $this->translator->trans('supplier.labelp'),
|
||||
Project::class => $this->translator->trans('project.labelp'),
|
||||
default => $this->translator->trans('tree.root_node.text'),
|
||||
};
|
||||
}
|
||||
|
||||
protected function entityClassToRootNodeIcon(string $class): ?string
|
||||
{
|
||||
$icon = "fa-fw fa-treeview fa-solid ";
|
||||
switch ($class) {
|
||||
case Category::class:
|
||||
return $icon . 'fa-tags';
|
||||
case Storelocation::class:
|
||||
return $icon . 'fa-cube';
|
||||
case Footprint::class:
|
||||
return $icon . 'fa-microchip';
|
||||
case Manufacturer::class:
|
||||
return $icon . 'fa-industry';
|
||||
case Supplier::class:
|
||||
return $icon . 'fa-truck';
|
||||
case Project::class:
|
||||
return $icon . 'fa-archive';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return match ($class) {
|
||||
Category::class => $icon . 'fa-tags',
|
||||
Storelocation::class => $icon . 'fa-cube',
|
||||
Footprint::class => $icon . 'fa-microchip',
|
||||
Manufacturer::class => $icon . 'fa-industry',
|
||||
Supplier::class => $icon . 'fa-truck',
|
||||
Project::class => $icon . 'fa-archive',
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,6 +37,7 @@ use Symfony\Component\Yaml\Yaml;
|
|||
* This class manages the permissions of users and groups.
|
||||
* Permissions are defined in the config/permissions.yaml file, and are parsed and resolved by this class using the
|
||||
* user and hierachical group PermissionData information.
|
||||
* @see \App\Tests\Services\UserSystem\PermissionManagerTest
|
||||
*/
|
||||
class PermissionManager
|
||||
{
|
||||
|
|
|
@ -25,6 +25,9 @@ use App\Entity\UserSystem\PermissionData;
|
|||
use App\Entity\UserSystem\User;
|
||||
use App\Security\Interfaces\HasPermissionsInterface;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\UserSystem\PermissionSchemaUpdaterTest
|
||||
*/
|
||||
class PermissionSchemaUpdater
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -27,6 +27,7 @@ use RuntimeException;
|
|||
|
||||
/**
|
||||
* This class generates random backup codes for two-factor authentication.
|
||||
* @see \App\Tests\Services\UserSystem\TFA\BackupCodeGeneratorTest
|
||||
*/
|
||||
class BackupCodeGenerator
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@ use App\Entity\UserSystem\User;
|
|||
|
||||
/**
|
||||
* This services offers methods to manage backup codes for two-factor authentication.
|
||||
* @see \App\Tests\Services\UserSystem\TFA\BackupCodeManagerTest
|
||||
*/
|
||||
class BackupCodeManager
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue