Skip to content

Commit

Permalink
Add UniqueTest
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Jul 29, 2023
1 parent 4a8f1a4 commit bee93a3
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Tests/Validator/Constraints/UniqueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Doctrine\Bundle\MongoDBBundle\Tests\Validator\Constraints;

use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique;
use Doctrine\Common\Annotations\AnnotationReader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;

use function assert;

use const PHP_VERSION_ID;

final class UniqueTest extends TestCase
{
public function testWithDefaultProperty(): void
{
$metadata = new ClassMetadata(UniqueDocumentDummyOne::class);

if (PHP_VERSION_ID >= 80000) {
$loader = new AnnotationLoader();
} else {
$loader = new AnnotationLoader(new AnnotationReader());
}

self::assertTrue($loader->loadClassMetadata($metadata));

[$constraint] = $metadata->getConstraints();
assert($constraint instanceof Unique);
self::assertSame(['email'], $constraint->fields);
self::assertSame('doctrine_odm.mongodb.unique', $constraint->validatedBy());
}
}

/** @Unique(fields={"email"}) */
#[Unique(['email'])]
class UniqueDocumentDummyOne
{
private string $email;
}

0 comments on commit bee93a3

Please sign in to comment.