CHFTypeTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testConvertToDatabaseValueThrowsWithInvalidValue() 0 4 1
A testMoney() 0 12 1
A testConvertToPHPValueThrowsWithInvalidValue() 0 4 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 InvalidArgumentException;
11
use Money\Money;
12
use PHPUnit\Framework\TestCase;
13
14
final class CHFTypeTest extends TestCase
15
{
16
    private CHFType $type;
17
18
    private AbstractPlatform $platform;
19
20
    protected function setUp(): void
21
    {
22
        $this->type = new CHFType();
23
24
        $this->platform = new MySQLPlatform();
25
    }
26
27
    public function testMoney(): void
28
    {
29
        self::assertSame('INT', $this->type->getSqlDeclaration(['foo' => 'bar'], $this->platform));
30
31
        // Should always return string
32
        $actualPhp = $this->type->convertToPHPValue(100, $this->platform);
33
        self::assertInstanceOf(Money::class, $actualPhp);
34
        self::assertTrue(Money::CHF(100)->equals($actualPhp));
0 ignored issues
show
Bug introduced by
It seems like $actualPhp can also be of type null; however, parameter $other of Money\Money::equals() does only seem to accept Money\Money, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        self::assertTrue(Money::CHF(100)->equals(/** @scrutinizer ignore-type */ $actualPhp));
Loading history...
35
36
        // Should support null values
37
        self::assertNull($this->type->convertToPHPValue(null, $this->platform));
38
        self::assertNull($this->type->convertToDatabaseValue(null, $this->platform));
39
    }
40
41
    public function testConvertToPHPValueThrowsWithInvalidValue(): void
42
    {
43
        $this->expectException(InvalidArgumentException::class);
44
        $this->type->convertToPHPValue('foo', $this->platform);
45
    }
46
47
    public function testConvertToDatabaseValueThrowsWithInvalidValue(): void
48
    {
49
        $this->expectException(InvalidArgumentException::class);
50
        $this->type->convertToDatabaseValue('foo', $this->platform);
51
    }
52
}
53