Skip to content

Commit 42d39d2

Browse files
Adding tests to Set / unset methods
1 parent dafd6f4 commit 42d39d2

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Hooks;
6+
7+
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
8+
use Barryvdh\LaravelIdeHelper\Contracts\ModelHookInterface;
9+
use Illuminate\Database\Eloquent\Builder;
10+
use Illuminate\Database\Eloquent\Model;
11+
12+
class CustomMethod implements ModelHookInterface
13+
{
14+
public function run(ModelsCommand $command, Model $model): void
15+
{
16+
$command->setMethod('custom', $command->getMethodType($model, Builder::class), ['$custom']);
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Hooks;
6+
7+
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
8+
use Barryvdh\LaravelIdeHelper\Contracts\ModelHookInterface;
9+
use Illuminate\Database\Eloquent\Builder;
10+
use Illuminate\Database\Eloquent\Model;
11+
12+
class UnsetMethod implements ModelHookInterface
13+
{
14+
public function run(ModelsCommand $command, Model $model): void
15+
{
16+
$command->unsetMethod('query');
17+
}
18+
}

tests/Console/ModelsCommand/ModelHooks/Test.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
88
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
99
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Hooks\CustomProperty;
10+
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Hooks\CustomMethod;
11+
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Hooks\UnsetMethod;
1012
use Illuminate\Filesystem\Filesystem;
1113
use Mockery;
1214

@@ -24,6 +26,8 @@ protected function getEnvironmentSetUp($app)
2426
],
2527
'model_hooks' => [
2628
CustomProperty::class,
29+
CustomMethod::class,
30+
UnsetMethod::class
2731
],
2832
]);
2933
}
@@ -71,9 +75,9 @@ public function test(): void
7175
*
7276
* @property int $id
7377
* @property-read string $custom
78+
* @method static \Illuminate\Database\Eloquent\Builder|Simple custom($custom)
7479
* @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery()
7580
* @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery()
76-
* @method static \Illuminate\Database\Eloquent\Builder|Simple query()
7781
* @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value)
7882
* @mixin \Eloquent
7983
*/

0 commit comments

Comments
 (0)