packages/sql-fixture/tests/Unit/Plan/RelationKindTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Plan;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Test;
9use PHPUnit\Framework\Attributes\UsesClass;
10use PHPUnit\Framework\TestCase;
11use SqlFixture\Plan\RelationKind;
12use SqlFixture\Plan\RelationSide;
13
14#[CoversClass(RelationKind::class)]
15#[UsesClass(RelationSide::class)]
16final class RelationKindTest extends TestCase
17{
18 #[Test]
19 public function testEachCaseIsSpeltAsItsDbmlOperator(): void
20 {
21 self::assertSame('<', RelationKind::OneToMany->value);
22 self::assertSame('>', RelationKind::ManyToOne->value);
23 self::assertSame('-', RelationKind::OneToOne->value);
24 }
25
26 #[Test]
27 public function testManyToManyIsNotAnOperator(): void
28 {
29 $operators = array_map(
30 static fn (RelationKind $kind): string => $kind->value,
31 RelationKind::cases()
32 );
33
34 self::assertSame(['<', '>', '-'], $operators);
35 }
36
37 #[Test]
38 public function testParentSideOneToManyPutsTheParentOnTheLeft(): void
39 {
40 self::assertSame(RelationSide::Left, RelationKind::OneToMany->parentSide());
41 self::assertSame(RelationSide::Right, RelationKind::OneToMany->childSide());
42 }
43
44 #[Test]
45 public function testChildSideManyToOnePutsTheParentOnTheRight(): void
46 {
47 self::assertSame(RelationSide::Right, RelationKind::ManyToOne->parentSide());
48 self::assertSame(RelationSide::Left, RelationKind::ManyToOne->childSide());
49 }
50
51 #[Test]
52 public function testOneToOnePutsTheParentOnTheLeft(): void
53 {
54 self::assertSame(RelationSide::Left, RelationKind::OneToOne->parentSide());
55 self::assertSame(RelationSide::Right, RelationKind::OneToOne->childSide());
56 }
57
58 #[Test]
59 public function testChildIsCollectionOnlyOneToOneHoldsASingleChildRow(): void
60 {
61 self::assertTrue(RelationKind::OneToMany->childIsCollection());
62 self::assertTrue(RelationKind::ManyToOne->childIsCollection());
63 self::assertFalse(RelationKind::OneToOne->childIsCollection());
64 }
65}
66