Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Generators/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ protected function getCasts(array $fields): array
$casts = [
'boolean-required' => 'boolean',
'boolean' => 'boolean',
'json' => 'array'
'json' => 'array',
'timestamp-required' => 'datetime',
'timestamp' => 'datetime'
];

$result = [];
Expand Down
16 changes: 16 additions & 0 deletions tests/ModelGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public function testCreateModel()
->setFields([
'integer-required' => ['media_id'],
'boolean-required' => ['is_published'],
'timestamp' => ['reviewed_at'],
'timestamp-required' => ['published_at'],
])
->setRelations(new RelationsDTO(
hasOne: ['Comment'],
Expand Down Expand Up @@ -98,6 +100,20 @@ className: WarningEvent::class,
);
}

public function testModelGeneratedByArtisan()
{
$this
->artisan('make:entity Post -S name -t reviewed_at -T publiched_at --only-model')
->assertSuccessful();

$this->assertGeneratedFileEquals('generated_model.php', 'app/Models/Post.php');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use the same fixture here

Suggested change
$this->assertGeneratedFileEquals('generated_model.php', 'app/Models/Post.php');
$this->assertGeneratedFileEquals('new_model.php', 'app/Models/Post.php');


$this->assertEventPushed(
className: SuccessCreateMessage::class,
message: 'Created a new Model: Post',
);
}

public function testCreateModelWithoutRelationsRelationStubNotExist()
{
config(['entity-generator.stubs.relation' => 'incorrect_stub']);
Expand Down
24 changes: 24 additions & 0 deletions tests/fixtures/ModelGeneratorTest/generated_model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use RonasIT\Support\Traits\ModelTrait;

class Post extends Model
{
use ModelTrait;

protected $fillable = [
'name',
'reviewed_at',
'publiched_at',
];

protected $hidden = ['pivot'];

protected $casts = [
'reviewed_at' => 'datetime',
'publiched_at' => 'datetime',
];
}
4 changes: 4 additions & 0 deletions tests/fixtures/ModelGeneratorTest/new_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ class Post extends Model
protected $fillable = [
'media_id',
'is_published',
'reviewed_at',
'published_at',
];

protected $hidden = ['pivot'];

protected $casts = [
'is_published' => 'boolean',
'reviewed_at' => 'datetime',
'published_at' => 'datetime',
];

public function comment()
Expand Down