File tree Expand file tree Collapse file tree 3 files changed +23
-17
lines changed Expand file tree Collapse file tree 3 files changed +23
-17
lines changed Original file line number Diff line number Diff line change 44
55class Config
66{
7- protected static \Closure $ callback ;
7+ /**
8+ * @var callable|null
9+ */
10+ protected static $ callback ;
811
9- public static function resolvePrunableModelsUsing (\ Closure $ callback )
12+ public static function resolvePrunableModelsUsing (? callable $ callback ): void
1013 {
1114 static ::$ callback = $ callback ;
1215 }
1316
1417 public static function getPrunableModels (): array
1518 {
16- if ( isset (static ::$ callback )) {
19+ if ( is_callable (static ::$ callback )) {
1720 return call_user_func (static ::$ callback );
1821 }
22+
1923 return config ('prunable-fields.models ' , []);
2024 }
2125}
Original file line number Diff line number Diff line change 5656 fn (ModelsFieldsPruned $ e ) => $ e ->count === 1 && $ e ->model === MassPrunableUser::class
5757 );
5858})->with ('user_with_mass_prunable_fields ' );
59-
60- test ('should allow the prunable models to be overridden at runtime ' , function (MassPrunableUser $ model ) {
61- \Maize \PrunableFields \Support \Config::resolvePrunableModelsUsing (fn () => [MassPrunableUser::class]);
62-
63- Event::fake ();
64-
65- pruneFields ([]);
66-
67- Event::assertDispatched (
68- ModelsFieldsPruned::class,
69- fn (ModelsFieldsPruned $ e ) => $ e ->count === 1 && $ e ->model === MassPrunableUser::class
70- );
71-
72- })->with ('user_with_mass_prunable_fields ' );
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