Completed
Pull Request — master (#3291)
by Tom
12:57
created

SimpleArrayTest::testArrayConvertsToPHPValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 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 Doctrine\Tests\DbalTestCase;
9
10
class SimpleArrayTest extends DbalTestCase
11
{
12
    /** @var AbstractPlatform */
13
    private $platform;
14
15
    /** @var Type */
16
    private $type;
17
18
    protected function setUp()
19
    {
20
        $this->platform = new MockPlatform();
21
        $this->type     = Type::getType('simple_array');
22
    }
23
24
    public function testArrayConvertsToDatabaseValue()
25
    {
26
        self::assertInternalType(
27
            'string',
28
            $this->type->convertToDatabaseValue(['one', 'two', 'three'], $this->platform)
29
        );
30
    }
31
32
    public function testArrayConvertsToPHPValue()
33
    {
34
        self::assertInternalType(
35
            'array',
36
            $this->type->convertToPHPValue('one,two,three', $this->platform)
37
        );
38
    }
39
40
    public function testArrayNormalizesToPHPValue()
41
    {
42
        self::assertInternalType(
43
            'array',
44
            $this->type->normalizeToPHPValue([], $this->platform)
45
        );
46
47
        self::assertInternalType(
48
            'null',
49
            $this->type->normalizeToPHPValue(null, $this->platform)
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->type->normalizeTo...(null, $this->platform) targeting Doctrine\DBAL\Types\Type::normalizeToPHPValue() 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...
50
        );
51
52
        self::assertInternalType(
53
            'array',
54
            $this->type->convertToPHPValue('one,two,three', $this->platform)
55
        );
56
    }
57
58
    public function testNullConversion()
59
    {
60
        self::assertNull($this->type->convertToPHPValue(null, $this->platform));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->type->convertToPH...(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...
61
    }
62
}
63