Completed
Pull Request — master (#523)
by
unknown
08:47
created

testExecuteWithoutForce()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 23
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 23
loc 23
rs 9.0856
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Doctrine Bundle
5
 *
6
 * The code was originally distributed inside the Symfony framework.
7
 *
8
 * (c) Fabien Potencier <[email protected]>
9
 * (c) Doctrine Project, Benjamin Eberlei <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Doctrine\Bundle\DoctrineBundle\Tests\Command;
16
17
use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
18
use Symfony\Component\Console\Application;
19
use Symfony\Component\Console\Tester\CommandTester;
20
21
class DropDatabaseDoctrineTest extends \PHPUnit_Framework_TestCase
22
{
23 View Code Duplication
    public function testExecuteWithoutForce()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        $connectionName = 'default';
26
        $dbName = 'test';
27
        $params = array(
28
            'dbname' => $dbName,
29
            'memory' => true,
30
            'driver' => 'pdo_sqlite'
31
        );
32
33
        $application = new Application();
34
        $application->add(new DropDatabaseDoctrineCommand());
35
36
        $command = $application->find('doctrine:database:drop');
37
        $command->setContainer($this->getMockContainer($connectionName, $params));
38
39
        $commandTester = new CommandTester($command);
40
        $commandTester->execute(
41
            array_merge(array('command' => $command->getName()))
42
        );
43
44
        $this->assertContains("Please run the operation with --force to execute", $commandTester->getDisplay());
45
    }
46
47 View Code Duplication
    public function testExecute()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        $connectionName = 'default';
50
        $dbName = 'test';
51
        $params = array(
52
            'dbname' => $dbName,
53
            'memory' => true,
54
            'driver' => 'pdo_sqlite'
55
        );
56
57
        $application = new Application();
58
        $application->add(new DropDatabaseDoctrineCommand());
59
60
        $command = $application->find('doctrine:database:drop');
61
        $command->setContainer($this->getMockContainer($connectionName, $params));
62
63
        $commandTester = new CommandTester($command);
64
        $commandTester->execute(
65
            array_merge(array('command' => $command->getName(), '--force' => true))
66
        );
67
68
        $this->assertContains("Dropped database for connection named \"$dbName\"", $commandTester->getDisplay());
69
    }
70
71
72
    /**
73
     * @param $connectionName
74
     * @param null $params Connection parameters
75
     * @return \PHPUnit_Framework_MockObject_MockObject
76
     */
77 View Code Duplication
    private function getMockContainer($connectionName, $params=null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        // Mock the container and everything you'll need here
80
        $mockDoctrine = $this->getMockBuilder('Doctrine\Common\Persistence\ConnectionRegistry')
81
            ->getMock();
82
83
        $mockDoctrine->expects($this->any())
84
            ->method('getDefaultConnectionName')
85
            ->withAnyParameters()
86
            ->willReturn($connectionName)
87
        ;
88
89
90
        $mockConnection = $this->getMockBuilder('Doctrine\DBAL\Connection')
91
            ->disableOriginalConstructor()
92
            ->setMethods(array('getParams'))
93
            ->getMockForAbstractClass();
94
95
        $mockConnection->expects($this->any())
96
            ->method('getParams')
97
            ->withAnyParameters()
98
            ->willReturn($params);
99
100
        
101
        $mockDoctrine->expects($this->any())
102
            ->method('getConnection')
103
            ->withAnyParameters()
104
            ->willReturn($mockConnection);
105
        ;
106
107
108
        $mockContainer = $this->getMockBuilder('Symfony\Component\DependencyInjection\Container')
109
            ->setMethods(array('get'))
110
            ->getMock();
111
112
        $mockContainer->expects($this->any())
113
            ->method('get')
114
            ->with('doctrine')
115
            ->willReturn($mockDoctrine);
116
117
        return $mockContainer;
118
    }
119
}
120