Skip to content

Commit 69fa1d6

Browse files
committed
test: add test for sql result
1 parent 39d3102 commit 69fa1d6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tests/Tests/ORM/Tools/SchemaToolTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\Tests\ORM\Tools;
66

77
use Doctrine\Common\Collections\Collection;
8+
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
89
use Doctrine\ORM\Mapping\ClassMetadata;
910
use Doctrine\ORM\Mapping\Column;
1011
use Doctrine\ORM\Mapping\Entity;
@@ -404,7 +405,13 @@ public function testJoinColumnWithOptions(): void
404405

405406
$schema = $schemaTool->getSchemaFromMetadata($classes);
406407

407-
self::assertSame(['deferrable' => true, 'deferred' => true], $schema->getTable('test')->getForeignKey('FK_D87F7E0C1E5D0459')->getOptions());
408+
self::assertSame(['deferrable' => true, 'deferred' => true], $schema->getTable('test')->getForeignKey('FK_D87F7E0C331521C6')->getOptions());
409+
self::assertSame([], $schema->getTable('test')->getForeignKey('FK_D87F7E0C21A08E28')->getOptions());
410+
411+
$sql = $schema->toSql(new PostgreSQLPlatform());
412+
413+
$this->assertSame('ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C331521C6 FOREIGN KEY (testRelation1_id) REFERENCES test_relation (id) DEFERRABLE INITIALLY DEFERRED', $sql[count($sql) - 2]);
414+
$this->assertSame('ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C21A08E28 FOREIGN KEY (testRelation2_id) REFERENCES test_relation (id) NOT DEFERRABLE INITIALLY IMMEDIATE', $sql[count($sql) - 1]);
408415
}
409416
}
410417

@@ -418,9 +425,14 @@ class TestEntityWithJoinColumnWithOptions
418425

419426
#[OneToOne(targetEntity: TestEntityWithJoinColumnWithOptionsRelation::class)]
420427
#[JoinColumn(options: ['deferrable' => true, 'deferred' => true])]
421-
private TestEntityWithJoinColumnWithOptionsRelation $test;
428+
private TestEntityWithJoinColumnWithOptionsRelation $testRelation1;
429+
430+
#[OneToOne(targetEntity: TestEntityWithJoinColumnWithOptionsRelation::class)]
431+
#[JoinColumn]
432+
private TestEntityWithJoinColumnWithOptionsRelation $testRelation2;
422433
}
423434

435+
#[Table('test_relation')]
424436
#[Entity]
425437
class TestEntityWithJoinColumnWithOptionsRelation
426438
{

0 commit comments

Comments
 (0)