Skip to content

Commit 21f5d1b

Browse files
committed
test: add functional
1 parent 69fa1d6 commit 21f5d1b

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Doctrine\ORM\Mapping\Id;
1212
use Doctrine\ORM\Mapping\JoinColumn;
1313
use Doctrine\ORM\Mapping\ManyToOne;
14+
use Doctrine\ORM\Mapping\OneToOne;
1415
use Doctrine\ORM\Mapping\Table;
1516
use Doctrine\Tests\OrmFunctionalTestCase;
1617
use PHPUnit\Framework\Attributes\Group;
@@ -42,6 +43,60 @@ public function testUpdateSchemaWithPostgreSQLSchema(): void
4243

4344
self::assertCount(0, $sql, implode("\n", $sql));
4445
}
46+
47+
public function testUpdateSchemaWithJoinColumnWithOptions(): void
48+
{
49+
$sql = $this->getUpdateSchemaSqlForModels(
50+
TestEntityWithJoinColumnWithOptions::class,
51+
TestEntityWithJoinColumnWithOptionsRelation::class,
52+
);
53+
54+
$this->assertSame([
55+
'CREATE TABLE test (id INT NOT NULL, testRelation1_id INT DEFAULT NULL, testRelation2_id INT DEFAULT NULL, PRIMARY KEY(id))',
56+
'CREATE UNIQUE INDEX UNIQ_D87F7E0C331521C6 ON test (testRelation1_id)',
57+
'CREATE UNIQUE INDEX UNIQ_D87F7E0C21A08E28 ON test (testRelation2_id)',
58+
'CREATE TABLE test_relation (id INT NOT NULL, PRIMARY KEY(id))',
59+
'ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C331521C6 FOREIGN KEY (testRelation1_id) REFERENCES test_relation (id) DEFERRABLE INITIALLY DEFERRED',
60+
'ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C21A08E28 FOREIGN KEY (testRelation2_id) REFERENCES test_relation (id) NOT DEFERRABLE INITIALLY IMMEDIATE',
61+
], $sql);
62+
63+
foreach ($sql as $query) {
64+
$this->_em->getConnection()->executeQuery($query);
65+
}
66+
67+
$sql = $this->getUpdateSchemaSqlForModels(
68+
TestEntityWithJoinColumnWithOptions::class,
69+
TestEntityWithJoinColumnWithOptionsRelation::class,
70+
);
71+
72+
$this->assertSame([], $sql);
73+
}
74+
}
75+
76+
#[Table('test')]
77+
#[Entity]
78+
class TestEntityWithJoinColumnWithOptions
79+
{
80+
#[Id]
81+
#[Column]
82+
private int $id;
83+
84+
#[OneToOne(targetEntity: TestEntityWithJoinColumnWithOptionsRelation::class)]
85+
#[JoinColumn(options: ['deferrable' => true, 'deferred' => true])]
86+
private TestEntityWithJoinColumnWithOptionsRelation $testRelation1;
87+
88+
#[OneToOne(targetEntity: TestEntityWithJoinColumnWithOptionsRelation::class)]
89+
#[JoinColumn]
90+
private TestEntityWithJoinColumnWithOptionsRelation $testRelation2;
91+
}
92+
93+
#[Table('test_relation')]
94+
#[Entity]
95+
class TestEntityWithJoinColumnWithOptionsRelation
96+
{
97+
#[Id]
98+
#[Column]
99+
private int $id;
45100
}
46101

47102
#[Table(name: 'stonewood.screen')]

0 commit comments

Comments
 (0)