MigrationEventTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testMigrationData() 0 15 1
A testGetData() 0 12 1
1
<?php
2
3
namespace RDV\Bundle\MigrationBundle\Tests\Unit\Event;
4
5
use RDV\Bundle\MigrationBundle\Event\MigrationEvent;
6
7
class MigrationEventTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var MigrationEvent
11
     */
12
    protected $migrationEvent;
13
14
    /** @var \PHPUnit_Framework_MockObject_MockObject */
15
    protected $connection;
16
17
    protected function setUp()
18
    {
19
        $this->connection = $this->getMockBuilder('Doctrine\DBAL\Connection')
20
            ->disableOriginalConstructor()
21
            ->getMock();
22
        $this->migrationEvent = new MigrationEvent($this->connection);
23
    }
24
25
    public function testMigrationData()
26
    {
27
        $middleMigration = $this->getMockForAbstractClass('RDV\Bundle\MigrationBundle\Migration\Migration');
28
        $this->migrationEvent->addMigration($middleMigration);
29
        $firstMigration = $this->getMockForAbstractClass('RDV\Bundle\MigrationBundle\Migration\Migration');
30
        $this->migrationEvent->addMigration($firstMigration, true);
31
        $lastMigration = $this->getMockForAbstractClass('RDV\Bundle\MigrationBundle\Migration\Migration');
32
        $this->migrationEvent->addMigration($lastMigration);
33
34
        $migrations = $this->migrationEvent->getMigrations();
35
        $this->assertEquals(3, count($migrations));
36
        $this->assertEquals($firstMigration, $migrations[0]);
37
        $this->assertEquals($middleMigration, $migrations[1]);
38
        $this->assertEquals($lastMigration, $migrations[2]);
39
    }
40
41
    public function testGetData()
42
    {
43
        $sql = 'select * from test_table';
44
        $params = [];
45
        $types = [];
46
47
        $this->connection->expects($this->once())
48
            ->method('fetchAll')
49
            ->with($sql, $params, $types)
50
            ->will($this->returnValue([]));
51
        $this->migrationEvent->getData($sql, $params, $types);
52
    }
53
}
54