Skip to content

Commit

Permalink
feat: Symfony 7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond authored and GromNaN committed Dec 11, 2023
1 parent ddf39bb commit a192cc6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
symfony-version:
- "5.4.*"
- "6.4.*"
- "7.0.x"
driver-version:
- "stable"
dependencies:
Expand All @@ -41,6 +42,9 @@ jobs:
driver-version: "1.5.0"
stability: "stable"
symfony-version: "5.4.*"
exclude:
- php-version: "8.1"
symfony-version: "7.0.x"

services:
mongodb:
Expand Down
5 changes: 2 additions & 3 deletions Form/DoctrineMongoDBExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ public function __construct(ManagerRegistry $registry)
}

/** @return FormTypeInterface[] */
protected function loadTypes()
protected function loadTypes(): array
{
return [
new Type\DocumentType($this->registry),
];
}

/** @return FormTypeGuesserInterface|null */
protected function loadTypeGuesser()
protected function loadTypeGuesser(): ?FormTypeGuesserInterface
{
return new DoctrineMongoDBTypeGuesser($this->registry);
}
Expand Down
14 changes: 6 additions & 8 deletions Form/DoctrineMongoDBTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public function __construct(ManagerRegistry $registry)
$this->registry = $registry;
}

/** @return TypeGuess|null */
public function guessType(string $class, string $property)
public function guessType(string $class, string $property): ?TypeGuess
{
$ret = $this->getMetadata($class);
if (! $ret) {
Expand Down Expand Up @@ -114,10 +113,11 @@ public function guessType(string $class, string $property)
Guess::MEDIUM_CONFIDENCE,
);
}

return null;
}

/** @return ValueGuess|null */
public function guessRequired(string $class, string $property)
public function guessRequired(string $class, string $property): ?ValueGuess
{
$ret = $this->getMetadata($class);
if ($ret && $ret[0]->hasField($property)) {
Expand All @@ -137,8 +137,7 @@ public function guessRequired(string $class, string $property)
return null;
}

/** @return ValueGuess|null */
public function guessMaxLength(string $class, string $property)
public function guessMaxLength(string $class, string $property): ?ValueGuess
{
return null;
}
Expand All @@ -150,8 +149,7 @@ public function guessMinLength($class, $property): void
{
}

/** @return ValueGuess|null */
public function guessPattern(string $class, string $property)
public function guessPattern(string $class, string $property): ?ValueGuess
{
$ret = $this->getMetadata($class);
if (! $ret || ! $ret[0]->hasField($property) || $ret[0]->hasAssociation($property)) {
Expand Down
9 changes: 3 additions & 6 deletions Tests/Validator/Constraints/UniqueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@
use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;

use function assert;
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;

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

$loader = new AnnotationLoader();
$loader = new AttributeLoader();

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

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

/** @Unique(fields={"email"}) */
#[Unique(['email'])]
class UniqueDocumentDummyOne
{
Expand Down
31 changes: 16 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@
"doctrine/persistence": "^2.2 || ^3.0",
"jean85/pretty-package-versions": "^1.3.0 || ^2.0.1",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"symfony/config": "^5.4 || ^6.2",
"symfony/console": "^5.4 || ^6.2",
"symfony/dependency-injection": "^5.4 || ^6.2",
"symfony/config": "^5.4 || ^6.2 || ^7.0",
"symfony/console": "^5.4 || ^6.2 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.2 || ^7.0",
"symfony/deprecation-contracts": "^2.1 || ^3.0",
"symfony/doctrine-bridge": "^5.4.19 || ^6.2",
"symfony/framework-bundle": "^5.4 || ^6.2",
"symfony/http-kernel": "^5.4 || ^6.2",
"symfony/options-resolver": "^5.4 || ^6.2"
"symfony/doctrine-bridge": "^5.4.19 || ^6.2 || ^7.0",
"symfony/framework-bundle": "^5.4 || ^6.2 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.2 || ^7.0",
"symfony/options-resolver": "^5.4 || ^6.2 || ^7.0"
},
"require-dev": {
"doctrine/coding-standard": "^11.0",
"doctrine/data-fixtures": "^1.3",
"phpunit/phpunit": "^9.5.5",
"psalm/plugin-symfony": "^5.0",
"symfony/browser-kit": "^5.4 || ^6.2",
"symfony/form": "^5.4 || ^6.2",
"symfony/phpunit-bridge": "^6.2",
"symfony/security-bundle": "^5.4 || ^6.2",
"symfony/stopwatch": "^5.4 || ^6.2",
"symfony/validator": "^5.4 || ^6.2",
"symfony/yaml": "^5.4 || ^6.2",
"symfony/browser-kit": "^5.4 || ^6.2 || ^7.0",
"symfony/form": "^5.4 || ^6.2 || ^7.0",
"symfony/phpunit-bridge": "^6.2 || ^7.0",
"symfony/security-bundle": "^5.4 || ^6.2 || ^7.0",
"symfony/stopwatch": "^5.4 || ^6.2 || ^7.0",
"symfony/validator": "^5.4 || ^6.2 || ^7.0",
"symfony/yaml": "^5.4 || ^6.2 || ^7.0",
"vimeo/psalm": "^5.12"
},
"conflict": {
Expand All @@ -59,7 +59,8 @@
"suggest": {
"doctrine/data-fixtures": "Load data fixtures"
},
"minimum-stability": "stable",
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"Doctrine\\Bundle\\MongoDBBundle\\": ""
Expand Down

0 comments on commit a192cc6

Please sign in to comment.