File tree 2 files changed +30
-0
lines changed
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
class Config
6
6
{
7
+ /**
8
+ * @var callable|null
9
+ */
10
+ protected static $ callback ;
11
+
12
+ public static function resolvePrunableModelsUsing (?callable $ callback ): void
13
+ {
14
+ static ::$ callback = $ callback ;
15
+ }
16
+
7
17
public static function getPrunableModels (): array
8
18
{
19
+ if (is_callable (static ::$ callback )) {
20
+ return call_user_func (static ::$ callback );
21
+ }
22
+
9
23
return config ('prunable-fields.models ' , []);
10
24
}
11
25
}
Original file line number Diff line number Diff line change 3
3
use Illuminate \Support \Facades \Event ;
4
4
use Illuminate \Support \Facades \Log ;
5
5
use Maize \PrunableFields \Events \ModelsFieldsPruned ;
6
+ use Maize \PrunableFields \Support \Config ;
6
7
use Maize \PrunableFields \Tests \Events \UserUpdatedEvent ;
7
8
use Maize \PrunableFields \Tests \Models \PrunableUser ;
8
9
67
68
fn (ModelsFieldsPruned $ e ) => $ e ->count === 1 && $ e ->model === PrunableUser::class
68
69
);
69
70
})->with ('user_with_prunable_fields ' );
71
+
72
+ test ('should allow the prunable models to be overridden at runtime ' , function (PrunableUser $ model ) {
73
+ Config::resolvePrunableModelsUsing (fn () => [PrunableUser::class]);
74
+
75
+ Event::fake ();
76
+
77
+ pruneFields ([]);
78
+
79
+ Event::assertDispatched (
80
+ ModelsFieldsPruned::class,
81
+ fn (ModelsFieldsPruned $ e ) => $ e ->count === 1 && $ e ->model === PrunableUser::class
82
+ );
83
+
84
+ Config::resolvePrunableModelsUsing (null );
85
+ })->with ('user_with_prunable_fields ' );
You can’t perform that action at this time.
0 commit comments