mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-28 22:08:17 +02:00
Fixed PHPunit tests
Some checks are pending
Build assets artifact / Build assets artifact (push) Waiting to run
Docker Image Build / docker (push) Waiting to run
Docker Image Build (FrankenPHP) / docker (push) Waiting to run
Static analysis / Static analysis (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.1, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.1, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.1, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, sqlite) (push) Waiting to run
Some checks are pending
Build assets artifact / Build assets artifact (push) Waiting to run
Docker Image Build / docker (push) Waiting to run
Docker Image Build (FrankenPHP) / docker (push) Waiting to run
Static analysis / Static analysis (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.1, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.1, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.1, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, sqlite) (push) Waiting to run
This commit is contained in:
parent
db810445fb
commit
dc25397469
5 changed files with 26 additions and 9 deletions
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||
namespace App\Serializer;
|
||||
|
||||
use App\Entity\Base\AbstractStructuralDBElement;
|
||||
use App\Serializer\APIPlatform\SkippableItemNormalizer;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
|
@ -36,6 +37,8 @@ class StructuralElementNormalizer implements NormalizerInterface, NormalizerAwar
|
|||
{
|
||||
use NormalizerAwareTrait;
|
||||
|
||||
public const ALREADY_CALLED = 'STRUCTURAL_ELEMENT_NORMALIZER_ALREADY_CALLED';
|
||||
|
||||
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
|
||||
{
|
||||
//Only normalize if we are doing a file export operation
|
||||
|
@ -43,15 +46,25 @@ class StructuralElementNormalizer implements NormalizerInterface, NormalizerAwar
|
|||
return false;
|
||||
}
|
||||
|
||||
if (isset($context[self::ALREADY_CALLED]) && in_array($data, $context[self::ALREADY_CALLED], true)) {
|
||||
//If we already handled this object, skip it
|
||||
return false;
|
||||
}
|
||||
|
||||
return $data instanceof AbstractStructuralDBElement;
|
||||
}
|
||||
|
||||
public function normalize($object, ?string $format = null, array $context = []): \ArrayObject|bool|float|int|string
|
||||
public function normalize($object, ?string $format = null, array $context = []): \ArrayObject|bool|float|int|string|array
|
||||
{
|
||||
if (!$object instanceof AbstractStructuralDBElement) {
|
||||
throw new \InvalidArgumentException('This normalizer only supports AbstractStructural objects!');
|
||||
}
|
||||
|
||||
//Avoid infinite recursion by checking if we already handled this object
|
||||
$context[self::ALREADY_CALLED] = $context[self::ALREADY_CALLED] ?? [];
|
||||
$context[SkippableItemNormalizer::DISABLE_ITEM_NORMALIZER] = true;
|
||||
$context[self::ALREADY_CALLED][] = $object;
|
||||
|
||||
$data = $this->normalizer->normalize($object, $format, $context);
|
||||
|
||||
//If the data is not an array, we can't do anything with it
|
||||
|
@ -75,7 +88,8 @@ class StructuralElementNormalizer implements NormalizerInterface, NormalizerAwar
|
|||
public function getSupportedTypes(?string $format): array
|
||||
{
|
||||
return [
|
||||
AbstractStructuralDBElement::class => true,
|
||||
//We cannot cache the result, as it depends on the context
|
||||
AbstractStructuralDBElement::class => false,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class Element14Provider implements InfoProviderInterface
|
|||
'rohsPhthalatesCompliant', 'SVHC', 'tariffCode', 'usEccn', 'hazardCode'];
|
||||
|
||||
private readonly HttpClientInterface $element14Client;
|
||||
|
||||
|
||||
public function __construct(HttpClientInterface $element14Client, private readonly Element14Settings $settings)
|
||||
{
|
||||
/* We use the mozilla CA from the composer ca bundle directly, as some debian systems seems to have problems
|
||||
|
@ -77,7 +77,7 @@ class Element14Provider implements InfoProviderInterface
|
|||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return trim($this->settings->apiKey) !== '';
|
||||
return $this->settings->apiKey !== null && trim($this->settings->apiKey) !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -308,4 +308,4 @@ class Element14Provider implements InfoProviderInterface
|
|||
ProviderCapabilities::DATASHEET,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class TMEClient
|
|||
|
||||
public function isUsable(): bool
|
||||
{
|
||||
return !($this->settings->apiToken === '' || $this->settings->apiSecret === '');
|
||||
return !($this->settings->apiToken === null || $this->settings->apiSecret === null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +59,7 @@ class TMEClient
|
|||
public function isUsingPrivateToken(): bool
|
||||
{
|
||||
//Private tokens are longer than anonymous ones (50 instead of 45 characters)
|
||||
return strlen($this->settings->apiToken) > 45;
|
||||
return strlen($this->settings->apiToken ?? '') > 45;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,4 +94,4 @@ class TMEClient
|
|||
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,9 @@ class StructuralElementNormalizerTest extends WebTestCase
|
|||
//Get an service instance.
|
||||
self::bootKernel();
|
||||
$this->service = self::getContainer()->get(StructuralElementNormalizer::class);
|
||||
//Inject the serializer, as the normalizer as this is not handled by the DI container
|
||||
$this->service->setNormalizer(self::getContainer()->get('serializer'));
|
||||
|
||||
}
|
||||
|
||||
public function testNormalize(): void
|
||||
|
|
|
@ -87,7 +87,7 @@ class ValidGoogleAuthCodeValidatorTest extends ConstraintValidatorTestCase
|
|||
return [];
|
||||
}
|
||||
|
||||
public function eraseCredentials()
|
||||
public function eraseCredentials(): void
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue