Skip to content

Commit e50bc8a

Browse files
committed
tests added.
1 parent ee434a7 commit e50bc8a

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Generator\Compiler\Mapper;
6+
7+
use N3XT0R\MigrationGenerator\Service\Generator\Compiler\Mapper\PrimaryKeyMapper;
8+
use N3XT0R\MigrationGenerator\Service\Generator\Definition\Entity\IndexEntity;
9+
use N3XT0R\MigrationGenerator\Service\Generator\Definition\Entity\PrimaryKeyEntity;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class PrimaryKeyMapperTest extends TestCase
13+
{
14+
protected PrimaryKeyMapper $mapper;
15+
16+
public function setUp(): void
17+
{
18+
parent::setUp();
19+
$this->mapper = new PrimaryKeyMapper();
20+
}
21+
22+
public function testMapPrimaryKeysWorks(): void
23+
{
24+
$this->assertCount(1, $this->mapper->map([new PrimaryKeyEntity()]));
25+
}
26+
27+
public function testMapNotPrimaryKeysNotWorks(): void
28+
{
29+
$this->assertCount(0, $this->mapper->map([new IndexEntity()]));
30+
}
31+
32+
public function testMapCombinedPrimaryKeyWorks(): void
33+
{
34+
$pk = new PrimaryKeyEntity();
35+
$pk->setName('combined');
36+
$pk->setColumns(['id', 'role_id']);
37+
$result = $this->mapper->map([$pk]);
38+
$this->assertStringContainsString("\$table->primary(['id', 'role_id'], 'combined');", $result[0]);
39+
}
40+
41+
public function testMapSingleNamedPrimaryKeyWorks(): void
42+
{
43+
$pk = new PrimaryKeyEntity();
44+
$pk->setName('PRIMARY');
45+
$pk->setColumns(['id']);
46+
$result = $this->mapper->map([$pk]);
47+
$this->assertStringContainsString("\$table->primary(['id'], 'PRIMARY');", $result[0]);
48+
}
49+
50+
public function testMapSingleNotNamedPrimaryKeyWorks(): void
51+
{
52+
$pk = new PrimaryKeyEntity();
53+
$pk->setColumns(['id']);
54+
$result = $this->mapper->map([$pk]);
55+
$this->assertStringContainsString("\$table->primary(['id']);", $result[0]);
56+
}
57+
}

0 commit comments

Comments
 (0)