Skip to content

Commit 78c8cdb

Browse files
committed
tests: make 100% lines code coverage
1 parent 58553cf commit 78c8cdb

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

tests/MigrationGeneratorTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace RonasIT\Support\Tests;
44

55
use Illuminate\Support\Carbon;
6+
use Illuminate\Support\Facades\Config;
67
use RonasIT\Support\Exceptions\UnknownFieldTypeException;
78
use RonasIT\Support\Generators\MigrationGenerator;
89

@@ -72,9 +73,35 @@ public function testCreateMigrationMYSQL()
7273
'string' => ['title', 'body'],
7374
'json' => ['meta'],
7475
'timestamp' => ['created_at'],
76+
'timestamp-required' => ['published_at'],
7577
])
7678
->generate();
7779

7880
$this->assertGeneratedFileEquals('migrations_mysql.php', 'database/migrations/2022_02_02_000000_posts_create_table.php');
7981
}
82+
83+
public function testCreateMigrationWithoutMigrationStub(): void
84+
{
85+
Carbon::setTestNow('2022-02-02');
86+
87+
Config::set('entity-generator.stubs.migration');
88+
89+
$result = app(MigrationGenerator::class)
90+
->setModel('Post')
91+
->setRelations([
92+
'belongsTo' => [],
93+
'belongsToMany' => [],
94+
'hasOne' => [],
95+
'hasMany' => [],
96+
])
97+
->setFields([
98+
'integer-required' => ['media_id', 'user_id'],
99+
'string' => ['title', 'body'],
100+
'json' => ['meta'],
101+
'timestamp' => ['created_at'],
102+
])
103+
->generate();
104+
105+
$this->assertNull($result);
106+
}
80107
}

tests/fixtures/MigrationGeneratorTest/migrations_mysql.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function up(): void
1919
$table->string('body')->nullable();
2020
$table->json('meta')->nullable();
2121
$table->timestamp('created_at')->nullable();
22+
$table->timestamp('published_at')->nullable();
2223
$table->timestamps();
2324
});
2425
}

0 commit comments

Comments
 (0)