-
-
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.
- Loading branch information
Showing
8 changed files
with
209 additions
and
5 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
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,11 @@ | ||
<?php | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Contracts; | ||
|
||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
interface ModelHookInterface | ||
{ | ||
public function run(ModelsCommand $command, Model $model): void; | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/Console/ModelsCommand/ModelHooks/Hooks/CustomProperty.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,15 @@ | ||
<?php | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Hooks; | ||
|
||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; | ||
use Barryvdh\LaravelIdeHelper\Contracts\ModelHookInterface; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class CustomProperty implements ModelHookInterface | ||
{ | ||
public function run(ModelsCommand $command, Model $model): void | ||
{ | ||
$command->setProperty('custom', 'string', true, false); | ||
} | ||
} |
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 | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Simple 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,84 @@ | ||
<?php | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks; | ||
|
||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; | ||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; | ||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Hooks\CustomProperty; | ||
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/ModelHooks/Models', | ||
], | ||
'model_hooks' => [ | ||
CustomProperty::class, | ||
], | ||
]); | ||
} | ||
|
||
public function test(): void | ||
{ | ||
$actualContent = null; | ||
|
||
$mockFilesystem = Mockery::mock(Filesystem::class); | ||
$mockFilesystem | ||
->shouldReceive('get') | ||
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.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->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); | ||
|
||
$expectedContent = <<<'PHP' | ||
<?php | ||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Models; | ||
use Illuminate\Database\Eloquent\Model; | ||
/** | ||
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Models\Simple | ||
* | ||
* @property int $id | ||
* @property-read string $custom | ||
* @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|Simple query() | ||
* @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) | ||
* @mixin \Eloquent | ||
*/ | ||
class Simple extends Model | ||
{ | ||
} | ||
|
||
PHP; | ||
|
||
$this->assertSame($expectedContent, $actualContent); | ||
} | ||
} |