44
55use  Illuminate \Container \Container ;
66use  Illuminate \Contracts \Events \Dispatcher  as  DispatcherContract ;
7+ use  Illuminate \Database \Capsule \Manager  as  DB ;
8+ use  Illuminate \Database \ConnectionResolverInterface ;
79use  Illuminate \Database \Console \PruneCommand ;
810use  Illuminate \Database \Eloquent \MassPrunable ;
911use  Illuminate \Database \Eloquent \Model ;
1012use  Illuminate \Database \Eloquent \Prunable ;
1113use  Illuminate \Database \Events \ModelsPruned ;
1214use  Illuminate \Events \Dispatcher ;
15+ use  Mockery  as  m ;
1316use  PHPUnit \Framework \TestCase ;
1417use  Symfony \Component \Console \Input \ArrayInput ;
1518use  Symfony \Component \Console \Output \BufferedOutput ;
@@ -60,6 +63,41 @@ public function testNonPrunableTest()
6063EOF, str_replace ("\r" , '' , $ outputfetch ()));
6164    }
6265
66+     public  function  testTheCommandMayBePretended ()
67+     {
68+         $ dbnew  DB ;
69+         $ dbaddConnection ([
70+             'driver '  => 'sqlite ' ,
71+             'database '  => ':memory: ' ,
72+         ]);
73+         $ dbsetAsGlobal ();
74+         DB ::connection ('default ' )->getSchemaBuilder ()->create ('prunables ' , function  ($ table
75+             $ tablestring ('name ' )->nullable ();
76+             $ tablestring ('value ' )->nullable ();
77+         });
78+         DB ::connection ('default ' )->table ('prunables ' )->insert ([
79+             ['name '  => 'zain ' , 'value '  => 1 ],
80+             ['name '  => 'patrice ' , 'value '  => 2 ],
81+             ['name '  => 'amelia ' , 'value '  => 3 ],
82+             ['name '  => 'stuart ' , 'value '  => 4 ],
83+             ['name '  => 'bello ' , 'value '  => 5 ],
84+         ]);
85+         $ resolvermock (ConnectionResolverInterface::class, ['connection '  => $ dbgetConnection ('default ' )]);
86+         PrunableTestModelWithPrunableRecords::setConnectionResolver ($ resolver
87+ 
88+         $ output$ this artisan ([
89+             '--model '  => PrunableTestModelWithPrunableRecords::class,
90+             '--pretend '  => true ,
91+         ]);
92+ 
93+         $ this assertEquals (<<<'EOF'
94+ 3 [Illuminate\Tests\Database\PrunableTestModelWithPrunableRecords] records will be pruned. 
95+ 
96+ EOF, str_replace ("\r" , '' , $ outputfetch ()));
97+ 
98+         $ this assertEquals (5 , PrunableTestModelWithPrunableRecords::count ());
99+     }
100+ 
63101    protected  function  artisan ($ arguments
64102    {
65103        $ inputnew  ArrayInput ($ arguments
@@ -84,13 +122,21 @@ class PrunableTestModelWithPrunableRecords extends Model
84122{
85123    use  MassPrunable;
86124
125+     protected  $ table'prunables ' ;
126+     protected  $ connection'default ' ;
127+ 
87128    public  function  pruneAll ()
88129    {
89130        event (new  ModelsPruned (static ::class, 10 ));
90131        event (new  ModelsPruned (static ::class, 20 ));
91132
92133        return  20 ;
93134    }
135+ 
136+     public  function  prunable ()
137+     {
138+         return  static ::where ('value ' , '>= ' , 3 );
139+     }
94140}
95141
96142class  PrunableTestModelWithoutPrunableRecords extends  Model
0 commit comments