File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 44
55class Config
66{
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+
717 public static function getPrunableModels (): array
818 {
19+ if (is_callable (static ::$ callback )) {
20+ return call_user_func (static ::$ callback );
21+ }
22+
923 return config ('prunable-fields.models ' , []);
1024 }
1125}
Original file line number Diff line number Diff line change 33use Illuminate \Support \Facades \Event ;
44use Illuminate \Support \Facades \Log ;
55use Maize \PrunableFields \Events \ModelsFieldsPruned ;
6+ use Maize \PrunableFields \Support \Config ;
67use Maize \PrunableFields \Tests \Events \UserUpdatedEvent ;
78use Maize \PrunableFields \Tests \Models \PrunableUser ;
89
6768 fn (ModelsFieldsPruned $ e ) => $ e ->count === 1 && $ e ->model === PrunableUser::class
6869 );
6970})->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