@@ -30,11 +30,13 @@ protected function setUp()
3030 Container::unsetEventDispatcher ();
3131 }
3232
33- public function test_save_fires_events ()
33+ public function test_save_fires_saving_and_create_events ()
3434 {
3535 $ dispatcher = m::mock (DispatcherInterface::class)->makePartial ();
3636 $ dispatcher ->shouldReceive ('fire ' )->once ()->withArgs ([Saving::class]);
37+ $ dispatcher ->shouldReceive ('fire ' )->once ()->withArgs ([Creating::class]);
3738 $ dispatcher ->shouldReceive ('fire ' )->once ()->withArgs ([Saved::class]);
39+ $ dispatcher ->shouldReceive ('fire ' )->once ()->withArgs ([Created::class]);
3840 Container::setEventDispatcher ($ dispatcher );
3941
4042 $ model = new ModelEventSaveStub ();
@@ -44,7 +46,9 @@ public function test_save_fires_events()
4446 public function test_create_fires_events ()
4547 {
4648 $ dispatcher = m::mock (DispatcherInterface::class);
49+ $ dispatcher ->shouldReceive ('fire ' )->once ()->withArgs ([Saving::class]);
4750 $ dispatcher ->shouldReceive ('fire ' )->once ()->withArgs ([Creating::class]);
51+ $ dispatcher ->shouldReceive ('fire ' )->once ()->withArgs ([Saved::class]);
4852 $ dispatcher ->shouldReceive ('fire ' )->once ()->withArgs ([Created::class]);
4953 Container::setEventDispatcher ($ dispatcher );
5054
@@ -60,13 +64,15 @@ public function test_create_fires_events()
6064 $ model ->setDn ('cn=foo,dc=bar,dc=baz ' );
6165 $ model ->cn = 'foo ' ;
6266 $ model ->objectclass = 'bar ' ;
63- $ this ->assertTrue ($ model ->create ());
67+ $ this ->assertTrue ($ model ->save ());
6468 }
6569
6670 public function test_updating_model_fires_events ()
6771 {
6872 $ dispatcher = m::mock (DispatcherInterface::class);
73+ $ dispatcher ->shouldReceive ('fire ' )->once ()->withArgs ([Saving::class]);
6974 $ dispatcher ->shouldReceive ('fire ' )->once ()->withArgs ([Updating::class]);
75+ $ dispatcher ->shouldReceive ('fire ' )->once ()->withArgs ([Saved::class]);
7076 $ dispatcher ->shouldReceive ('fire ' )->once ()->withArgs ([Updated::class]);
7177 Container::setEventDispatcher ($ dispatcher );
7278
@@ -108,8 +114,26 @@ public function test_deleting_model_fires_events()
108114
109115class ModelEventSaveStub extends Model
110116{
111- public function create (array $ attributes = [])
117+ public function newQueryWithoutScopes ()
118+ {
119+ return (new ModelQueryBuilderSaveStub (new Connection ()))->setModel ($ this );
120+ }
121+
122+ public function synchronize ()
112123 {
113124 return true ;
114125 }
115126}
127+
128+ class ModelQueryBuilderSaveStub extends Builder
129+ {
130+ public function insert ($ dn , array $ attributes )
131+ {
132+ return true ;
133+ }
134+
135+ public function update ($ dn , array $ modifications )
136+ {
137+ return true ;
138+ }
139+ }
0 commit comments