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

This commit is contained in:
Jan Böhmer 2025-07-13 20:06:38 +02:00
parent db810445fb
commit dc25397469
5 changed files with 26 additions and 9 deletions

View file

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace App\Serializer; namespace App\Serializer;
use App\Entity\Base\AbstractStructuralDBElement; use App\Entity\Base\AbstractStructuralDBElement;
use App\Serializer\APIPlatform\SkippableItemNormalizer;
use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
@ -36,6 +37,8 @@ class StructuralElementNormalizer implements NormalizerInterface, NormalizerAwar
{ {
use NormalizerAwareTrait; use NormalizerAwareTrait;
public const ALREADY_CALLED = 'STRUCTURAL_ELEMENT_NORMALIZER_ALREADY_CALLED';
public function supportsNormalization($data, ?string $format = null, array $context = []): bool public function supportsNormalization($data, ?string $format = null, array $context = []): bool
{ {
//Only normalize if we are doing a file export operation //Only normalize if we are doing a file export operation
@ -43,15 +46,25 @@ class StructuralElementNormalizer implements NormalizerInterface, NormalizerAwar
return false; 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; 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) { if (!$object instanceof AbstractStructuralDBElement) {
throw new \InvalidArgumentException('This normalizer only supports AbstractStructural objects!'); 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); $data = $this->normalizer->normalize($object, $format, $context);
//If the data is not an array, we can't do anything with it //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 public function getSupportedTypes(?string $format): array
{ {
return [ return [
AbstractStructuralDBElement::class => true, //We cannot cache the result, as it depends on the context
AbstractStructuralDBElement::class => false,
]; ];
} }
} }

View file

@ -77,7 +77,7 @@ class Element14Provider implements InfoProviderInterface
public function isActive(): bool public function isActive(): bool
{ {
return trim($this->settings->apiKey) !== ''; return $this->settings->apiKey !== null && trim($this->settings->apiKey) !== '';
} }
/** /**

View file

@ -48,7 +48,7 @@ class TMEClient
public function isUsable(): bool 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 public function isUsingPrivateToken(): bool
{ {
//Private tokens are longer than anonymous ones (50 instead of 45 characters) //Private tokens are longer than anonymous ones (50 instead of 45 characters)
return strlen($this->settings->apiToken) > 45; return strlen($this->settings->apiToken ?? '') > 45;
} }
/** /**

View file

@ -41,6 +41,9 @@ class StructuralElementNormalizerTest extends WebTestCase
//Get an service instance. //Get an service instance.
self::bootKernel(); self::bootKernel();
$this->service = self::getContainer()->get(StructuralElementNormalizer::class); $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 public function testNormalize(): void

View file

@ -87,7 +87,7 @@ class ValidGoogleAuthCodeValidatorTest extends ConstraintValidatorTestCase
return []; return [];
} }
public function eraseCredentials() public function eraseCredentials(): void
{ {
} }