Passed
Push — master ( 68bc04...2d5d0a )
by Adrien
02:23
created

php$0 ➔ testConvertToPHPValueThrowsWithZero()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcodevTests\Felix\DBAL\Types;
6
7
use Doctrine\DBAL\Platforms\AbstractPlatform;
8
use Ecodev\Felix\DBAL\Types\EnumType;
9
use PHPUnit\Framework\TestCase;
10
11
final class EnumTypeTest extends TestCase
12
{
13
    /**
14
     * @var EnumType
15
     */
16
    private $type;
17
18
    /**
19
     * @var AbstractPlatform
20
     */
21
    private $platform;
22
23
    public function setUp(): void
24
    {
25
        $this->type = new class() extends EnumType {
26
            protected function getPossibleValues(): array
27
            {
28
                return ['value1', 'value2'];
29
            }
30
        };
31
32
        $this->platform = $this->createMock(AbstractPlatform::class);
1 ignored issue
show
Documentation Bug introduced by
It seems like $this->createMock(Doctri...bstractPlatform::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Doctrine\DBAL\Platforms\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...
33
    }
34
35
    public function testEnum(): void
36
    {
37
        self::assertSame("ENUM('value1', 'value2')", $this->type->getSqlDeclaration(['foo'], $this->platform));
38
39
        // Should always return string
40
        self::assertSame('value1', $this->type->convertToPHPValue('value1', $this->platform));
41
42
        // Should support null values or empty string
43
        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 Ecodev\Felix\DBAL\Types\...pe::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...
44
        self::assertNull($this->type->convertToPHPValue('', $this->platform));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->type->convertToPH...ue('', $this->platform) targeting Ecodev\Felix\DBAL\Types\...pe::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...
45
        self::assertNull($this->type->convertToDatabaseValue(null, $this->platform));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->type->convertToDa...(null, $this->platform) targeting Ecodev\Felix\DBAL\Types\...onvertToDatabaseValue() 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
        self::assertNull($this->type->convertToDatabaseValue('', $this->platform));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->type->convertToDa...ue('', $this->platform) targeting Ecodev\Felix\DBAL\Types\...onvertToDatabaseValue() 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...
47
48
        self::assertTrue($this->type->requiresSQLCommentHint($this->platform));
49
    }
50
51
    public function testConvertToPHPValueThrowsWithInvalidValue(): void
52
    {
53
        $this->expectException(\InvalidArgumentException::class);
54
55
        $this->type->convertToPHPValue('foo', $this->platform);
56
    }
57
58
    public function testConvertToDatabaseValueThrowsWithInvalidValue(): void
59
    {
60
        $this->expectException(\InvalidArgumentException::class);
61
62
        $this->type->convertToDatabaseValue('foo', $this->platform);
63
    }
64
65
    public function testConvertToPHPValueThrowsWithZero(): void
66
    {
67
        $this->expectException(\InvalidArgumentException::class);
68
69
        $this->type->convertToPHPValue(0, $this->platform);
70
    }
71
72
    public function testConvertToDatabaseValueThrowsWithZero(): void
73
    {
74
        $this->expectException(\InvalidArgumentException::class);
75
76
        $this->type->convertToDatabaseValue(0, $this->platform);
77
    }
78
}
79