Failed Conditions
Push — master ( 5e6761...398dce )
by Adrien
04:14 queued 01:57
created

CHFTypeTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testConvertToDatabaseValueThrowsWithInvalidValue() 0 4 1
A testMoney() 0 14 1
A testConvertToPHPValueThrowsWithInvalidValue() 0 4 1
A setUp() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcodevTests\Felix\DBAL\Types;
6
7
use Doctrine\DBAL\Platforms\AbstractPlatform;
8
use Doctrine\DBAL\Platforms\MySqlPlatform;
9
use Ecodev\Felix\DBAL\Types\CHFType;
10
use Money\Money;
11
use PHPUnit\Framework\TestCase;
12
13
class CHFTypeTest extends TestCase
14
{
15
    /**
16
     * @var CHFType
17
     */
18
    private $type;
19
20
    /**
21
     * @var AbstractPlatform
22
     */
23
    private $platform;
24
25
    public function setUp(): void
26
    {
27
        $this->type = $this->getMockBuilder(CHFType::class)
1 ignored issue
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(Ec...ods(array())->getMock() of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Ecodev\Felix\DBAL\Types\CHFType of property $type.

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...
28
            ->disableOriginalConstructor()
29
            ->onlyMethods([])
30
            ->getMock();
31
        $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...
32
        $this->platform = new MySqlPlatform();
33
    }
34
35
    public function testMoney(): void
36
    {
37
        self::assertSame('INT', $this->type->getSqlDeclaration(['foo'], $this->platform));
38
39
        // Should always return string
40
        $actualPhp = $this->type->convertToPHPValue(100, $this->platform);
41
        self::assertInstanceOf(Money::class, $actualPhp);
42
        self::assertTrue(Money::CHF(100)->equals($actualPhp));
43
44
        // Should support null values
45
        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...
46
        self::assertNull($this->type->convertToDatabaseValue(null, $this->platform));
47
48
        self::assertTrue($this->type->requiresSQLCommentHint($this->platform));
49
    }
50
51
    public function testConvertToPHPValueThrowsWithInvalidValue(): void
52
    {
53
        $this->expectException(\InvalidArgumentException::class);
54
        $this->type->convertToPHPValue('foo', $this->platform);
55
    }
56
57
    public function testConvertToDatabaseValueThrowsWithInvalidValue(): void
58
    {
59
        $this->expectException(\InvalidArgumentException::class);
60
        $this->type->convertToDatabaseValue('foo', $this->platform);
61
    }
62
}
63