Passed
Pull Request — master (#3291)
by Tom
63:46
created

testArrayConvertsToDatabaseValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
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() : void
19
    {
20
        $this->platform = new MockPlatform();
21
        $this->type     = Type::getType('simple_array');
22
    }
23
24
    public function testArrayConvertsToDatabaseValue()
25
    {
26
        self::assertIsString(
27
            $this->type->convertToDatabaseValue(['one', 'two', 'three'], $this->platform)
28
        );
29
    }
30
31
    public function testArrayConvertsToPHPValue()
32
    {
33
        self::assertIsArray(
34
            $this->type->convertToPHPValue('one,two,three', $this->platform)
35
        );
36
    }
37
38
    public function testArrayNormalizesToPHPValue()
39
    {
40
        self::assertIsArray(
41
            $this->type->normalizeToPHPValue([], $this->platform)
42
        );
43
44
        self::assertNull(
45
            $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...
46
        );
47
48
        self::assertIsArray(
49
            $this->type->convertToPHPValue('one,two,three', $this->platform)
50
        );
51
    }
52
53
    public function testNullConversion()
54
    {
55
        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...
56
    }
57
}
58