Completed
Push — master ( 1ed64c...63fdb5 )
by Julián
02:29
created

CLIApplicationBuilderTest::testOnlyEntityManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
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\CLIApplicationBuilder;
13
14
/**
15
 * @covers Jgut\Slim\Doctrine\CLIApplicationBuilder
16
 */
17
class CLIApplicationBuilderTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @expectedException \InvalidArgumentException
21
     */
22
    public function testNoEntityManager()
23
    {
24
        CLIApplicationBuilder::build('');
1 ignored issue
show
Documentation introduced by
'' is of type string, but the function expects a array|object<Doctrine\ORM\EntityManager>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
25
    }
26
27
    public function testOnlyEntityManager()
28
    {
29
        $entityOptions = [
30
            'connection' => [
31
                'driver' => 'pdo_sqlite',
32
                'memory' => true,
33
            ],
34
            'annotation_paths' => sys_get_temp_dir(),
35
        ];
36
37
        $application = CLIApplicationBuilder::build($entityOptions);
38
39
        self::assertInstanceOf('Symfony\Component\Console\Application', $application);
40
    }
41
42
    /**
43
     * @expectedException \InvalidArgumentException
44
     */
45
    public function testNoDocumentManager()
46
    {
47
        $entityOptions = [
48
            'connection' => [
49
                'driver' => 'pdo_sqlite',
50
                'memory' => true,
51
            ],
52
            'annotation_paths' => sys_get_temp_dir(),
53
        ];
54
55
        CLIApplicationBuilder::build($entityOptions, '');
1 ignored issue
show
Documentation introduced by
'' is of type string, but the function expects a array|object<Doctrine\OD...B\DocumentManager>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
    }
57
58
    public function testBothManagers()
59
    {
60
        $entityOptions = [
61
            'connection' => [
62
                'driver' => 'pdo_sqlite',
63
                'memory' => true,
64
            ],
65
            'annotation_paths' => sys_get_temp_dir(),
66
        ];
67
        $documentOptions = [
68
            'connection' => [
69
                'server' => 'mongodb://localhost:27017',
70
            ],
71
            'annotation_paths' => sys_get_temp_dir(),
72
        ];
73
74
        $application = CLIApplicationBuilder::build($entityOptions, $documentOptions);
75
76
        self::assertInstanceOf('Symfony\Component\Console\Application', $application);
77
        self::assertTrue($application->has('odm:generate:documents'));
78
        self::assertTrue($application->has('odm:generate:hydrators'));
79
        self::assertTrue($application->has('odm:generate:proxies'));
80
        self::assertTrue($application->has('odm:generate:repositories'));
81
        self::assertTrue($application->has('odm:clear-cache:metadata'));
82
        self::assertTrue($application->has('odm:schema:create'));
83
        self::assertTrue($application->has('odm:schema:drop'));
84
        self::assertTrue($application->has('odm:schema:update'));
85
    }
86
}
87