Skip to content

Commit

Permalink
Merge pull request #780 from doctrine/4.6.x-merge-up-into-4.7.x_2hQv2b1z
Browse files Browse the repository at this point in the history
Merge release 4.6.1 into 4.7.x
  • Loading branch information
malarzm authored Oct 24, 2023
2 parents 294b0fb + 0135a16 commit cf1a23d
Show file tree
Hide file tree
Showing 21 changed files with 110 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Command/TailCursorDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 0;
}

/** @return ContainerInterface */
/** @return ContainerInterface|null */
protected function getContainer()
{
return $this->container;
Expand Down
2 changes: 1 addition & 1 deletion Tests/CacheWarmer/HydratorCacheWarmerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function testWarmerNotExecuted(int $autoGenerate): void
}

/** @return array<array{int}> */
public function provideWarmerNotExecuted(): array
public static function provideWarmerNotExecuted(): array
{
return [
[ Configuration::AUTOGENERATE_ALWAYS ],
Expand Down
2 changes: 1 addition & 1 deletion Tests/CacheWarmer/PersistentCollectionCacheWarmerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testWarmerNotExecuted(int $autoGenerate): void
$this->warmer->warmUp('meh');
}

public function provideWarmerNotExecuted(): array
public static function provideWarmerNotExecuted(): array
{
return [
[ Configuration::AUTOGENERATE_ALWAYS ],
Expand Down
4 changes: 2 additions & 2 deletions Tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testLoggerConfig(bool $expected, array $config, bool $debug): vo
}

/** @return array<string, array{expected: bool, config: array, debug: bool}> */
public function provideLoggerConfigs(): array
public static function provideLoggerConfigs(): array
{
$config = ['connections' => ['default' => []]];

Expand Down Expand Up @@ -109,7 +109,7 @@ public function testDataCollectorConfig(bool $expected, array $config, bool $deb
}

/** @return array<string, array{expected: bool, config: array, debug: bool}> */
public function provideDataCollectorConfigs(): array
public static function provideDataCollectorConfigs(): array
{
$config = ['connections' => ['default' => []]];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
use function is_dir;
use function reset;

abstract class AbstractMongoDBExtensionTest extends TestCase
abstract class AbstractMongoDBExtensionTestCase extends TestCase
{
abstract protected function loadFromFile(ContainerBuilder $container, string $file): void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
self::assertTrue($kernel->isBooted());
}

/** @group legacy */
/**
* @group legacy
* @doesNotPerformAssertions
*/
public function testMetadataCacheConfigUsingNonPsr6ServiceDefinedByApplication(): void
{
$this->expectDeprecation('Since doctrine/mongodb-odm-bundle 4.4: Configuring doctrine/cache is deprecated. Please update the cache service "custom_cache_service" to use a PSR-6 cache.');
Expand Down
8 changes: 4 additions & 4 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function testFullConfiguration(array $config): void
}

/** @return array<mixed[]> */
public function provideFullConfiguration(): array
public static function provideFullConfiguration(): array
{
$yaml = Yaml::parse(file_get_contents(__DIR__ . '/Fixtures/config/yml/full.yml'));
$yaml = $yaml['doctrine_mongodb'];
Expand Down Expand Up @@ -249,7 +249,7 @@ public function testMergeOptions(array $configs, array $expected): void
}

/** @return array<mixed[]> */
public function provideMergeOptions(): array
public static function provideMergeOptions(): array
{
$cases = [];

Expand Down Expand Up @@ -371,7 +371,7 @@ public function testNormalizeOptions(array $config, array $expected): void
}

/** @return array<mixed[]> */
public function provideNormalizeOptions(): array
public static function provideNormalizeOptions(): array
{
$cases = [];

Expand Down Expand Up @@ -527,7 +527,7 @@ public function testFixtureLoaderValidation(array $config): void
}

/** @return array<mixed[]> */
public function provideExceptionConfiguration(): array
public static function provideExceptionConfiguration(): array
{
$yaml = Yaml::parse(file_get_contents(__DIR__ . '/Fixtures/config/yml/exception.yml'));
$yaml = $yaml['doctrine_mongodb'];
Expand Down
4 changes: 2 additions & 2 deletions Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ private function getContainer($bundles = 'OtherXmlBundle'): ContainerBuilder
]));
}

public function parameterProvider(): array
public static function parameterProvider(): array
{
return [
['proxy_namespace', 'proxy_namespace', 'foo'],
['proxy-namespace', 'proxy_namespace', 'bar'],
];
}

public function getAutomappingConfigurations(): array
public static function getAutomappingConfigurations(): array
{
return [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/** @MongoDB\Document */
class Test
class TestDocument
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

#[MongoDB\Document]
class Test
class TestDocument
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

#[MongoDB\Document]
class Test
class TestDocument
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

namespace Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\NewXmlBundle\Document;

class Test
class TestDocument
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

namespace Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\OtherXmlBundle\Document;

class Test
class TestDocument
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

namespace Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\XmlBundle\Document;

class Test
class TestDocument
{
}
2 changes: 1 addition & 1 deletion Tests/DependencyInjection/XmlMongoDBExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

class XmlMongoDBExtensionTest extends AbstractMongoDBExtensionTest
class XmlMongoDBExtensionTest extends AbstractMongoDBExtensionTestCase
{
protected function loadFromFile(ContainerBuilder $container, string $file): void
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/DependencyInjection/YamlMongoDBExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class YamlMongoDBExtensionTest extends AbstractMongoDBExtensionTest
class YamlMongoDBExtensionTest extends AbstractMongoDBExtensionTestCase
{
protected function loadFromFile(ContainerBuilder $container, string $file): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use PHPUnit\Framework\TestCase;
use ReflectionProperty;

abstract class AbstractDriverTest extends TestCase
abstract class AbstractDriverTestCase extends TestCase
{
public function testFindMappingFile(): void
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/Mapping/Driver/XmlDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver;

class XmlDriverTest extends AbstractDriverTest
class XmlDriverTest extends AbstractDriverTestCase
{
protected function getFileExtension(): string
{
Expand Down
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;
}
34 changes: 32 additions & 2 deletions Validator/Constraints/Unique.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,36 @@
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
class Unique extends UniqueEntity
{
/** @var string */
public $service = 'doctrine_odm.mongodb.unique';
/**
* @param string[]|string $fields The combination of fields that must contain unique values or a set of options
* @param bool|string[]|string $ignoreNull The combination of fields that ignore null values
* @param mixed $payload
*/
public function __construct(
$fields,
?string $message = null,
string $service = 'doctrine_odm.mongodb.unique',
?string $em = null,
?string $entityClass = null,
?string $repositoryMethod = null,
?string $errorPath = null,
$ignoreNull = null,
?array $groups = null,
$payload = null,
array $options = []
) {
parent::__construct(
$fields,
$message,
$service,
$em,
$entityClass,
$repositoryMethod,
$errorPath,
$ignoreNull,
$groups,
$payload,
$options,
);
}
}
18 changes: 9 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=1"/>
</php>

<filter>
<whitelist>
<coverage>
<include>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</include>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
Expand Down

0 comments on commit cf1a23d

Please sign in to comment.