Skip to content

Commit b9e07b9

Browse files
committed
Add traits test to MySQLComparatorTest
1 parent ae6314e commit b9e07b9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/Providers/MySQL/MySQLComparatorTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Composite\Entity\AbstractEntity;
1616
use Composite\Sync\Attributes\Index;
1717
use Composite\Sync\Tests\TestStand\Entities;
18+
use Composite\DB\Traits;
1819

1920
final class MySQLComparatorTest extends \PHPUnit\Framework\TestCase
2021
{
@@ -61,6 +62,18 @@ public function __construct(
6162
) {}
6263
};
6364

65+
$traitsEntity = new
66+
#[Table(connection: 'mysql', name: 'Traits')]
67+
class('a') extends AbstractEntity {
68+
use Traits\UpdatedAt;
69+
use Traits\SoftDelete;
70+
71+
public function __construct(
72+
#[PrimaryKey]
73+
public readonly string $id,
74+
) {}
75+
};
76+
6477
return [
6578
[
6679
'entity' => $simpleEntity,
@@ -567,6 +580,28 @@ public function __construct(
567580
'expectedUpQueries' => [],
568581
'expectedDownQueries' => [],
569582
],
583+
[
584+
'entity' => $traitsEntity,
585+
'sql' => null,
586+
'expectedNewColumns' => ['id', 'updated_at', 'deleted_at'],
587+
'expectedChangedColumns' => [],
588+
'expectedNewIndexes' => [],
589+
'expectedDeletedIndexes' => [],
590+
'expectedPrimaryKeyChanged' => false,
591+
'expectedUpQueries' => [
592+
<<<SQL
593+
CREATE TABLE `Traits` (
594+
`id` VARCHAR(255) NOT NULL,
595+
`updated_at` TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
596+
`deleted_at` TIMESTAMP(6) NULL DEFAULT NULL,
597+
PRIMARY KEY (`id`)
598+
) ENGINE=InnoDB COLLATE=utf8mb4_unicode_ci;
599+
SQL,
600+
],
601+
'expectedDownQueries' => [
602+
'DROP TABLE IF EXISTS `Traits`;'
603+
],
604+
],
570605
];
571606
}
572607

0 commit comments

Comments
 (0)