-
-
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.
Add support in morphTo relationship for null values (1547) (#1549)
Co-authored-by: Barry vd. Heuvel <[email protected]>
- Loading branch information
1 parent
672acce
commit f7a3dc8
Showing
6 changed files
with
132 additions
and
1 deletion.
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Morphs\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\MorphTo; | ||
|
||
class Morphs extends Model | ||
{ | ||
public function relationMorphTo(): MorphTo | ||
{ | ||
return $this->morphTo(); | ||
} | ||
|
||
public function nullableRelationMorphTo(): MorphTo | ||
{ | ||
return $this->morphTo(); | ||
} | ||
} |
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\Morphs; | ||
|
||
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(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/Console/ModelsCommand/Morphs/__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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Morphs\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\MorphTo; | ||
|
||
/** | ||
* | ||
* | ||
* @property string $relation_morph_to_type | ||
* @property int $relation_morph_to_id | ||
* @property string|null $nullable_relation_morph_to_type | ||
* @property int|null $nullable_relation_morph_to_id | ||
* @property-read Model|\Eloquent|null $nullableRelationMorphTo | ||
* @property-read Model|\Eloquent $relationMorphTo | ||
* @method static \Illuminate\Database\Eloquent\Builder|Morphs newModelQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|Morphs newQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|Morphs query() | ||
* @method static \Illuminate\Database\Eloquent\Builder|Morphs whereNullableRelationMorphToId($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|Morphs whereNullableRelationMorphToType($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|Morphs whereRelationMorphToId($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|Morphs whereRelationMorphToType($value) | ||
* @mixin \Eloquent | ||
*/ | ||
class Morphs extends Model | ||
{ | ||
public function relationMorphTo(): MorphTo | ||
{ | ||
return $this->morphTo(); | ||
} | ||
|
||
public function nullableRelationMorphTo(): MorphTo | ||
{ | ||
return $this->morphTo(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/Console/ModelsCommand/migrations/____morphs_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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class MorphsTable extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
Schema::create('morphs', function (Blueprint $table) { | ||
$table->morphs('relation_morph_to'); | ||
$table->nullableMorphs('nullable_relation_morph_to'); | ||
}); | ||
} | ||
} |