-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\TestKernel; | ||
use Doctrine\Common\Cache\Psr6\DoctrineProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; | ||
use Symfony\Component\Cache\Adapter\ArrayAdapter; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
class CacheCompatibilityPassTest extends TestCase | ||
{ | ||
use ExpectDeprecationTrait; | ||
|
||
/** | ||
* @group legacy | ||
* @doesNotPerformAssertions | ||
*/ | ||
public function testMetadataCacheConfigUsingPsr6ServiceDefinedByApplication(): void | ||
{ | ||
(new class (false) extends TestKernel { | ||
public function registerContainerConfiguration(LoaderInterface $loader): void | ||
{ | ||
parent::registerContainerConfiguration($loader); | ||
$loader->load(static function (ContainerBuilder $containerBuilder): void { | ||
$containerBuilder->loadFromExtension( | ||
'doctrine_mongodb', | ||
['document_managers' => ['default' => ['metadata_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]]] | ||
); | ||
$containerBuilder->setDefinition( | ||
'custom_cache_service', | ||
new Definition(ArrayAdapter::class) | ||
); | ||
}); | ||
} | ||
})->boot(); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
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.'); | ||
(new class (false) extends TestKernel { | ||
public function registerContainerConfiguration(LoaderInterface $loader): void | ||
{ | ||
parent::registerContainerConfiguration($loader); | ||
$loader->load(static function (ContainerBuilder $containerBuilder): void { | ||
$containerBuilder->loadFromExtension( | ||
'doctrine_mongodb', | ||
['document_managers' => ['default' => ['metadata_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]]] | ||
); | ||
$containerBuilder->setDefinition( | ||
'custom_cache_service', | ||
(new Definition(DoctrineProvider::class)) | ||
->setArguments([new Definition(ArrayAdapter::class)]) | ||
->setFactory([DoctrineProvider::class, 'wrap']) | ||
); | ||
}); | ||
} | ||
})->boot(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures; | ||
|
||
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle; | ||
use Psr\Log\NullLogger; | ||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
use function md5; | ||
use function mt_rand; | ||
use function sys_get_temp_dir; | ||
|
||
class TestKernel extends Kernel | ||
{ | ||
/** @var string|null */ | ||
private $projectDir; | ||
|
||
public function __construct(bool $debug = true) | ||
{ | ||
parent::__construct('test', $debug); | ||
} | ||
|
||
/** @return iterable<Bundle> */ | ||
public function registerBundles(): iterable | ||
{ | ||
return [ | ||
new FrameworkBundle(), | ||
new DoctrineMongoDBBundle(), | ||
]; | ||
} | ||
|
||
public function registerContainerConfiguration(LoaderInterface $loader): void | ||
{ | ||
$loader->load(static function (ContainerBuilder $container): void { | ||
$container->loadFromExtension('framework', ['secret' => 'F00']); | ||
|
||
$container->loadFromExtension('doctrine_mongodb', [ | ||
'connections' => ['default' => []], | ||
'document_managers' => [ | ||
'default' => [ | ||
'mappings' => [ | ||
'RepositoryServiceBundle' => [ | ||
'type' => 'annotation', | ||
'dir' => __DIR__ . '/Bundles/RepositoryServiceBundle/Document', | ||
'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Document', | ||
], | ||
], | ||
], | ||
], | ||
]); | ||
|
||
// Register a NullLogger to avoid getting the stderr default logger of FrameworkBundle | ||
$container->register('logger', NullLogger::class); | ||
}); | ||
} | ||
|
||
public function getProjectDir(): string | ||
{ | ||
if ($this->projectDir === null) { | ||
$this->projectDir = sys_get_temp_dir() . '/sf_kernel_' . md5((string) mt_rand()); | ||
} | ||
|
||
return $this->projectDir; | ||
} | ||
|
||
public function getRootDir(): string | ||
{ | ||
return $this->getProjectDir(); | ||
} | ||
} |