SchemaDumperExtensionTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace RDV\Bundle\MigrationBundle\Tests\Unit\Tools;
4
5
use Doctrine\DBAL\Schema\Column;
6
use Doctrine\DBAL\Types\Type;
7
8
use RDV\Bundle\MigrationBundle\Twig\SchemaDumperExtension;
9
10
class SchemaDumperExtensionTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var SchemaDumperExtension
14
     */
15
    protected $extension;
16
17
    /**
18
     * @var \PHPUnit_Framework_MockObject_MockObject
19
     */
20
    protected $platform;
21
22
    /**
23
     * @var \PHPUnit_Framework_MockObject_MockObject
24
     */
25
    protected $managerRegistry;
26
27
    protected function setUp()
28
    {
29
        $this->managerRegistry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
30
        $this->extension = new SchemaDumperExtension($this->managerRegistry);
31
    }
32
33
    public function testGetName()
34
    {
35
        $this->assertEquals('schema_dumper_extension', $this->extension->getName());
36
    }
37
38
    public function testGetFunctions()
39
    {
40
        $this->assertEquals(1, count($this->extension->getFunctions()));
41
    }
42
43
    public function testGetStringColumnOptions()
44
    {
45
        $this->assertPlatform();
46
        $this->platform->expects($this->once())
47
            ->method('isCommentedDoctrineType')
48
            ->will($this->returnValue(false));
49
50
        $column = new Column('string_column', Type::getType(Type::STRING));
51
        $column->setLength(255);
52
        $result = $this->extension->getColumnOptions($column);
53
        $this->assertEquals(1, count($result));
54
        $this->assertEquals(255, $result['length']);
55
    }
56
57
    public function testGetIntegerColumnOptions()
58
    {
59
        $this->assertPlatform();
60
        $this->platform->expects($this->once())
61
            ->method('isCommentedDoctrineType')
62
            ->will($this->returnValue(true));
63
64
        $column = new Column('string_column', Type::getType(Type::INTEGER));
65
        $column->setNotnull(false);
66
        $column->setAutoincrement(true);
67
        $column->setUnsigned(true);
68
        $result = $this->extension->getColumnOptions($column);
69
        $this->assertEquals(4, count($result));
70
        $this->assertTrue($result['unsigned']);
71
        $this->assertTrue($result['autoincrement']);
72
        $this->assertFalse($result['notnull']);
73
        $this->assertEquals('(DC2Type:integer)', $result['comment']);
74
    }
75
76
    protected function assertPlatform()
77
    {
78
        $this->platform = $this->getMockBuilder('Doctrine\DBAL\Platforms\AbstractPlatform')
79
            ->disableOriginalConstructor()
80
            ->setMethods(['isCommentedDoctrineType'])
81
            ->getMockForAbstractClass();
82
83
        $connection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
84
        $connection->expects($this->once())
85
            ->method('getDatabasePlatform')
86
            ->will($this->returnValue($this->platform));
87
        $this->managerRegistry->expects($this->once())
88
            ->method('getConnection')
89
            ->will($this->returnValue($connection));
90
    }
91
}
92