Skip to content

Commit 4f0ec0a

Browse files
authored
Merge pull request #624 from web-auth/test/entity-test
Add Credential entity and related tests
2 parents 4e1ac62 + f546ffa commit 4f0ec0a

File tree

4 files changed

+125
-10
lines changed

4 files changed

+125
-10
lines changed

phpunit.xml.dist

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<server name="SYMFONY_PHPUNIT_VERSION" value="10.1"/>
2323
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
2424
<env name="APP_DEBUG" value="true"/>
25+
<env name="DATABASE_URL" value="sqlite:///%kernel.project_dir%/var/data.db"/>
2526
<server name="KERNEL_CLASS" value="Webauthn\Tests\Bundle\Functional\AppKernel"/>
2627
<ini name="memory_limit" value="-1"/>
2728
</php>

tests/symfony/config/config.yml

-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
parameters:
2-
env(DATABASE_URL): ''
3-
41
framework:
52
test: true
63
secret: 'test'
@@ -98,13 +95,6 @@ services:
9895

9996
doctrine:
10097
dbal:
101-
driver: 'pdo_mysql'
102-
server_version: '5.7'
103-
charset: utf8mb4
104-
default_table_options:
105-
charset: utf8mb4
106-
collate: utf8mb4_unicode_ci
107-
10898
url: '%env(resolve:DATABASE_URL)%'
10999
orm:
110100
enable_lazy_ghost_objects: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Webauthn\Tests\Bundle\Functional\Entity;
6+
7+
use Doctrine\DBAL\Types\Types;
8+
use Doctrine\ORM\Mapping as ORM;
9+
use Webauthn\PublicKeyCredentialSource;
10+
11+
#[ORM\Entity]
12+
#[Orm\Table(name: 'credentials')]
13+
class Credential extends PublicKeyCredentialSource
14+
{
15+
#[ORM\Id]
16+
#[ORM\Column(type: Types::STRING, length: 10)]
17+
#[ORM\GeneratedValue(strategy: 'NONE')]
18+
public string $id;
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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

Comments
 (0)