-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting column options like
charset
and collation
everywhere
This makes it possible to set custom options on the following: * `JoinTable` * `JoinColumn` * `InverseJoinColumn`
- Loading branch information
Showing
10 changed files
with
271 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
tests/Doctrine/Tests/ORM/Functional/Ticket/GH6823Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<?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 | ||
); | ||
|
||
self::assertEquals('CREATE TABLE gh6823_user (id VARCHAR(255) NOT NULL, group_id VARCHAR(255) CHARACTER SET ascii DEFAULT NULL COLLATE `ascii_general_ci`, status_id VARCHAR(255) CHARACTER SET latin1 DEFAULT NULL COLLATE `latin1_bin`, INDEX IDX_70DD1774FE54D947 (group_id), INDEX IDX_70DD17746BF700BD (status_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_bin` ENGINE = InnoDB', $this->getLastLoggedQuery(6)['sql']); | ||
self::assertEquals('CREATE TABLE gh6823_user_tags (user_id VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_bin`, tag_id VARCHAR(255) CHARACTER SET latin1 NOT NULL COLLATE `latin1_bin`, INDEX IDX_596B1281A76ED395 (user_id), INDEX IDX_596B1281BAD26311 (tag_id), PRIMARY KEY(user_id, tag_id)) DEFAULT CHARACTER SET ascii COLLATE `ascii_general_ci` ENGINE = InnoDB', $this->getLastLoggedQuery(5)['sql']); | ||
self::assertEquals('CREATE TABLE gh6823_group (id VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET ascii COLLATE `ascii_general_ci` ENGINE = InnoDB', $this->getLastLoggedQuery(4)['sql']); | ||
self::assertEquals('CREATE TABLE gh6823_status (id VARCHAR(255) CHARACTER SET latin1 NOT NULL COLLATE `latin1_bin`, PRIMARY KEY(id)) DEFAULT CHARACTER SET koi8r COLLATE `koi8r_bin` ENGINE = InnoDB', $this->getLastLoggedQuery(3)['sql']); | ||
self::assertEquals('ALTER TABLE gh6823_user ADD CONSTRAINT FK_70DD1774FE54D947 FOREIGN KEY (group_id) REFERENCES gh6823_group (id)', $this->getLastLoggedQuery(2)['sql']); | ||
self::assertEquals('ALTER TABLE gh6823_user ADD CONSTRAINT FK_70DD17746BF700BD FOREIGN KEY (status_id) REFERENCES gh6823_status (id)', $this->getLastLoggedQuery(1)['sql']); | ||
self::assertEquals('ALTER TABLE gh6823_user_tags ADD CONSTRAINT FK_596B1281A76ED395 FOREIGN KEY (user_id) REFERENCES gh6823_user (id)', $this->getLastLoggedQuery(0)['sql']); | ||
} | ||
} | ||
|
||
/** | ||
* @Entity | ||
* @Table(name="gh6823_user", options={ | ||
* "charset"="utf8mb4", | ||
* "collation"="utf8mb4_bin" | ||
* }) | ||
*/ | ||
class GH6823User | ||
{ | ||
/** | ||
* @var string | ||
* @Id | ||
* @Column(type="string") | ||
*/ | ||
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") | ||
*/ | ||
public $id; | ||
} | ||
|
||
/** | ||
* @Entity | ||
* @Table(name="gh6823_status", options={ | ||
* "charset"="koi8r", | ||
* "collation"="koi8r_bin" | ||
* }) | ||
*/ | ||
class GH6823Status | ||
{ | ||
/** | ||
* @var string | ||
* @Id | ||
* @Column(type="string", 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", options={"charset"="latin1", "collation"="latin1_bin"}) | ||
*/ | ||
public $id; | ||
} |
Oops, something went wrong.