Passed
Pull Request — master (#3291)
by Tom
13:53
created

SimpleArrayTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 20
dl 0
loc 51
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testArrayConvertsToDatabaseValue() 0 5 1
A setUp() 0 4 1
A testArrayNormalizesToPHPValue() 0 15 1
A testArrayConvertsToPHPValue() 0 5 1
A testNullConversion() 0 3 1
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Types;
4
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\DBAL\Types\ConversionException;
7
use Doctrine\DBAL\Types\Type;
8
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
9
use Doctrine\Tests\DbalTestCase;
10
use function serialize;
11
12
class SimpleArrayTest extends DbalTestCase
13
{
14
    /** @var AbstractPlatform */
15
    private $platform;
16
17
    /** @var Type */
18
    private $type;
19
20
    protected function setUp()
21
    {
22
        $this->platform = new MockPlatform();
23
        $this->type     = Type::getType('simple_array');
24
    }
25
26
    public function testArrayConvertsToDatabaseValue()
27
    {
28
        self::assertInternalType(
29
            'string',
30
            $this->type->convertToDatabaseValue(['one', 'two', 'three'], $this->platform)
31
        );
32
    }
33
34
    public function testArrayConvertsToPHPValue()
35
    {
36
        self::assertInternalType(
37
            'array',
38
            $this->type->convertToPHPValue('one,two,three', $this->platform)
39
        );
40
    }
41
42
    public function testArrayNormalizesToPHPValue()
43
    {
44
        self::assertInternalType(
45
            'array',
46
            $this->type->normalizeToPHPValue([], $this->platform)
47
        );
48
49
        self::assertInternalType(
50
            'null',
51
            $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...
52
        );
53
54
        self::assertInternalType(
55
            'array',
56
            $this->type->convertToPHPValue('one,two,three', $this->platform)
57
        );
58
    }
59
60
    public function testNullConversion()
61
    {
62
        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...
63
    }
64
}
65