Passed
Pull Request — master (#2144)
by Alan
02:54
created

createTestDocumentManager()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\Test;
15
16
use Doctrine\Common\Annotations\AnnotationReader;
17
use Doctrine\Common\Cache\ArrayCache;
18
use Doctrine\MongoDB\Connection;
19
use Doctrine\ODM\MongoDB\Configuration;
20
use Doctrine\ODM\MongoDB\DocumentManager;
21
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
22
23
/**
24
 * Provides utility functions needed in tests.
25
 *
26
 * @author Alan Poulain <[email protected]>
27
 */
28
class DoctrineMongoDbOdmTestHelper
29
{
30
    /**
31
     * Returns a document manager for testing.
32
     */
33
    public static function createTestDocumentManager(?Configuration $config = null): DocumentManager
34
    {
35
        if (null === $config) {
36
            $config = self::createTestConfiguration();
37
        }
38
39
        $connection = new Connection();
40
41
        return DocumentManager::create($connection, $config);
42
    }
43
44
    public static function createTestConfiguration(): Configuration
45
    {
46
        $config = new Configuration();
47
        $config->setDocumentNamespaces(['SymfonyTestsDoctrine' => 'Symfony\Bridge\Doctrine\Tests\Fixtures']);
48
        $config->setAutoGenerateProxyClasses(true);
49
        $config->setProxyDir(\sys_get_temp_dir());
50
        $config->setProxyNamespace('SymfonyTests\Doctrine');
51
        $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
52
        $config->setMetadataCacheImpl(new ArrayCache());
53
        $config->setHydratorDir(\sys_get_temp_dir().'/Hydrators');
54
        $config->setHydratorNamespace('Hydrators');
55
56
        return $config;
57
    }
58
59
    /**
60
     * This class cannot be instantiated.
61
     */
62
    private function __construct()
63
    {
64
    }
65
}
66