Skip to content

Commit 6dfe0f3

Browse files
committed
test: add functional
1 parent 69fa1d6 commit 6dfe0f3

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
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;
1718

1819
use function array_filter;
20+
use function array_slice;
1921
use function implode;
2022
use function str_starts_with;
2123

@@ -42,6 +44,60 @@ public function testUpdateSchemaWithPostgreSQLSchema(): void
4244

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

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

0 commit comments

Comments
 (0)