Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion src/Generators/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ function (Column $column) {
return $column->name();
},
array_filter($columns, function (Column $column) {
return stripos($column->dataType(), 'datetime') !== false
return $column->dataType() === 'date'
|| stripos($column->dataType(), 'datetime') !== false
|| stripos($column->dataType(), 'timestamp') !== false;
})
);
Expand Down
11 changes: 6 additions & 5 deletions tests/Feature/Generator/ModelGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function output_generates_models($definition, $path, $model)
->with('model.fillable.stub')
->andReturn(file_get_contents('stubs/model.fillable.stub'));

if (in_array($definition, ['drafts/nested-components.yaml','drafts/resource-statements.yaml'])) {
if (in_array($definition, ['drafts/nested-components.yaml', 'drafts/resource-statements.yaml'])) {
$this->files->expects('stub')
->with('model.hidden.stub')
->andReturn(file_get_contents('stubs/model.hidden.stub'));
Expand All @@ -66,7 +66,7 @@ public function output_generates_models($definition, $path, $model)
->with('model.casts.stub')
->andReturn(file_get_contents('stubs/model.casts.stub'));

if ($definition === 'drafts/readme-example.yaml') {
if (in_array($definition, ['drafts/readme-example.yaml', 'drafts/all-column-types.yaml'])) {
$this->files->expects('stub')
->with('model.dates.stub')
->andReturn(file_get_contents('stubs/model.dates.stub'));
Expand Down Expand Up @@ -109,6 +109,9 @@ public function output_works_for_pascal_case_definition()
->with('model.casts.stub')
->andReturn(file_get_contents('stubs/model.casts.stub'))
->twice();
$this->files->expects('stub')
->with('model.dates.stub')
->andReturn(file_get_contents('stubs/model.dates.stub'));
$this->files->expects('stub')
->with('model.method.stub')
->andReturn(file_get_contents('stubs/model.method.stub'))
Expand Down Expand Up @@ -255,15 +258,12 @@ public function output_respects_configuration()
$this->files->expects('stub')
->with('model.class.stub')
->andReturn(file_get_contents('stubs/model.class.stub'));

$this->files->expects('stub')
->with('model.fillable.stub')
->andReturn(file_get_contents('stubs/model.fillable.stub'));

$this->files->expects('stub')
->with('model.casts.stub')
->andReturn(file_get_contents('stubs/model.casts.stub'));

$this->files->expects('stub')
->with('model.method.stub')
->andReturn(file_get_contents('stubs/model.method.stub'));
Expand Down Expand Up @@ -450,6 +450,7 @@ public function modelTreeDataProvider()
['drafts/unconventional.yaml', 'app/Team.php', 'models/unconventional.php'],
['drafts/nested-components.yaml', 'app/Admin/User.php', 'models/nested-components.php'],
['drafts/resource-statements.yaml', 'app/User.php', 'models/resource-statements.php'],
['drafts/all-column-types.yaml', 'app/AllType.php', 'models/all-column-types.php'],
];
}

Expand Down
109 changes: 109 additions & 0 deletions tests/fixtures/models/all-column-types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class AllType extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'bigInteger',
'binary',
'boolean',
'char',
'date',
'dateTime',
'dateTimeTz',
'decimal',
'double',
'enum',
'float',
'geometry',
'geometryCollection',
'integer',
'ipAddress',
'json',
'jsonb',
'lineString',
'longText',
'macAddress',
'mediumInteger',
'mediumText',
'morphs',
'uuidMorphs',
'multiLineString',
'multiPoint',
'multiPolygon',
'nullableMorphs',
'nullableUuidMorphs',
'nullableTimestamps',
'point',
'polygon',
'rememberToken',
'set',
'smallInteger',
'string',
'text',
'time',
'timeTz',
'timestamp',
'timestampTz',
'tinyInteger',
'unsignedBigInteger',
'unsignedDecimal',
'unsignedInteger',
'unsignedMediumInteger',
'unsignedSmallInteger',
'unsignedTinyInteger',
'uuid',
'year',
];

/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'bigInteger' => 'integer',
'boolean' => 'boolean',
'decimal' => 'decimal',
'double' => 'double',
'float' => 'float',
'json' => 'array',
'mediumInteger' => 'integer',
'smallInteger' => 'integer',
'tinyInteger' => 'integer',
'unsignedBigInteger' => 'integer',
'unsignedDecimal' => 'decimal',
'unsignedInteger' => 'integer',
'unsignedMediumInteger' => 'integer',
'unsignedSmallInteger' => 'integer',
'unsignedTinyInteger' => 'integer',
];

/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = [
'date',
'dateTime',
'dateTimeTz',
'nullableTimestamps',
'timestamp',
'timestampTz',
];


public function uuid()
{
return $this->belongsTo(\App\Uuid::class);
}
}
9 changes: 9 additions & 0 deletions tests/fixtures/models/certificate-pascal-case-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class Certificate extends Model
'certificate_type_id' => 'integer',
];

/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = [
'expiry_date',
];


public function certificateType()
{
Expand Down