Completed
Pull Request — master (#3254)
by Farhad
14:30
created

ArrayTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Types;
4
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\DBAL\Types\Type;
7
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
8
use function serialize;
9
10
class ArrayTest extends \Doctrine\Tests\DbalTestCase
11
{
12
    /**
13
     * @var AbstractPlatform
14
     */
15
    protected $_platform;
16
17
    /**
18
     * @var Type
19
     */
20
    protected $_type;
21
22
    protected function setUp()
23
    {
24
        $this->_platform = new MockPlatform();
25
        $this->_type = Type::getType('array');
26
    }
27
28
    public function testArrayConvertsToDatabaseValue()
29
    {
30
        self::assertInternalType(
31
            'string',
32
            $this->_type->convertToDatabaseValue(array(), $this->_platform)
33
        );
34
    }
35
36
    public function testArrayConvertsToPHPValue()
37
    {
38
        self::assertInternalType(
39
            'array',
40
            $this->_type->convertToPHPValue(serialize(array()), $this->_platform)
41
        );
42
    }
43
44
    public function testConversionFailure()
45
    {
46
        $this->expectException('Doctrine\DBAL\Types\ConversionException');
47
        $this->expectExceptionMessage("Could not convert database value to 'array' as an error was triggered by the unserialization: 'unserialize(): Error at offset 0 of 7 bytes'");
48
        $this->_type->convertToPHPValue('abcdefg', $this->_platform);
49
    }
50
51
    public function testNullConversion()
52
    {
53
        self::assertNull($this->_type->convertToPHPValue(null, $this->_platform));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->_type->convertToP...null, $this->_platform) targeting Doctrine\DBAL\Types\Type::convertToPHPValue() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
54
    }
55
56
    /**
57
     * @group DBAL-73
58
     */
59
    public function testFalseConversion()
60
    {
61
        self::assertFalse($this->_type->convertToPHPValue(serialize(false), $this->_platform));
62
    }
63
}
64