Completed
Push — master ( 0d0a18...6997ac )
by Julián
02:15
created

CouchDBBuilderTest::testConsoleHelperSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
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
 * @group couchdb
22
 */
23
class CouchDBBuilderTest extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @var CouchDBBuilder
27
     */
28
    protected $builder;
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function setUp()
34
    {
35
        $this->builder = new CouchDBBuilder([], 'test');
36
    }
37
38
    /**
39
     * @expectedException \InvalidArgumentException
40
     */
41
    public function testManagerNoConnection()
42
    {
43
        $this->builder->setOption(
44
            'metadata_mapping',
45
            [
46
                ['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__, 'namespace' => 'annotation'],
47
                ['type' => ManagerBuilder::METADATA_MAPPING_XML, 'path' => __DIR__, 'namespace' => 'xml'],
48
                ['type' => ManagerBuilder::METADATA_MAPPING_YAML, 'path' => __DIR__, 'namespace' => 'yaml'],
49
                ['type' => ManagerBuilder::METADATA_MAPPING_PHP, 'path' => __DIR__, 'namespace' => 'php'],
50
            ]
51
        );
52
53
        $this->builder->getManager(true);
54
    }
55
56
    /**
57
     * @expectedException \InvalidArgumentException
58
     * @expectedExceptionMessageRegExp  /^Expecting array of instance of CouchDBClient as first argument/
59
     */
60
    public function testManageWrongConnection()
61
    {
62
        $this->builder->setOption('connection', 'connection');
63
        $this->builder->setOption(
64
            'metadata_mapping',
65
            [['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__]]
66
        );
67
68
        $this->builder->getManager();
69
    }
70
71
    public function testManager()
72
    {
73
        $this->builder->setOption('connection', ['dbname' => 'ddbb']);
74
        $this->builder->setOption(
75
            'metadata_mapping',
76
            [['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__]]
77
        );
78
        $this->builder->setOption('lucene_handler_name', 'lucene');
79
80
        static::assertInstanceOf(DocumentManager::class, $this->builder->getManager());
81
    }
82
83
    public function testConsoleCommands()
84
    {
85
        $this->builder->setOption('connection', ['dbname' => 'ddbb']);
86
        $this->builder->setOption(
87
            'metadata_mapping',
88
            [['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__]]
89
        );
90
91
        $commands = $this->builder->getConsoleCommands();
92
93
        return array_walk(
94
            $commands,
95
            function (Command $command) {
96
                static::assertEquals(1, preg_match('/^test:(odm:)?/', $command->getName()));
97
            }
98
        );
99
    }
100
101
    public function testConsoleHelperSet()
102
    {
103
        $this->builder->setOption('connection', ['dbname' => 'ddbb']);
104
        $this->builder->setOption(
105
            'metadata_mapping',
106
            [['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__]]
107
        );
108
109
        $helperSet = $this->builder->getConsoleHelperSet();
110
111
        static::assertInstanceOf(HelperSet::class, $helperSet);
112
        static::assertTrue($helperSet->has('couchdb'));
113
        static::assertTrue($helperSet->has('dm'));
114
    }
115
}
116