GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Branch master (3b9792)
by Tomasz
01:41
created

testImpossibleDatabaseConversionWithUnsupportedValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
declare(strict_types=1);
3
namespace Thunder\Platenum\Tests;
4
5
use Doctrine\DBAL\DriverManager;
6
use Doctrine\DBAL\Platforms\MySqlPlatform;
7
use Doctrine\ORM\Configuration;
8
use Doctrine\ORM\EntityManager;
9
use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver;
10
use Thunder\Platenum\Doctrine\PlatenumDoctrineType;
11
use Thunder\Platenum\Tests\Fake\DoctrineEntity;
12
use Thunder\Platenum\Tests\Fake\DoctrineIntEnum;
13
use Thunder\Platenum\Tests\Fake\DoctrineStringEnum;
14
15
/**
16
 * @author Tomasz Kowalczyk <[email protected]>
17
 */
18
final class DoctrineTest extends AbstractTestCase
19
{
20
    public function testCreateFromMember(): void
21
    {
22
        $connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'dbname' => ':memory:']);
23
        $connection->exec('CREATE TABLE doctrine_entity (
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Connection::exec() has been deprecated: Use {@link executeStatement()} instead. ( Ignorable by Annotation )

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

23
        /** @scrutinizer ignore-deprecated */ $connection->exec('CREATE TABLE doctrine_entity (

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
24
            id INTEGER NOT NULL PRIMARY KEY,
25
            int_value INTEGER NOT NULL,
26
            string_value VARCHAR(20) NOT NULL,
27
            nullable_value VARCHAR(20) NULL
28
        )');
29
        $configuration = new Configuration();
30
        $configuration->setMetadataDriverImpl(new StaticPHPDriver([__DIR__.'/Fake']));
31
        $configuration->setProxyDir(__DIR__.'/../var/doctrine');
32
        $configuration->setProxyNamespace('Platenum\\Doctrine');
33
34
        PlatenumDoctrineType::registerInteger('intEnum', DoctrineIntEnum::class);
35
        PlatenumDoctrineType::registerString('stringEnum', DoctrineStringEnum::class);
36
37
        $entity = new DoctrineEntity(1337, DoctrineIntEnum::FIRST(), DoctrineStringEnum::TWO());
38
        $em = EntityManager::create($connection, $configuration);
39
        $em->persist($entity);
40
        $em->flush();
41
        $em->clear();
42
43
        $foundEntity = $em->find(DoctrineEntity::class, 1337);
44
        $this->assertInstanceOf(DoctrineEntity::class, $foundEntity);
45
        $this->assertSame($entity->getId(), $foundEntity->getId());
46
        $this->assertSame($entity->getIntValue(), $foundEntity->getIntValue());
47
        $this->assertSame($entity->getStringValue(), $foundEntity->getStringValue());
48
        $this->assertNull($foundEntity->getNullableValue());
49
    }
50
51
    public function testDoctrineType(): void
52
    {
53
        PlatenumDoctrineType::registerInteger('intEnum0', DoctrineIntEnum::class);
54
        $intType = PlatenumDoctrineType::getType('intEnum0');
55
56
        $platform = new MySqlPlatform();
57
        $this->assertTrue($intType->requiresSQLCommentHint($platform));
58
        $this->assertSame('intEnum0', $intType->getName());
59
        $this->assertSame('INT', $intType->getSQLDeclaration([], $platform));
60
61
        PlatenumDoctrineType::registerString('stringEnum0', DoctrineStringEnum::class);
62
        $stringType = PlatenumDoctrineType::getType('stringEnum0');
63
        $this->assertSame('VARCHAR(255)', $stringType->getSQLDeclaration([], $platform));
64
    }
65
66
    public function testInvalidClass(): void
67
    {
68
        $this->expectException(\LogicException::class);
69
        $this->expectExceptionMessage('PlatenumDoctrineType allows only Platenum enumerations, `stdClass` given.');
70
        PlatenumDoctrineType::registerInteger('invalid', \stdClass::class);
71
    }
72
73
    public function testDuplicateAlias(): void
74
    {
75
        PlatenumDoctrineType::registerString('enumX', DoctrineIntEnum::class);
76
77
        $this->expectException(\LogicException::class);
78
        $this->expectExceptionMessage('Alias `'.DoctrineIntEnum::class.'` was already registered in PlatenumDoctrineType.');
79
        PlatenumDoctrineType::registerString('enumX', DoctrineIntEnum::class);
80
    }
81
82
    public function testImpossibleDatabaseConversionWithUnsupportedValue(): void
83
    {
84
        PlatenumDoctrineType::registerString('impossibleEnumConvert', DoctrineIntEnum::class);
85
        $this->expectException(\LogicException::class);
86
        PlatenumDoctrineType::getType('impossibleEnumConvert')->convertToDatabaseValue('not an object', new MySqlPlatform());
87
    }
88
89
    public function testImpossibleValueConversionCast(): void
90
    {
91
        PlatenumDoctrineType::registerString('impossibleEnumCast', DoctrineIntEnum::class);
92
        $result = PlatenumDoctrineType::getType('impossibleEnumCast')->convertToDatabaseValue(DoctrineIntEnum::FIRST(), new MySqlPlatform());
93
        $this->assertSame('1', $result, $result);
94
    }
95
}
96