Completed
Push — master ( e36983...47c243 )
by Julián
04:08
created

testBadDocumentManagers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
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 testNoManagers()
23
    {
24
        CLIApplicationBuilder::build();
25
    }
26
27
    /**
28
     * @expectedException \InvalidArgumentException
29
     */
30
    public function testBadEntityManagers()
31
    {
32
        CLIApplicationBuilder::build('');
0 ignored issues
show
Documentation introduced by
'' is of type string, but the function expects a array|object<Doctrine\ORM\EntityManager>|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...
33
    }
34
35
    public function testEntityManager()
36
    {
37
        $entityOptions = [
38
            'connection' => [
39
                'driver' => 'pdo_sqlite',
40
                'memory' => true,
41
            ],
42
            'annotation_paths' => sys_get_temp_dir(),
43
        ];
44
45
        $application = CLIApplicationBuilder::build($entityOptions);
46
47
        self::assertInstanceOf('Symfony\Component\Console\Application', $application);
48
        self::assertTrue($application->has('orm:schema-tool:create'));
49
    }
50
51
    /**
52
     * @expectedException \InvalidArgumentException
53
     */
54
    public function testBadDocumentManagers()
55
    {
56
        CLIApplicationBuilder::build(null, '');
0 ignored issues
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...
57
    }
58
59
    public function testDocumentManagers()
60
    {
61
        $documentOptions = [
62
            'connection' => [
63
                'server' => 'mongodb://localhost:27017',
64
            ],
65
            'annotation_paths' => sys_get_temp_dir(),
66
        ];
67
68
        $application = CLIApplicationBuilder::build(null, $documentOptions);
69
70
        self::assertInstanceOf('Symfony\Component\Console\Application', $application);
71
        self::assertTrue($application->has('odm:generate:documents'));
72
        self::assertTrue($application->has('odm:generate:hydrators'));
73
        self::assertTrue($application->has('odm:generate:proxies'));
74
        self::assertTrue($application->has('odm:generate:repositories'));
75
        self::assertTrue($application->has('odm:clear-cache:metadata'));
76
        self::assertTrue($application->has('odm:schema:create'));
77
        self::assertTrue($application->has('odm:schema:drop'));
78
        self::assertTrue($application->has('odm:schema:update'));
79
    }
80
}
81