Skip to content

Commit 68d9d21

Browse files
authored
Merge pull request #24 from yabhq/feat/uuid-column-name
Add test case for UUID column models
2 parents bd7793d + 2a69a46 commit 68d9d21

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Yab\Mint\Tests\Factories;
4+
5+
use Yab\Mint\Tests\Models\UuidColumnModel;
6+
7+
$factory->define(UuidColumnModel::class, function () {
8+
return [];
9+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateUuidColumnModelsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('uuid_column_models', function (Blueprint $table) {
17+
$table->string('uuid');
18+
$table->timestamps();
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*
25+
* @return void
26+
*/
27+
public function down()
28+
{
29+
Schema::dropIfExists('uuid_models');
30+
}
31+
}

tests/Models/UuidColumnModel.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Yab\Mint\Tests\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Yab\Mint\Traits\UuidModel as UuidModelTrait;
7+
8+
class UuidColumnModel extends Model
9+
{
10+
use UuidModelTrait;
11+
12+
/**
13+
* Set the UUID column name for the model.
14+
*
15+
* @return string
16+
*/
17+
public static function getUuidColumnName(): string
18+
{
19+
return 'uuid';
20+
}
21+
}

tests/UuidTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Ramsey\Uuid\Uuid;
66
use Yab\Mint\Tests\TestCase;
77
use Yab\Mint\Tests\Models\UuidModel;
8+
use Yab\Mint\Tests\Models\UuidColumnModel;
89

910
class UuidTest extends TestCase
1011
{
@@ -36,4 +37,16 @@ public function the_uuid_of_a_model_can_not_be_altered()
3637
'id' => $originalId,
3738
]);
3839
}
40+
41+
/** @test */
42+
public function the_uuid_column_name_can_be_customized_on_the_model()
43+
{
44+
$model = factory(UuidColumnModel::class)->create();
45+
46+
$this->assertTrue(Uuid::isValid($model->uuid));
47+
48+
$this->assertDatabaseHas('uuid_column_models', [
49+
'uuid' => $model->uuid,
50+
]);
51+
}
3952
}

0 commit comments

Comments
 (0)