Failed Conditions
Push — master ( fab761...8502a7 )
by Adrien
03:06
created

testConvertToDatabaseValueThrowsWithInvalidValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcodevTests\Felix\DBAL\Types;
6
7
use Cake\Chronos\ChronosTime;
1 ignored issue
show
Bug introduced by
The type Cake\Chronos\ChronosTime 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...
8
use Doctrine\DBAL\Platforms\AbstractPlatform;
9
use Doctrine\DBAL\Platforms\MySQLPlatform;
10
use Doctrine\DBAL\Types\ConversionException;
11
use Ecodev\Felix\DBAL\Types\TimeType;
12
use PHPUnit\Framework\TestCase;
13
14
class TimeTypeTest extends TestCase
15
{
16
    private TimeType $type;
17
18
    private AbstractPlatform $platform;
19
20
    protected function setUp(): void
21
    {
22
        $this->type = new TimeType();
23
        $this->platform = new MySQLPlatform();
24
    }
25
26
    public function testConvertToDatabaseValue(): void
27
    {
28
        self::assertSame('TIME', $this->type->getSqlDeclaration(['foo'], $this->platform));
29
        self::assertFalse($this->type->requiresSQLCommentHint($this->platform));
30
31
        $actual = $this->type->convertToDatabaseValue(new ChronosTime('09:33'), $this->platform);
32
        self::assertSame('09:33:00', $actual, 'support Chronos');
33
34
        self::assertNull($this->type->convertToDatabaseValue(null, $this->platform), 'support null values');
35
    }
36
37
    public function testConvertToPHPValue(): void
38
    {
39
        $actualPhp = $this->type->convertToPHPValue('18:59:23', $this->platform);
40
        self::assertInstanceOf(ChronosTime::class, $actualPhp);
41
        self::assertSame('18:59:23', $actualPhp->__toString(), 'support string');
42
43
        $actualPhp = $this->type->convertToPHPValue(new ChronosTime('18:59:23'), $this->platform);
44
        self::assertInstanceOf(ChronosTime::class, $actualPhp);
45
        self::assertSame('18:59:23', $actualPhp->__toString(), 'support ChronosTime');
46
47
        self::assertNull($this->type->convertToPHPValue(null, $this->platform), 'support null values');
48
    }
49
50
    public function testConvertToPHPValueThrowsWithInvalidValue(): void
51
    {
52
        $this->expectException(ConversionException::class);
53
54
        $this->type->convertToPHPValue(123, $this->platform);
55
    }
56
57
    public function testConvertToDatabaseValueThrowsWithInvalidValue(): void
58
    {
59
        $this->expectException(ConversionException::class);
60
61
        $this->type->convertToDatabaseValue(123, $this->platform);
62
    }
63
}
64