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
Push — master ( 204364...f34ae5 )
by Tomasz
05:54
created

DoctrineTest::testInheritance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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

26
        /** @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...
27
            id INTEGER NOT NULL PRIMARY KEY,
28
            int_value INTEGER NOT NULL,
29
            string_value VARCHAR(20) NOT NULL,
30
            nullable_value VARCHAR(20) NULL
31
        )');
32
        $configuration = new Configuration();
33
        $configuration->setMetadataDriverImpl(new StaticPHPDriver([__DIR__.'/Fake']));
34
        $configuration->setProxyDir(__DIR__.'/../var/doctrine');
35
        $configuration->setProxyNamespace('Platenum\\Doctrine');
36
37
        PlatenumDoctrineType::registerInteger('intEnum', DoctrineIntEnum::class);
38
        PlatenumDoctrineType::registerString('stringEnum', DoctrineStringEnum::class);
39
40
        $entity = new DoctrineEntity(1337, DoctrineIntEnum::FIRST(), DoctrineStringEnum::TWO());
41
        $em = EntityManager::create($connection, $configuration);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::create() has been deprecated: Use {@see DriverManager::getConnection()} to bootstrap the connection and call the constructor. ( Ignorable by Annotation )

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

41
        $em = /** @scrutinizer ignore-deprecated */ EntityManager::create($connection, $configuration);

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...
42
        $em->persist($entity);
43
        $em->flush();
44
        $em->clear();
45
46
        $foundEntity = $em->find(DoctrineEntity::class, 1337);
47
        $this->assertInstanceOf(DoctrineEntity::class, $foundEntity);
48
        $this->assertSame($entity->getId(), $foundEntity->getId());
49
        $this->assertSame($entity->getIntValue(), $foundEntity->getIntValue());
50
        $this->assertSame($entity->getStringValue(), $foundEntity->getStringValue());
51
        $this->assertNull($foundEntity->getNullableValue());
52
    }
53
54
    public function testDoctrineType(): void
55
    {
56
        PlatenumDoctrineType::registerInteger('intEnum0', DoctrineIntEnum::class);
57
        $intType = PlatenumDoctrineType::getType('intEnum0');
58
59
        $platform = new MySQL80Platform();
60
        $this->assertTrue($intType->requiresSQLCommentHint($platform));
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Types\Type::requiresSQLCommentHint() has been deprecated. ( Ignorable by Annotation )

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

60
        $this->assertTrue(/** @scrutinizer ignore-deprecated */ $intType->requiresSQLCommentHint($platform));
Loading history...
61
        $this->assertSame('intEnum0', $intType->getName());
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Types\Type::getName() has been deprecated: this method will be removed in Doctrine DBAL 4.0, use {@see TypeRegistry::lookupName()} instead. ( Ignorable by Annotation )

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

61
        $this->assertSame('intEnum0', /** @scrutinizer ignore-deprecated */ $intType->getName());

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...
62
        $this->assertSame('INT', $intType->getSQLDeclaration([], $platform));
63
64
        PlatenumDoctrineType::registerString('stringEnum0', DoctrineStringEnum::class);
65
        $stringType = PlatenumDoctrineType::getType('stringEnum0');
66
        $this->assertSame('VARCHAR(255)', $stringType->getSQLDeclaration([], $platform));
67
    }
68
69
    public function testInvalidClass(): void
70
    {
71
        $this->expectException(\LogicException::class);
72
        $this->expectExceptionMessage('PlatenumDoctrineType allows only Platenum enumerations, `stdClass` given.');
73
        PlatenumDoctrineType::registerInteger('invalid', \stdClass::class);
74
    }
75
76
    public function testDuplicateAlias(): void
77
    {
78
        PlatenumDoctrineType::registerString('enumX', DoctrineIntEnum::class);
79
80
        $this->expectException(\LogicException::class);
81
        $this->expectExceptionMessage('Alias `'.DoctrineIntEnum::class.'` was already registered in PlatenumDoctrineType.');
82
        PlatenumDoctrineType::registerString('enumX', DoctrineIntEnum::class);
83
    }
84
85
    public function testImpossibleDatabaseConversionWithUnsupportedValue(): void
86
    {
87
        PlatenumDoctrineType::registerString('impossibleEnumConvert', DoctrineIntEnum::class);
88
        $this->expectException(\LogicException::class);
89
        PlatenumDoctrineType::getType('impossibleEnumConvert')->convertToDatabaseValue('not an object', new MySql80Platform());
90
    }
91
92
    public function testImpossibleValueConversionCast(): void
93
    {
94
        PlatenumDoctrineType::registerString('impossibleEnumCast', DoctrineIntEnum::class);
95
        $result = PlatenumDoctrineType::getType('impossibleEnumCast')->convertToDatabaseValue(DoctrineIntEnum::FIRST(), new MySql80Platform());
96
        $this->assertSame('1', $result, $result);
97
    }
98
99
    public function testNoTrait(): void
100
    {
101
        $this->expectException(\LogicException::class);
102
        $this->expectExceptionMessage('PlatenumDoctrineType allows only Platenum enumerations, `'.NoTraitEnum::class.'` given.');
103
        PlatenumDoctrineType::registerString('noTraitEnum', NoTraitEnum::class);
104
    }
105
106
    public function testInheritance(): void
107
    {
108
        PlatenumDoctrineType::registerString('doctrineExtendsEnum', DoctrineExtendsEnum::class);
109
        $this->assertTrue(true);
110
    }
111
}
112