Skip to content

Commit

Permalink
test: add test for sql result
Browse files Browse the repository at this point in the history
  • Loading branch information
vencakrecl committed Jun 18, 2024
1 parent 2f0756c commit f68b5e3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tests/Tests/ORM/Tools/SchemaToolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Tests\ORM\Tools;

use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
Expand Down Expand Up @@ -404,7 +405,13 @@ public function testJoinColumnWithOptions(): void

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

self::assertSame(['deferrable' => true, 'deferred' => true], $schema->getTable('test')->getForeignKey('FK_D87F7E0C1E5D0459')->getOptions());
self::assertSame(['deferrable' => true, 'deferred' => true], $schema->getTable('test')->getForeignKey('FK_D87F7E0C331521C6')->getOptions());
self::assertSame([], $schema->getTable('test')->getForeignKey('FK_D87F7E0C21A08E28')->getOptions());

$sql = $schema->toSql(new PostgreSQLPlatform());

$this->assertSame('ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C331521C6 FOREIGN KEY (testRelation1_id) REFERENCES test_relation (id) DEFERRABLE INITIALLY DEFERRED', $sql[count($sql) - 2]);
$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]);
}
}

Expand All @@ -418,9 +425,14 @@ class TestEntityWithJoinColumnWithOptions

#[OneToOne(targetEntity: TestEntityWithJoinColumnWithOptionsRelation::class)]
#[JoinColumn(options: ['deferrable' => true, 'deferred' => true])]
private TestEntityWithJoinColumnWithOptionsRelation $test;
private TestEntityWithJoinColumnWithOptionsRelation $testRelation1;

#[OneToOne(targetEntity: TestEntityWithJoinColumnWithOptionsRelation::class)]
#[JoinColumn]
private TestEntityWithJoinColumnWithOptionsRelation $testRelation2;
}

#[Table('test_relation')]
#[Entity]
class TestEntityWithJoinColumnWithOptionsRelation
{
Expand Down

0 comments on commit f68b5e3

Please sign in to comment.