mirror of
https://github.com/doctrine/DoctrineMongoDBBundle.git
synced 2026-03-23 22:32:07 +01:00
35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Doctrine\Bundle\MongoDBBundle\Tests;
|
|
|
|
use Doctrine\ODM\MongoDB\Configuration;
|
|
use Doctrine\ODM\MongoDB\DocumentManager;
|
|
use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver;
|
|
use MongoDB\Client;
|
|
use PHPUnit\Framework\TestCase as BaseTestCase;
|
|
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
|
|
|
use function getenv;
|
|
use function sys_get_temp_dir;
|
|
|
|
class TestCase extends BaseTestCase
|
|
{
|
|
/** @param string[] $paths */
|
|
public static function createTestDocumentManager(array $paths = []): DocumentManager
|
|
{
|
|
$config = new Configuration();
|
|
$config->setAutoGenerateProxyClasses(Configuration::AUTOGENERATE_FILE_NOT_EXISTS);
|
|
$config->setProxyDir(sys_get_temp_dir());
|
|
$config->setHydratorDir(sys_get_temp_dir());
|
|
$config->setProxyNamespace('SymfonyTests\Doctrine');
|
|
$config->setHydratorNamespace('SymfonyTests\Doctrine');
|
|
$config->setMetadataDriverImpl(new AttributeDriver($paths));
|
|
$config->setMetadataCache(new ArrayAdapter());
|
|
$uri = getenv('MONGODB_URI');
|
|
|
|
return DocumentManager::create(new Client($uri), $config);
|
|
}
|
|
}
|