-
-
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.
Make writing relation count properties optional (#969)
* Make writing relation count properties optional * Clean up description * Add test for write_model_magic_where=false * Add test for write_model_relation_count_properties=false
- Loading branch information
Showing
6 changed files
with
426 additions
and
6 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
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,9 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\MagicWhere\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Post extends Model | ||
{ | ||
} |
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,150 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\MagicWhere; | ||
|
||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; | ||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; | ||
use Illuminate\Filesystem\Filesystem; | ||
use Mockery; | ||
|
||
class Test extends AbstractModelsCommand | ||
{ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
parent::getEnvironmentSetUp($app); | ||
|
||
$app['config']->set('ide-helper', [ | ||
'model_locations' => [ | ||
// This is calculated from the base_path() which points to | ||
// vendor/orchestra/testbench-core/laravel | ||
'/../../../../tests/Console/ModelsCommand/MagicWhere/Models', | ||
], | ||
'write_model_magic_where' => false | ||
]); | ||
} | ||
|
||
public function test(): void | ||
{ | ||
$actualContent = null; | ||
$mockFilesystem = Mockery::mock(Filesystem::class); | ||
$mockFilesystem | ||
->shouldReceive('get') | ||
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php')) | ||
->once(); | ||
$mockFilesystem | ||
->shouldReceive('put') | ||
->with( | ||
Mockery::any(), | ||
Mockery::capture($actualContent) | ||
) | ||
->andReturn(1) // Simulate we wrote _something_ to the file | ||
->once(); | ||
|
||
$this->instance(Filesystem::class, $mockFilesystem); | ||
|
||
$command = $this->app->make(ModelsCommand::class); | ||
|
||
$tester = $this->runCommand($command, [ | ||
'--write' => true, | ||
]); | ||
|
||
$this->assertSame(0, $tester->getStatusCode()); | ||
$this->assertEmpty($tester->getDisplay()); | ||
|
||
$expectedContent = <<<'PHP' | ||
<?php declare(strict_types=1); | ||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\MagicWhere\Models; | ||
use Illuminate\Database\Eloquent\Model; | ||
/** | ||
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\MagicWhere\Models\Post | ||
* | ||
* @property integer $id | ||
* @property string|null $char_nullable | ||
* @property string $char_not_nullable | ||
* @property string|null $string_nullable | ||
* @property string $string_not_nullable | ||
* @property string|null $text_nullable | ||
* @property string $text_not_nullable | ||
* @property string|null $medium_text_nullable | ||
* @property string $medium_text_not_nullable | ||
* @property string|null $long_text_nullable | ||
* @property string $long_text_not_nullable | ||
* @property integer|null $integer_nullable | ||
* @property integer $integer_not_nullable | ||
* @property integer|null $tiny_integer_nullable | ||
* @property integer $tiny_integer_not_nullable | ||
* @property integer|null $small_integer_nullable | ||
* @property integer $small_integer_not_nullable | ||
* @property integer|null $medium_integer_nullable | ||
* @property integer $medium_integer_not_nullable | ||
* @property integer|null $big_integer_nullable | ||
* @property integer $big_integer_not_nullable | ||
* @property integer|null $unsigned_integer_nullable | ||
* @property integer $unsigned_integer_not_nullable | ||
* @property integer|null $unsigned_tiny_integer_nullable | ||
* @property integer $unsigned_tiny_integer_not_nullable | ||
* @property integer|null $unsigned_small_integer_nullable | ||
* @property integer $unsigned_small_integer_not_nullable | ||
* @property integer|null $unsigned_medium_integer_nullable | ||
* @property integer $unsigned_medium_integer_not_nullable | ||
* @property integer|null $unsigned_big_integer_nullable | ||
* @property integer $unsigned_big_integer_not_nullable | ||
* @property float|null $float_nullable | ||
* @property float $float_not_nullable | ||
* @property float|null $double_nullable | ||
* @property float $double_not_nullable | ||
* @property string|null $decimal_nullable | ||
* @property string $decimal_not_nullable | ||
* @property string|null $unsigned_decimal_nullable | ||
* @property string $unsigned_decimal_not_nullable | ||
* @property integer|null $boolean_nullable | ||
* @property integer $boolean_not_nullable | ||
* @property string|null $enum_nullable | ||
* @property string $enum_not_nullable | ||
* @property string|null $json_nullable | ||
* @property string $json_not_nullable | ||
* @property string|null $jsonb_nullable | ||
* @property string $jsonb_not_nullable | ||
* @property string|null $date_nullable | ||
* @property string $date_not_nullable | ||
* @property string|null $datetime_nullable | ||
* @property string $datetime_not_nullable | ||
* @property string|null $datetimetz_nullable | ||
* @property string $datetimetz_not_nullable | ||
* @property string|null $time_nullable | ||
* @property string $time_not_nullable | ||
* @property string|null $timetz_nullable | ||
* @property string $timetz_not_nullable | ||
* @property string|null $timestamp_nullable | ||
* @property string $timestamp_not_nullable | ||
* @property string|null $timestamptz_nullable | ||
* @property string $timestamptz_not_nullable | ||
* @property integer|null $year_nullable | ||
* @property integer $year_not_nullable | ||
* @property mixed|null $binary_nullable | ||
* @property mixed $binary_not_nullable | ||
* @property string|null $uuid_nullable | ||
* @property string $uuid_not_nullable | ||
* @property string|null $ipaddress_nullable | ||
* @property string $ipaddress_not_nullable | ||
* @property string|null $macaddress_nullable | ||
* @property string $macaddress_not_nullable | ||
* @property \Illuminate\Support\Carbon|null $created_at | ||
* @property \Illuminate\Support\Carbon|null $updated_at | ||
* @method static \Illuminate\Database\Eloquent\Builder|Post newModelQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|Post newQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|Post query() | ||
* @mixin \Eloquent | ||
*/ | ||
class Post extends Model | ||
{ | ||
} | ||
|
||
PHP; | ||
|
||
$this->assertSame($expectedContent, $actualContent); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/Console/ModelsCommand/RelationCountProperties/Models/Post.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,14 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\RelationCountProperties\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
||
class Post extends Model | ||
{ | ||
public function relationHasMany(): HasMany | ||
{ | ||
return $this->hasMany(Post::class); | ||
} | ||
} |
Oops, something went wrong.