File: GH11982Test.php

package info (click to toggle)
doctrine 3.5.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,556 kB
  • sloc: php: 108,620; xml: 1,340; makefile: 35; sh: 14
file content (99 lines) | stat: -rw-r--r-- 2,787 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Index;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;

use function method_exists;
use function reset;

class GH11982Test extends OrmFunctionalTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->setUpEntitySchema([
            GH11982ColumnIndex::class,
        ]);
    }

    #[Group('GH-11982')]
    public function testSchema(): void
    {
        if ($this->_em->getConnection()->getDatabasePlatform() instanceof PostgreSQLPlatform) {
            self::markTestSkipped('This test does not work on psql.');
        }

        if (! method_exists(Index::class, 'getIndexedColumns')) {
            self::markTestSkipped('This test requires doctrine/dbal >=4.3');
        }

        $indexes = $this->createSchemaManager()
            ->introspectTable('GH11982ColumnIndex')
            ->getIndexes();

        self::assertCount(3, $indexes); // primary + 2 custom indexes
        self::assertArrayHasKey('class_idx', $indexes);

        unset($indexes['primary']);
        unset($indexes['class_idx']);
        $unnamedIndexColumns = reset($indexes)->getIndexedColumns();
        self::assertCount(1, $unnamedIndexColumns);
        self::assertEquals(
            'indexTrue',
            $unnamedIndexColumns[0]->getColumnName()->toString(),
        );
    }

    #[Group('GH-11982')]
    public function testSchemaLegacyDbal(): void
    {
        if ($this->_em->getConnection()->getDatabasePlatform() instanceof PostgreSQLPlatform) {
            self::markTestSkipped('This test does not work on psql.');
        }

        if (method_exists(Index::class, 'getIndexedColumns')) {
            self::markTestSkipped('This test requires doctrine/dbal <4.3');
        }

        $indexes = $this->createSchemaManager()
            ->introspectTable('GH11982ColumnIndex')
            ->getIndexes();

        self::assertCount(3, $indexes); // primary + 2 custom indexes
        self::assertArrayHasKey('class_idx', $indexes);

        unset($indexes['primary']);
        unset($indexes['class_idx']);
        $unnamedIndexColumns = reset($indexes)->getColumns();
        self::assertCount(1, $unnamedIndexColumns);
        self::assertEquals('indexTrue', $unnamedIndexColumns[0]);
    }
}

#[ORM\Entity]
#[ORM\Index(
    name: 'class_idx',
    fields: ['classIndex'],
    flags: ['fulltext'],
    options: ['test'],
)]
class GH11982ColumnIndex
{
    #[ORM\Id]
    #[ORM\Column]
    public string $noIndex;

    #[ORM\Column(index: true)]
    public string $indexTrue;

    #[ORM\Column]
    public string $classIndex;
}