Completed
Push — master ( 738857...981736 )
by Roma
01:08
created

SetTypeTest::testConvertToPHPNullValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Test\DBAL\Types;
4
5
6
use PHPUnit\Framework\TestCase;
7
use Doctrine\DBAL\Types\SetType;
8
use Doctrine\DBAL\Platforms\AbstractPlatform;
9
10
class SetTypeTest extends TestCase {
11
12
    /**
13
     * @return AbstractPlatform
14
     */
15
    public function getPlatform() {
16
17
        /** @var AbstractPlatform $mockPlatform */
18
        $mockPlatform = $this->getMockForAbstractClass(AbstractPlatform::class);
19
20
        return $mockPlatform;
21
    }
22
23
    /**
24
     * @return SetType
25
     */
26
    public function getType() {
27
28
        $mockBuilder = $this->getMockBuilder(SetType::class);
29
        $mockBuilder = $mockBuilder->disableOriginalConstructor();
30
        $mockBuilder = $mockBuilder->setMethods(array('getValue', 'getName'));
31
32
        /** @var SetType $mock */
33
        $mock = $mockBuilder->getMock();
34
        $mock->method('getName')->will($this->returnValue('test'));
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Doctrine\DBAL\Types\SetType>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
        $mock->method('getValue')->will($this->returnValue(array('GET', 'SET')));
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Doctrine\DBAL\Types\SetType>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
37
        return $mock;
38
    }
39
40
41
    public function testConvertToDatabaseNullValue() {
42
43
        $result = $this->getType()->convertToDatabaseValue(null, $this->getPlatform());
44
45
        $this->assertNull($result);
46
    }
47
48
    /**
49
     * @expectedException \InvalidArgumentException
50
     */
51
    public function testConvertToDatabaseValueNotArray() {
52
53
        $this->getType()->convertToDatabaseValue('NOT_ALLOWED', $this->getPlatform());
54
    }
55
56
    /**
57
     * @expectedException \InvalidArgumentException
58
     */
59
    public function testConvertToDatabaseValueNotAllowed() {
60
61
        $this->getType()->convertToDatabaseValue(array('NOT_ALLOWED'), $this->getPlatform());
62
    }
63
64
    public function testConvertToDatabaseValue() {
65
66
        $result = $this->getType()->convertToDatabaseValue(array('GET'), $this->getPlatform());
67
68
        $this->assertEquals('GET', $result);
69
    }
70
71
    public function testConvertToPHPNullValue() {
72
73
        $result = $this->getType()->convertToPHPValue(null, $this->getPlatform());
74
75
        $this->assertNull($result);
76
    }
77
78
    public function testConvertToPHPValue() {
79
80
        $result = $this->getType()->convertToPHPValue('TEST', $this->getPlatform());
81
82
        $this->assertEquals(array('TEST'), $result);
83
    }
84
85
    public function testGetSQLDeclaration() {
86
87
        $result = $this->getType()->getSQLDeclaration(array(), $this->getPlatform());
88
89
        $this->assertEquals('SET ( \'GET\',\'SET\' )', $result);
90
    }
91
92
    public function testRequiresSQLCommentHint() {
93
94
        $this->assertTrue($this->getType()->requiresSQLCommentHint($this->getPlatform()));
95
    }
96
}
97