|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Webauthn\Tests\Bundle\Functional\Entity; |
| 6 | + |
| 7 | +use Doctrine\ORM\EntityManagerInterface; |
| 8 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 9 | +use PHPUnit\Framework\Attributes\Test; |
| 10 | +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
| 11 | + |
| 12 | +/** |
| 13 | + * @internal |
| 14 | + */ |
| 15 | +final class EntityTest extends KernelTestCase |
| 16 | +{ |
| 17 | + #[Test] |
| 18 | + #[DataProvider('expectedFields')] |
| 19 | + public function theSchemaIsValid(string $name, string $type, null|bool $nullable): void |
| 20 | + { |
| 21 | + //Given |
| 22 | + /** @var EntityManagerInterface $entityManager */ |
| 23 | + $entityManager = self::getContainer()->get(EntityManagerInterface::class); |
| 24 | + |
| 25 | + //When |
| 26 | + $classMetadata = $entityManager->getClassMetadata(Credential::class); |
| 27 | + $fields = $classMetadata->fieldMappings; |
| 28 | + |
| 29 | + //Then |
| 30 | + static::assertArrayHasKey($name, $fields); |
| 31 | + $field = $fields[$name]; |
| 32 | + static::assertSame($type, $field['type']); |
| 33 | + static::assertSame($nullable, $field['nullable']); |
| 34 | + |
| 35 | + } |
| 36 | + |
| 37 | + public static function expectedFields(): iterable |
| 38 | + { |
| 39 | + yield [ |
| 40 | + 'name' => 'publicKeyCredentialId', |
| 41 | + 'type' => 'base64', |
| 42 | + 'nullable' => null, |
| 43 | + ]; |
| 44 | + yield [ |
| 45 | + 'name' => 'type', |
| 46 | + 'type' => 'string', |
| 47 | + 'nullable' => null, |
| 48 | + ]; |
| 49 | + yield [ |
| 50 | + 'name' => 'transports', |
| 51 | + 'type' => 'array', |
| 52 | + 'nullable' => null, |
| 53 | + ]; |
| 54 | + yield [ |
| 55 | + 'name' => 'attestationType', |
| 56 | + 'type' => 'string', |
| 57 | + 'nullable' => null, |
| 58 | + ]; |
| 59 | + yield [ |
| 60 | + 'name' => 'trustPath', |
| 61 | + 'type' => 'trust_path', |
| 62 | + 'nullable' => null, |
| 63 | + ]; |
| 64 | + yield [ |
| 65 | + 'name' => 'aaguid', |
| 66 | + 'type' => 'aaguid', |
| 67 | + 'nullable' => null, |
| 68 | + ]; |
| 69 | + yield [ |
| 70 | + 'name' => 'credentialPublicKey', |
| 71 | + 'type' => 'base64', |
| 72 | + 'nullable' => null, |
| 73 | + ]; |
| 74 | + yield [ |
| 75 | + 'name' => 'userHandle', |
| 76 | + 'type' => 'string', |
| 77 | + 'nullable' => null, |
| 78 | + ]; |
| 79 | + yield [ |
| 80 | + 'name' => 'counter', |
| 81 | + 'type' => 'integer', |
| 82 | + 'nullable' => null, |
| 83 | + ]; |
| 84 | + yield [ |
| 85 | + 'name' => 'otherUI', |
| 86 | + 'type' => 'array', |
| 87 | + 'nullable' => true, |
| 88 | + ]; |
| 89 | + yield [ |
| 90 | + 'name' => 'backupEligible', |
| 91 | + 'type' => 'boolean', |
| 92 | + 'nullable' => true, |
| 93 | + ]; |
| 94 | + yield [ |
| 95 | + 'name' => 'backupStatus', |
| 96 | + 'type' => 'boolean', |
| 97 | + 'nullable' => true, |
| 98 | + ]; |
| 99 | + yield [ |
| 100 | + 'name' => 'uvInitialized', |
| 101 | + 'type' => 'boolean', |
| 102 | + 'nullable' => true, |
| 103 | + ]; |
| 104 | + } |
| 105 | +} |
0 commit comments