Completed
Push — master ( 63cb48...b7ca1d )
by Julián
02:17
created

CouchDBBuilderTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * doctrine-manager-builder (https://github.com/juliangut/doctrine-manager-builder)
4
 * Doctrine2 managers builder
5
 *
6
 * @license BSD-3-Clause
7
 * @author Julián Gutiérrez <[email protected]>
8
 */
9
10
namespace Jgut\Doctrine\ManagerBuilder\Tests;
11
12
use Doctrine\ODM\CouchDB\DocumentManager;
13
use Jgut\Doctrine\ManagerBuilder\CouchDBBuilder;
14
use Jgut\Doctrine\ManagerBuilder\ManagerBuilder;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Helper\HelperSet;
17
18
/**
19
 * CouchDB entity builder tests.
20
 */
21
class CouchDBBuilderTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var CouchDBBuilder
25
     */
26
    protected $builder;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function setUp()
32
    {
33
        $this->builder = new CouchDBBuilder([], 'test');
34
    }
35
36
    /**
37
     * @expectedException \InvalidArgumentException
38
     */
39
    public function testManagerNoConnection()
40
    {
41
        $this->builder->setOption(
42
            'metadata_mapping',
43
            [
44
                ['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__, 'namespace' => 'annotation'],
45
                ['type' => ManagerBuilder::METADATA_MAPPING_XML, 'path' => __DIR__, 'namespace' => 'xml'],
46
                ['type' => ManagerBuilder::METADATA_MAPPING_YAML, 'path' => __DIR__, 'namespace' => 'yaml'],
47
                ['type' => ManagerBuilder::METADATA_MAPPING_PHP, 'path' => __DIR__, 'namespace' => 'php'],
48
            ]
49
        );
50
51
        $this->builder->getManager(true, true);
52
    }
53
54
    /**
55
     * @expectedException \InvalidArgumentException
56
     * @expectedExceptionMessageRegExp  /^Expecting array of instance of CouchDBClient as first argument/
57
     */
58
    public function testManageWrongConnection()
59
    {
60
        $this->builder->setOption('connection', 'connection');
61
        $this->builder->setOption(
62
            'metadata_mapping',
63
            [['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__]]
64
        );
65
66
        $this->builder->getManager();
67
    }
68
69
    public function testManager()
70
    {
71
        $this->builder->setOption('connection', ['dbname' => 'ddbb']);
72
        $this->builder->setOption(
73
            'metadata_mapping',
74
            [['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__]]
75
        );
76
        $this->builder->setOption('lucene_handler_name', 'lucene');
77
78
        static::assertInstanceOf(DocumentManager::class, $this->builder->getManager(true));
79
    }
80
81
    public function testConsoleCommands()
82
    {
83
        $this->builder->setOption('connection', ['dbname' => 'ddbb']);
84
        $this->builder->setOption(
85
            'metadata_mapping',
86
            [['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__]]
87
        );
88
89
        $commands = $this->builder->getConsoleCommands();
90
91
        return array_walk(
92
            $commands,
93
            function ($command) {
94
                static::assertInstanceOf(Command::class, $command);
95
            }
96
        );
97
    }
98
99
    public function testConsoleHelperSet()
100
    {
101
        $this->builder->setOption('connection', ['dbname' => 'ddbb']);
102
        $this->builder->setOption(
103
            'metadata_mapping',
104
            [['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__]]
105
        );
106
107
        $helperSet = $this->builder->getConsoleHelperSet();
108
109
        static::assertInstanceOf(HelperSet::class, $helperSet);
110
        static::assertTrue($helperSet->has('couchdb'));
111
        static::assertTrue($helperSet->has('dm'));
112
    }
113
}
114