Failed Conditions
Pull Request — master (#3291)
by Tom
63:05
created

SimpleArrayTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testArrayConvertsStringToPHPValue() 0 5 1
A setUp() 0 4 1
A testArrayConvertsArrayToDatabaseValue() 0 5 1
A testArrayPassesThroughArrayForConvertToPHPValue() 0 5 1
A testNullConvertsToPHPValue() 0 5 1
A testEmptyArrayConvertsToNullToDatabaseValue() 0 5 1
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Types;
4
5
use Doctrine\DBAL\Types\Type;
6
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
7
use Doctrine\Tests\DbalTestCase;
8
9
class SimpleArrayTest extends DbalTestCase
10
{
11
    /** @var AbstractPlatform */
0 ignored issues
show
Bug introduced by
The type Doctrine\Tests\DBAL\Types\AbstractPlatform was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
    protected $_platform;
13
14
    /** @var Type */
15
    protected $_type;
16
17
    protected function setUp()
18
    {
19
        $this->_platform = new MockPlatform();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Tests\DBAL\Mocks\MockPlatform() of type Doctrine\Tests\DBAL\Mocks\MockPlatform is incompatible with the declared type Doctrine\Tests\DBAL\Types\AbstractPlatform of property $_platform.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
20
        $this->_type     = Type::getType('simple_array');
21
    }
22
23
    public function testEmptyArrayConvertsToNullToDatabaseValue()
24
    {
25
        self::assertInternalType(
26
            'null',
27
            $this->_type->convertToDatabaseValue([], $this->_platform)
28
        );
29
    }
30
31
    public function testArrayConvertsArrayToDatabaseValue()
32
    {
33
        self::assertInternalType(
34
            'string',
35
            $this->_type->convertToDatabaseValue(['one', 'two'], $this->_platform)
36
        );
37
    }
38
39
    public function testArrayConvertsStringToPHPValue()
40
    {
41
        self::assertInternalType(
42
            'array',
43
            $this->_type->convertToPHPValue('one,two', $this->_platform)
44
        );
45
    }
46
47
    public function testNullConvertsToPHPValue()
48
    {
49
        self::assertInternalType(
50
            'array',
51
            $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...
52
        );
53
    }
54
55
    public function testArrayPassesThroughArrayForConvertToPHPValue()
56
    {
57
        self::assertInternalType(
58
            'array',
59
            $this->_type->convertToPHPValue([], $this->_platform)
60
        );
61
    }
62
}
63