-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support for all possible `Model::$casts` types * add testing for casts * update changelog * update changelog (again?)
- Loading branch information
Showing
6 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/Console/ModelsCommand/SimpleCasts/Models/SimpleCast.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SimpleCasts\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class SimpleCast extends Model | ||
{ | ||
protected $casts = [ | ||
'cast_to_int' => 'int', | ||
'cast_to_integer' => 'integer', | ||
'cast_to_real' => 'real', | ||
'cast_to_float' => 'float', | ||
'cast_to_double' => 'double', | ||
'cast_to_decimal' => 'decimal:4', | ||
'cast_to_string' => 'string', | ||
'cast_to_bool' => 'bool', | ||
'cast_to_boolean' => 'boolean', | ||
'cast_to_object' => 'object', | ||
'cast_to_array' => 'array', | ||
'cast_to_json' => 'json', | ||
'cast_to_collection' => 'collection', | ||
'cast_to_date' => 'date', | ||
'cast_to_datetime' => 'datetime', | ||
'cast_to_custom_datetime' => 'custom_datetime:Y-m-d H:i:s', | ||
'cast_to_immutable_date' => 'immutable_date', | ||
'cast_to_immutable_custom_datetime' => 'immutable_custom_datetime:Y-m-d H:i:s', | ||
'cast_to_immutable_datetime' => 'immutable_datetime', | ||
'cast_to_timestamp' => 'timestamp', | ||
'cast_to_encrypted' => 'encrypted', | ||
'cast_to_encrypted_array' => 'encrypted:array', | ||
'cast_to_encrypted_collection' => 'encrypted:collection', | ||
'cast_to_encrypted_json' => 'encrypted:json', | ||
'cast_to_encrypted_object' => 'encrypted:object', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SimpleCasts; | ||
|
||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; | ||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; | ||
|
||
class Test extends AbstractModelsCommand | ||
{ | ||
public function test(): void | ||
{ | ||
$command = $this->app->make(ModelsCommand::class); | ||
|
||
$tester = $this->runCommand($command, [ | ||
'--write' => true, | ||
]); | ||
|
||
$this->assertSame(0, $tester->getStatusCode()); | ||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); | ||
$this->assertMatchesMockedSnapshot(); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
tests/Console/ModelsCommand/SimpleCasts/__snapshots__/Test__test__1.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SimpleCasts\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SimpleCasts\Models\SimpleCast | ||
* | ||
* @property integer $cast_to_int | ||
* @property integer $cast_to_integer | ||
* @property float $cast_to_real | ||
* @property float $cast_to_float | ||
* @property float $cast_to_double | ||
* @property string $cast_to_decimal | ||
* @property string $cast_to_string | ||
* @property boolean $cast_to_bool | ||
* @property boolean $cast_to_boolean | ||
* @property object $cast_to_object | ||
* @property array $cast_to_array | ||
* @property array $cast_to_json | ||
* @property \Illuminate\Support\Collection $cast_to_collection | ||
* @property \Illuminate\Support\Carbon $cast_to_date | ||
* @property \Illuminate\Support\Carbon $cast_to_datetime | ||
* @property \Illuminate\Support\Carbon $cast_to_custom_datetime | ||
* @property \Carbon\CarbonImmutable $cast_to_immutable_date | ||
* @property \Carbon\CarbonImmutable $cast_to_immutable_custom_datetime | ||
* @property \Carbon\CarbonImmutable $cast_to_immutable_datetime | ||
* @property integer $cast_to_timestamp | ||
* @property mixed $cast_to_encrypted | ||
* @property array $cast_to_encrypted_array | ||
* @property \Illuminate\Support\Collection $cast_to_encrypted_collection | ||
* @property array $cast_to_encrypted_json | ||
* @property object $cast_to_encrypted_object | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast newModelQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast newQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast query() | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToArray($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToBool($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToBoolean($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToCollection($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToCustomDatetime($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToDate($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToDatetime($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToDecimal($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToDouble($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToEncrypted($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToEncryptedArray($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToEncryptedCollection($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToEncryptedJson($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToEncryptedObject($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToFloat($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToImmutableCustomDatetime($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToImmutableDate($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToImmutableDatetime($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToInt($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToInteger($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToJson($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToObject($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToReal($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToString($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|SimpleCast whereCastToTimestamp($value) | ||
* @mixin \Eloquent | ||
*/ | ||
class SimpleCast extends Model | ||
{ | ||
protected $casts = [ | ||
'cast_to_int' => 'int', | ||
'cast_to_integer' => 'integer', | ||
'cast_to_real' => 'real', | ||
'cast_to_float' => 'float', | ||
'cast_to_double' => 'double', | ||
'cast_to_decimal' => 'decimal:4', | ||
'cast_to_string' => 'string', | ||
'cast_to_bool' => 'bool', | ||
'cast_to_boolean' => 'boolean', | ||
'cast_to_object' => 'object', | ||
'cast_to_array' => 'array', | ||
'cast_to_json' => 'json', | ||
'cast_to_collection' => 'collection', | ||
'cast_to_date' => 'date', | ||
'cast_to_datetime' => 'datetime', | ||
'cast_to_custom_datetime' => 'custom_datetime:Y-m-d H:i:s', | ||
'cast_to_immutable_date' => 'immutable_date', | ||
'cast_to_immutable_custom_datetime' => 'immutable_custom_datetime:Y-m-d H:i:s', | ||
'cast_to_immutable_datetime' => 'immutable_datetime', | ||
'cast_to_timestamp' => 'timestamp', | ||
'cast_to_encrypted' => 'encrypted', | ||
'cast_to_encrypted_array' => 'encrypted:array', | ||
'cast_to_encrypted_collection' => 'encrypted:collection', | ||
'cast_to_encrypted_json' => 'encrypted:json', | ||
'cast_to_encrypted_object' => 'encrypted:object', | ||
]; | ||
} |
41 changes: 41 additions & 0 deletions
41
tests/Console/ModelsCommand/migrations/____simple_casts_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class SimpleCastsTable extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
Schema::create('simple_casts', static function (Blueprint $table) { | ||
$table->string('cast_to_int'); | ||
$table->string('cast_to_integer'); | ||
$table->string('cast_to_real'); | ||
$table->string('cast_to_float'); | ||
$table->string('cast_to_double'); | ||
$table->string('cast_to_decimal'); | ||
$table->string('cast_to_string'); | ||
$table->string('cast_to_bool'); | ||
$table->string('cast_to_boolean'); | ||
$table->string('cast_to_object'); | ||
$table->string('cast_to_array'); | ||
$table->string('cast_to_json'); | ||
$table->string('cast_to_collection'); | ||
$table->string('cast_to_date'); | ||
$table->string('cast_to_datetime'); | ||
$table->string('cast_to_custom_datetime'); | ||
$table->string('cast_to_immutable_date'); | ||
$table->string('cast_to_immutable_custom_datetime'); | ||
$table->string('cast_to_immutable_datetime'); | ||
$table->string('cast_to_timestamp'); | ||
$table->string('cast_to_encrypted'); | ||
$table->string('cast_to_encrypted_array'); | ||
$table->string('cast_to_encrypted_collection'); | ||
$table->string('cast_to_encrypted_json'); | ||
$table->string('cast_to_encrypted_object'); | ||
}); | ||
} | ||
} |