Completed
Push — master ( 016ff4...fb2978 )
by Julián
07:54
created

DocumentManagerBuilderTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 104
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testBadCacheDriver() 0 8 1
A testNoMetadata() 0 11 1
A testNoCreation() 0 13 1
A testAnnotationsCreation() 0 11 1
A testXMLCreation() 0 11 1
A testYAMLCreation() 0 11 1
1
<?php
2
/**
3
 * Slim3 Doctrine integration (https://github.com/juliangut/slim-doctrine)
4
 *
5
 * @link https://github.com/juliangut/slim-doctrine for the canonical source repository
6
 *
7
 * @license https://raw.githubusercontent.com/juliangut/slim-doctrine/master/LICENSE
8
 */
9
10
namespace Jgut\Slim\Doctrine\Tests;
11
12
use Jgut\Slim\Doctrine\DocumentManagerBuilder;
13
use Doctrine\Common\Proxy\AbstractProxyFactory;
14
15
/**
16
 * @covers Jgut\Slim\Doctrine\DocumentManagerBuilder
17
 */
18
class DocumentManagerBuilderTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @cover \Jgut\Slim\Doctrine\DocumentManagerBuilder::build
22
     *
23
     * @expectedException \InvalidArgumentException
24
     */
25
    public function testBadCacheDriver()
26
    {
27
        $options = [
28
            'cache_driver' => 'notValid',
29
        ];
30
31
        DocumentManagerBuilder::build($options);
32
    }
33
34
    /**
35
     * @cover \Jgut\Slim\Doctrine\DocumentManagerBuilder::build
36
     * @cover \Jgut\Slim\Doctrine\DocumentManagerBuilder::setupAnnotationMetadata
37
     *
38
     * @expectedException \InvalidArgumentException
39
     */
40
    public function testNoMetadata()
41
    {
42
        $options = [
43
            'annotation_files' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'],
44
            'annotation_namespaces' => ['\Jgut\Slim\Doctrine'],
45
            'annotation_autoloaders' => [function () {
46
            }],
47
        ];
48
49
        DocumentManagerBuilder::build($options);
50
    }
51
52
    /**
53
     * @cover \Jgut\Slim\Doctrine\DocumentManagerBuilder::build
54
     * @cover \Jgut\Slim\Doctrine\DocumentManagerBuilder::setupProxy
55
     * @cover \Jgut\Slim\Doctrine\DocumentManagerBuilder::setupHydrator
56
     * @cover \Jgut\Slim\Doctrine\DocumentManagerBuilder::setupLogger
57
     *
58
     * @expectedException \InvalidArgumentException
59
     */
60
    public function testNoCreation()
61
    {
62
        $options = [
63
            'annotation_paths' => sys_get_temp_dir(),
64
            'proxies_namespace' => 'myNamespace\Proxies',
65
            'auto_generate_proxies' => AbstractProxyFactory::AUTOGENERATE_ALWAYS,
66
            'hydrators_namespace' => 'myNamespace\Hydrators',
67
            'logger_callable' => function () {
68
            },
69
        ];
70
71
        DocumentManagerBuilder::build($options);
72
    }
73
74
    /**
75
     * @cover \Jgut\Slim\Doctrine\DocumentManagerBuilder::build
76
     * @cover \Jgut\Slim\Doctrine\DocumentManagerBuilder::createConfiguration
77
     */
78
    public function testAnnotationsCreation()
79
    {
80
        $options = [
81
            'connection' => [
82
                'server' => 'mongodb://localhost:27017',
83
            ],
84
            'annotation_paths' => sys_get_temp_dir(),
85
        ];
86
87
        $this->assertInstanceOf('\Doctrine\ODM\MongoDB\DocumentManager', DocumentManagerBuilder::build($options));
88
    }
89
90
    /**
91
     * @cover \Jgut\Slim\Doctrine\DocumentManagerBuilder::build
92
     * @cover \Jgut\Slim\Doctrine\DocumentManagerBuilder::createConfiguration
93
     */
94
    public function testXMLCreation()
95
    {
96
        $options = [
97
            'connection' => [
98
                'server' => 'mongodb://localhost:27017',
99
            ],
100
            'xml_paths' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'],
101
        ];
102
103
        $this->assertInstanceOf('\Doctrine\ODM\MongoDB\DocumentManager', DocumentManagerBuilder::build($options));
104
    }
105
106
    /**
107
     * @cover \Jgut\Slim\Doctrine\DocumentManagerBuilder::build
108
     * @cover \Jgut\Slim\Doctrine\DocumentManagerBuilder::createConfiguration
109
     */
110
    public function testYAMLCreation()
111
    {
112
        $options = [
113
            'connection' => [
114
                'server' => 'mongodb://localhost:27017',
115
            ],
116
            'yaml_paths' => [dirname(__DIR__) . '/files/fakeAnnotationFile.php'],
117
        ];
118
119
        $this->assertInstanceOf('\Doctrine\ODM\MongoDB\DocumentManager', DocumentManagerBuilder::build($options));
120
    }
121
}
122