fix tests (wip)

This commit is contained in:
2021-12-08 10:51:30 +01:00
parent 60a8c20896
commit 32178e22fe
8 changed files with 15 additions and 11 deletions

View File

@@ -13,6 +13,7 @@ namespace Chill\DocGeneratorBundle\Serializer\Normalizer;
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
use ReflectionClass;
use RuntimeException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
@@ -49,7 +50,11 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
public function normalize($object, ?string $format = null, array $context = [])
{
$classMetadataKey = $object ?? $context['docgen:expects'];
$classMetadataKey = $object ?? $context['docgen:expects'] ?? null;
if (null === $classMetadataKey) {
throw new RuntimeException('Could not determine the metadata for this object. Either provide a non-null object, or a "docgen:expects" key in the context');
}
if (!$this->classMetadataFactory->hasMetadataFor($classMetadataKey)) {
throw new LogicException(sprintf('This object does not have metadata: %s. Add groups on this entity to allow to serialize with the format %s and groups %s', is_object($object) ? get_class($object) : $context['docgen:expects'], $format, implode(', ', $context['groups'])));

View File

@@ -40,7 +40,7 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
$user->setMainCenter($center = new Center());
$center->setName('test');
$normalized = $this->normalizer->normalize($user, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read']]);
$normalized = $this->normalizer->normalize($user, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => User::class]);
$expected = [
'label' => 'User Test',
'email' => '',