File: GH6823Test.php

package info (click to toggle)
doctrine 2.14.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,612 kB
  • sloc: php: 113,660; xml: 4,630; makefile: 28; sh: 14
file content (158 lines) | stat: -rw-r--r-- 5,023 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\JoinTable;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\Table;
use Doctrine\Tests\OrmFunctionalTestCase;

use function method_exists;

class GH6823Test extends OrmFunctionalTestCase
{
    public function testCharsetCollationWhenCreatingForeignRelations(): void
    {
        if (! $this->_em->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) {
            self::markTestSkipped('This test is useful for all databases, but designed only for mysql.');
        }

        if (method_exists(AbstractPlatform::class, 'getGuidExpression')) {
            self::markTestSkipped('Test valid for doctrine/dbal:3.x only.');
        }

        $this->createSchemaForModels(
            GH6823User::class,
            GH6823Group::class,
            GH6823Status::class
        );

        $schemaManager = $this->createSchemaManager();
        /* gh6823_user.group_id should use charset ascii and collation
         * ascii_general_ci, because that is what gh6823_group.id falls back to */
        $userGroupIdOptions = $schemaManager->listTableDetails('gh6823_user')->getColumn('group_id')->toArray();
        self::assertSame('ascii', $userGroupIdOptions['charset']);
        self::assertSame('ascii_general_ci', $userGroupIdOptions['collation']);

        /* gh6823_user.status_id should use charset latin1 and collation
         * latin1_bin, because that is what gh6823_status.id uses */
        $userStatusIdOptions = $schemaManager->listTableDetails('gh6823_user')->getColumn('status_id')->toArray();
        self::assertSame('latin1', $userStatusIdOptions['charset']);
        self::assertSame('latin1_bin', $userStatusIdOptions['collation']);

        /* gh6823_user_tags.user_id should use charset utf8mb4 and collation
         * utf8mb4_bin, because that is what gh6823_user.id falls back to */
        $userTagsUserIdOptions = $schemaManager->listTableDetails('gh6823_user_tags')->getColumn('user_id')->toArray();
        self::assertSame('utf8mb4', $userTagsUserIdOptions['charset']);
        self::assertSame('utf8mb4_bin', $userTagsUserIdOptions['collation']);

        /* gh6823_user_tags.tag_id should use charset latin1 and collation
         * latin1_bin, because that is what gh6823_tag.id falls back to */
        $userTagsTagIdOption = $schemaManager->listTableDetails('gh6823_user_tags')->getColumn('tag_id')->toArray();
        self::assertSame('latin1', $userTagsTagIdOption['charset']);
        self::assertSame('latin1_bin', $userTagsTagIdOption['collation']);
    }
}

/**
 * @Entity
 * @Table(name="gh6823_user", options={
 *     "charset"="utf8mb4",
 *     "collation"="utf8mb4_bin"
 * })
 */
class GH6823User
{
    /**
     * @var string
     * @Id
     * @Column(type="string", length=255)
     */
    public $id;

    /**
     * @var GH6823Group
     * @ManyToOne(targetEntity="GH6823Group")
     * @JoinColumn(name="group_id", referencedColumnName="id", options={"charset"="ascii", "collation"="ascii_general_ci"})
     */
    public $group;

    /**
     * @var GH6823Status
     * @ManyToOne(targetEntity="GH6823Status")
     * @JoinColumn(name="status_id", referencedColumnName="id", options={"charset"="latin1", "collation"="latin1_bin"})
     */
    public $status;

    /**
     * @var Collection<int, GH6823Tag>
     * @ManyToMany(targetEntity="GH6823Tag")
     * @JoinTable(name="gh6823_user_tags", joinColumns={
     *   @JoinColumn(name="user_id", referencedColumnName="id", options={"charset"="utf8mb4", "collation"="utf8mb4_bin"})
     * }, inverseJoinColumns={
     *   @JoinColumn(name="tag_id", referencedColumnName="id", options={"charset"="latin1", "collation"="latin1_bin"})
     * }, options={"charset"="ascii", "collation"="ascii_general_ci"})
     */
    public $tags;
}

/**
 * @Entity
 * @Table(name="gh6823_group", options={
 *     "charset"="ascii",
 *     "collation"="ascii_general_ci"
 * })
 */
class GH6823Group
{
    /**
     * @var string
     * @Id
     * @Column(type="string", length=255)
     */
    public $id;
}

/**
 * @Entity
 * @Table(name="gh6823_status", options={
 *     "charset"="koi8r",
 *     "collation"="koi8r_bin"
 * })
 */
class GH6823Status
{
    /**
     * @var string
     * @Id
     * @Column(type="string", length=255, options={"charset"="latin1", "collation"="latin1_bin"})
     */
    public $id;
}

/**
 * @Entity
 * @Table(name="gh6823_tag", options={
 *     "charset"="koi8r",
 *     "collation"="koi8r_bin"
 * })
 */
class GH6823Tag
{
    /**
     * @var string
     * @Id
     * @Column(type="string", length=255, options={"charset"="latin1", "collation"="latin1_bin"})
     */
    public $id;
}