Skip to content

Commit

Permalink
Merge pull request #624 from web-auth/test/entity-test
Browse files Browse the repository at this point in the history
Add Credential entity and related tests
  • Loading branch information
Spomky authored Jul 10, 2024
2 parents 4e1ac62 + f546ffa commit 4f0ec0a
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 10 deletions.
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<server name="SYMFONY_PHPUNIT_VERSION" value="10.1"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
<env name="APP_DEBUG" value="true"/>
<env name="DATABASE_URL" value="sqlite:///%kernel.project_dir%/var/data.db"/>
<server name="KERNEL_CLASS" value="Webauthn\Tests\Bundle\Functional\AppKernel"/>
<ini name="memory_limit" value="-1"/>
</php>
Expand Down
10 changes: 0 additions & 10 deletions tests/symfony/config/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
parameters:
env(DATABASE_URL): ''

framework:
test: true
secret: 'test'
Expand Down Expand Up @@ -98,13 +95,6 @@ services:

doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci

url: '%env(resolve:DATABASE_URL)%'
orm:
enable_lazy_ghost_objects: true
Expand Down
19 changes: 19 additions & 0 deletions tests/symfony/functional/Entity/Credential.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Webauthn\Tests\Bundle\Functional\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Webauthn\PublicKeyCredentialSource;

#[ORM\Entity]
#[Orm\Table(name: 'credentials')]
class Credential extends PublicKeyCredentialSource
{
#[ORM\Id]
#[ORM\Column(type: Types::STRING, length: 10)]
#[ORM\GeneratedValue(strategy: 'NONE')]
public string $id;
}
105 changes: 105 additions & 0 deletions tests/symfony/functional/Entity/EntityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

declare(strict_types=1);

namespace Webauthn\Tests\Bundle\Functional\Entity;

use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
* @internal
*/
final class EntityTest extends KernelTestCase
{
#[Test]
#[DataProvider('expectedFields')]
public function theSchemaIsValid(string $name, string $type, null|bool $nullable): void
{
//Given
/** @var EntityManagerInterface $entityManager */
$entityManager = self::getContainer()->get(EntityManagerInterface::class);

//When
$classMetadata = $entityManager->getClassMetadata(Credential::class);
$fields = $classMetadata->fieldMappings;

//Then
static::assertArrayHasKey($name, $fields);
$field = $fields[$name];
static::assertSame($type, $field['type']);
static::assertSame($nullable, $field['nullable']);

}

public static function expectedFields(): iterable
{
yield [
'name' => 'publicKeyCredentialId',
'type' => 'base64',
'nullable' => null,
];
yield [
'name' => 'type',
'type' => 'string',
'nullable' => null,
];
yield [
'name' => 'transports',
'type' => 'array',
'nullable' => null,
];
yield [
'name' => 'attestationType',
'type' => 'string',
'nullable' => null,
];
yield [
'name' => 'trustPath',
'type' => 'trust_path',
'nullable' => null,
];
yield [
'name' => 'aaguid',
'type' => 'aaguid',
'nullable' => null,
];
yield [
'name' => 'credentialPublicKey',
'type' => 'base64',
'nullable' => null,
];
yield [
'name' => 'userHandle',
'type' => 'string',
'nullable' => null,
];
yield [
'name' => 'counter',
'type' => 'integer',
'nullable' => null,
];
yield [
'name' => 'otherUI',
'type' => 'array',
'nullable' => true,
];
yield [
'name' => 'backupEligible',
'type' => 'boolean',
'nullable' => true,
];
yield [
'name' => 'backupStatus',
'type' => 'boolean',
'nullable' => true,
];
yield [
'name' => 'uvInitialized',
'type' => 'boolean',
'nullable' => true,
];
}
}

0 comments on commit 4f0ec0a

Please sign in to comment.