SetTypeTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testConvertToDatabaseValueNotAllowed() 0 4 1
A testConvertToDatabaseValue() 0 6 1
A testConvertToPHPNullValue() 0 6 1
A testConvertToPHPValue() 0 6 1
A testGetSQLDeclaration() 0 6 1
A testRequiresSQLCommentHint() 0 4 1
A getPlatform() 0 7 1
A getType() 0 13 1
A testConvertToDatabaseNullValue() 0 6 1
A testConvertToDatabaseValueNotArray() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * Team: jungle
5
 * User: Roma Baranenko
6
 * Contacts: <[email protected]>
7
 * Date: 05.12.17
8
 * Time: 18:50
9
 */
10
11
namespace Doctrine\Test\DBAL\Types;
12
13
14
use PHPUnit\Framework\TestCase;
15
use Doctrine\DBAL\Types\SetType;
16
use Doctrine\DBAL\Platforms\AbstractPlatform;
17
18
/**
19
 * Class SetTypeTest
20
 * @package Doctrine\Test\DBAL\Types
21
 * @author Roma Baranenko <[email protected]>
22
 */
23
class SetTypeTest extends TestCase {
24
25
    /**
26
     * @return AbstractPlatform
27
     */
28
    public function getPlatform() {
29
30
        /** @var AbstractPlatform $mockPlatform */
31
        $mockPlatform = $this->getMockForAbstractClass(AbstractPlatform::class);
32
33
        return $mockPlatform;
34
    }
35
36
    /**
37
     * @return SetType
38
     */
39
    public function getType() {
40
41
        $mockBuilder = $this->getMockBuilder(SetType::class);
42
        $mockBuilder = $mockBuilder->disableOriginalConstructor();
43
        $mockBuilder = $mockBuilder->setMethods(array('getValue', 'getName'));
44
45
        $mock = $mockBuilder->getMock();
46
        $mock->method('getName')->will($this->returnValue('test'));
47
        $mock->method('getValue')->will($this->returnValue(array('GET', 'SET')));
48
49
        /** @var SetType $mock */
50
        return $mock;
51
    }
52
53
54
    public function testConvertToDatabaseNullValue() {
55
56
        $result = $this->getType()->convertToDatabaseValue(null, $this->getPlatform());
57
58
        $this->assertNull($result);
59
    }
60
61
    /**
62
     * @expectedException \InvalidArgumentException
63
     */
64
    public function testConvertToDatabaseValueNotArray() {
65
66
        $this->getType()->convertToDatabaseValue('NOT_ALLOWED', $this->getPlatform());
67
    }
68
69
    /**
70
     * @expectedException \InvalidArgumentException
71
     */
72
    public function testConvertToDatabaseValueNotAllowed() {
73
74
        $this->getType()->convertToDatabaseValue(array('NOT_ALLOWED'), $this->getPlatform());
75
    }
76
77
    public function testConvertToDatabaseValue() {
78
79
        $result = $this->getType()->convertToDatabaseValue(array('GET'), $this->getPlatform());
80
81
        $this->assertEquals('GET', $result);
82
    }
83
84
    public function testConvertToPHPNullValue() {
85
86
        $result = $this->getType()->convertToPHPValue(null, $this->getPlatform());
87
88
        $this->assertNull($result);
89
    }
90
91
    public function testConvertToPHPValue() {
92
93
        $result = $this->getType()->convertToPHPValue('TEST', $this->getPlatform());
94
95
        $this->assertEquals(array('TEST'), $result);
96
    }
97
98
    public function testGetSQLDeclaration() {
99
100
        $result = $this->getType()->getSQLDeclaration(array(), $this->getPlatform());
101
102
        $this->assertEquals('SET ( \'GET\',\'SET\' )', $result);
103
    }
104
105
    public function testRequiresSQLCommentHint() {
106
107
        $this->assertTrue($this->getType()->requiresSQLCommentHint($this->getPlatform()));
108
    }
109
}
110