From 133e4b4bf9c7890495624246a6730dbe3a5ca8fa Mon Sep 17 00:00:00 2001 From: Bowen Date: Fri, 20 Dec 2024 16:35:10 +0800 Subject: [PATCH] add restoring and restored events --- contracts/database/orm/events.go | 2 + contracts/database/orm/observer.go | 59 +++- database/console/stubs.go | 28 -- database/gorm/query.go | 73 ++-- database/gorm/query_test.go | 44 +++ database/gorm/test_models.go | 16 + mocks/database/orm/Observer.go | 322 ------------------ mocks/database/orm/ObserverWithCreating.go | 81 +++++ mocks/database/orm/ObserverWithDeleting.go | 81 +++++ .../database/orm/ObserverWithForceDeleting.go | 81 +++++ mocks/database/orm/ObserverWithRestored.go | 81 +++++ mocks/database/orm/ObserverWithRestoring.go | 81 +++++ mocks/database/orm/ObserverWithRetrieved.go | 81 +++++ mocks/database/orm/ObserverWithSaved.go | 81 +++++ mocks/database/orm/ObserverWithSaving.go | 81 +++++ mocks/database/orm/ObserverWithUpdating.go | 81 +++++ 16 files changed, 890 insertions(+), 383 deletions(-) create mode 100644 mocks/database/orm/ObserverWithCreating.go create mode 100644 mocks/database/orm/ObserverWithDeleting.go create mode 100644 mocks/database/orm/ObserverWithForceDeleting.go create mode 100644 mocks/database/orm/ObserverWithRestored.go create mode 100644 mocks/database/orm/ObserverWithRestoring.go create mode 100644 mocks/database/orm/ObserverWithRetrieved.go create mode 100644 mocks/database/orm/ObserverWithSaved.go create mode 100644 mocks/database/orm/ObserverWithSaving.go create mode 100644 mocks/database/orm/ObserverWithUpdating.go diff --git a/contracts/database/orm/events.go b/contracts/database/orm/events.go index a49ea8870..651456674 100644 --- a/contracts/database/orm/events.go +++ b/contracts/database/orm/events.go @@ -18,6 +18,8 @@ const ( EventDeleted EventType = "deleted" EventForceDeleting EventType = "force_deleting" EventForceDeleted EventType = "force_deleted" + EventRestored EventType = "restored" + EventRestoring EventType = "restoring" ) type Event interface { diff --git a/contracts/database/orm/observer.go b/contracts/database/orm/observer.go index c445fa845..f37bfb13f 100644 --- a/contracts/database/orm/observer.go +++ b/contracts/database/orm/observer.go @@ -1,30 +1,61 @@ package orm type Observer interface { - // Retrieved called when the model is retrieved from the database. - Retrieved(Event) error - // Creating called when the model is being created. - Creating(Event) error // Created called when the model has been created. Created(Event) error - // Updating called when the model is being updated. - Updating(Event) error // Updated called when the model has been updated. Updated(Event) error - // Saving called when the model is being saved. - Saving(Event) error - // Saved called when the model has been saved. - Saved(Event) error - // Deleting called when the model is being deleted. - Deleting(Event) error // Deleted called when the model has been deleted. Deleted(Event) error - // ForceDeleting called when the model is being force deleted. - ForceDeleting(Event) error // ForceDeleted called when the model has been force deleted. ForceDeleted(Event) error } +type ObserverWithCreating interface { + // Creating called when the model is being created. + Creating(Event) error +} + +type ObserverWithDeleting interface { + // Deleting called when the model is being deleted. + Deleting(Event) error +} + +type ObserverWithForceDeleting interface { + // ForceDeleting called when the model is being force deleted. + ForceDeleting(Event) error +} + +type ObserverWithRestored interface { + // Restored called when the model has been restored. + Restored(Event) error +} + +type ObserverWithRestoring interface { + // Restoring called when the model is being restored. + Restoring(Event) error +} + +type ObserverWithRetrieved interface { + // Retrieved called when the model is retrieved from the database. + Retrieved(Event) error +} + +type ObserverWithSaved interface { + // Saved called when the model has been saved. + Saved(Event) error +} + +type ObserverWithSaving interface { + // Saving called when the model is being saved. + Saving(Event) error +} + +type ObserverWithUpdating interface { + // Updating called when the model is being updated. + Updating(Event) error +} + type ModelToObserver struct { Model any Observer Observer diff --git a/database/console/stubs.go b/database/console/stubs.go index ac57aeca8..670ee8c41 100644 --- a/database/console/stubs.go +++ b/database/console/stubs.go @@ -26,46 +26,18 @@ import ( type DummyObserver struct{} -func (u *DummyObserver) Retrieved(event orm.Event) error { - return nil -} - -func (u *DummyObserver) Creating(event orm.Event) error { - return nil -} - func (u *DummyObserver) Created(event orm.Event) error { return nil } -func (u *DummyObserver) Updating(event orm.Event) error { - return nil -} - func (u *DummyObserver) Updated(event orm.Event) error { return nil } -func (u *DummyObserver) Saving(event orm.Event) error { - return nil -} - -func (u *DummyObserver) Saved(event orm.Event) error { - return nil -} - -func (u *DummyObserver) Deleting(event orm.Event) error { - return nil -} - func (u *DummyObserver) Deleted(event orm.Event) error { return nil } -func (u *DummyObserver) ForceDeleting(event orm.Event) error { - return nil -} - func (u *DummyObserver) ForceDeleted(event orm.Event) error { return nil } diff --git a/database/gorm/query.go b/database/gorm/query.go index d4e661673..85d40bfa5 100644 --- a/database/gorm/query.go +++ b/database/gorm/query.go @@ -674,11 +674,19 @@ func (r *Query) Restore(model ...any) (*contractsorm.Result, error) { return nil, errors.OrmDeletedAtColumnNotFound } + if err := r.restoring(realModel); err != nil { + return nil, err + } + res := tx.Update(deletedAtColumnName, nil) if res.Error != nil { return nil, res.Error } + if err := r.restored(realModel); err != nil { + return nil, err + } + return &contractsorm.Result{ RowsAffected: res.RowsAffected, }, res.Error @@ -1439,6 +1447,14 @@ func (r *Query) refreshConnection(model any) (*Query, error) { return query, nil } +func (r *Query) restored(dest any) error { + return r.event(contractsorm.EventRestored, r.instance.Statement.Model, dest) +} + +func (r *Query) restoring(dest any) error { + return r.event(contractsorm.EventRestoring, r.instance.Statement.Model, dest) +} + func (r *Query) retrieved(dest any) error { return r.event(contractsorm.EventRetrieved, nil, dest) } @@ -1590,11 +1606,8 @@ func getDeletedAtColumn(model any) string { } t := reflect.TypeOf(model) - v := reflect.ValueOf(model) - if t.Kind() == reflect.Pointer { t = t.Elem() - v = v.Elem() } for i := 0; i < t.NumField(); i++ { @@ -1660,28 +1673,50 @@ func getModelConnection(model any) (string, error) { func getObserverEvent(event contractsorm.EventType, observer contractsorm.Observer) func(contractsorm.Event) error { switch event { - case contractsorm.EventRetrieved: - return observer.Retrieved - case contractsorm.EventCreating: - return observer.Creating case contractsorm.EventCreated: return observer.Created - case contractsorm.EventUpdating: - return observer.Updating - case contractsorm.EventUpdated: - return observer.Updated - case contractsorm.EventSaving: - return observer.Saving - case contractsorm.EventSaved: - return observer.Saved - case contractsorm.EventDeleting: - return observer.Deleting + case contractsorm.EventCreating: + if o, ok := observer.(contractsorm.ObserverWithCreating); ok { + return o.Creating + } case contractsorm.EventDeleted: return observer.Deleted - case contractsorm.EventForceDeleting: - return observer.ForceDeleting + case contractsorm.EventDeleting: + if o, ok := observer.(contractsorm.ObserverWithDeleting); ok { + return o.Deleting + } case contractsorm.EventForceDeleted: return observer.ForceDeleted + case contractsorm.EventForceDeleting: + if o, ok := observer.(contractsorm.ObserverWithForceDeleting); ok { + return o.ForceDeleting + } + case contractsorm.EventRestored: + if o, ok := observer.(contractsorm.ObserverWithRestored); ok { + return o.Restored + } + case contractsorm.EventRestoring: + if o, ok := observer.(contractsorm.ObserverWithRestoring); ok { + return o.Restoring + } + case contractsorm.EventRetrieved: + if o, ok := observer.(contractsorm.ObserverWithRetrieved); ok { + return o.Retrieved + } + case contractsorm.EventSaved: + if o, ok := observer.(contractsorm.ObserverWithSaved); ok { + return o.Saved + } + case contractsorm.EventSaving: + if o, ok := observer.(contractsorm.ObserverWithSaving); ok { + return o.Saving + } + case contractsorm.EventUpdated: + return observer.Updated + case contractsorm.EventUpdating: + if o, ok := observer.(contractsorm.ObserverWithUpdating); ok { + return o.Updating + } } return nil diff --git a/database/gorm/query_test.go b/database/gorm/query_test.go index 4383ff4da..19f99d03a 100644 --- a/database/gorm/query_test.go +++ b/database/gorm/query_test.go @@ -1444,6 +1444,50 @@ func (s *QueryTestSuite) TestEvent_ForceDeleted() { } } +func (s *QueryTestSuite) TestEvent_Restored() { + for _, query := range s.queries { + user := User{Name: "event_restored_name", Avatar: "event_restored_avatar"} + s.Nil(query.Query().Create(&user)) + + res, err := query.Query().Delete(&user) + s.NoError(err) + s.Equal(int64(1), res.RowsAffected) + + res, err = query.Query().WithTrashed().Restore(&user) + s.NoError(err) + s.Equal(int64(1), res.RowsAffected) + s.Equal("event_restored_name1", user.Name) + + var user1 User + s.Nil(query.Query().Find(&user1, user.ID)) + s.True(user1.ID > 0) + s.Equal("event_restored_name", user1.Name) + s.Equal("event_restored_avatar", user1.Avatar) + } +} + +func (s *QueryTestSuite) TestEvent_Restoring() { + for _, query := range s.queries { + user := User{Name: "event_restoring_name", Avatar: "event_restoring_avatar"} + s.Nil(query.Query().Create(&user)) + + res, err := query.Query().Delete(&user) + s.NoError(err) + s.Equal(int64(1), res.RowsAffected) + + res, err = query.Query().WithTrashed().Restore(&user) + s.NoError(err) + s.Equal(int64(1), res.RowsAffected) + s.Equal("event_restoring_name1", user.Name) + + var user1 User + s.Nil(query.Query().Find(&user1, user.ID)) + s.True(user1.ID > 0) + s.Equal("event_restoring_name", user1.Name) + s.Equal("event_restoring_avatar", user1.Avatar) + } +} + func (s *QueryTestSuite) TestEvent_Retrieved() { for _, query := range s.queries { tests := []struct { diff --git a/database/gorm/test_models.go b/database/gorm/test_models.go index 7732dd57f..8c82f681f 100644 --- a/database/gorm/test_models.go +++ b/database/gorm/test_models.go @@ -304,6 +304,22 @@ func (u *User) DispatchesEvents() map[ormcontract.EventType]func(ormcontract.Eve event.SetAttribute("name", "event_retrieved_name1") } + return nil + }, + ormcontract.EventRestored: func(event ormcontract.Event) error { + name := event.GetAttribute("name") + if name != nil && name.(string) == "event_restored_name" { + event.SetAttribute("name", "event_restored_name1") + } + + return nil + }, + ormcontract.EventRestoring: func(event ormcontract.Event) error { + name := event.GetAttribute("name") + if name != nil && name.(string) == "event_restoring_name" { + event.SetAttribute("name", "event_restoring_name1") + } + return nil }, } diff --git a/mocks/database/orm/Observer.go b/mocks/database/orm/Observer.go index 9dc4eddc8..611e9a1be 100644 --- a/mocks/database/orm/Observer.go +++ b/mocks/database/orm/Observer.go @@ -66,52 +66,6 @@ func (_c *Observer_Created_Call) RunAndReturn(run func(orm.Event) error) *Observ return _c } -// Creating provides a mock function with given fields: _a0 -func (_m *Observer) Creating(_a0 orm.Event) error { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for Creating") - } - - var r0 error - if rf, ok := ret.Get(0).(func(orm.Event) error); ok { - r0 = rf(_a0) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Observer_Creating_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Creating' -type Observer_Creating_Call struct { - *mock.Call -} - -// Creating is a helper method to define mock.On call -// - _a0 orm.Event -func (_e *Observer_Expecter) Creating(_a0 interface{}) *Observer_Creating_Call { - return &Observer_Creating_Call{Call: _e.mock.On("Creating", _a0)} -} - -func (_c *Observer_Creating_Call) Run(run func(_a0 orm.Event)) *Observer_Creating_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(orm.Event)) - }) - return _c -} - -func (_c *Observer_Creating_Call) Return(_a0 error) *Observer_Creating_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Observer_Creating_Call) RunAndReturn(run func(orm.Event) error) *Observer_Creating_Call { - _c.Call.Return(run) - return _c -} - // Deleted provides a mock function with given fields: _a0 func (_m *Observer) Deleted(_a0 orm.Event) error { ret := _m.Called(_a0) @@ -158,52 +112,6 @@ func (_c *Observer_Deleted_Call) RunAndReturn(run func(orm.Event) error) *Observ return _c } -// Deleting provides a mock function with given fields: _a0 -func (_m *Observer) Deleting(_a0 orm.Event) error { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for Deleting") - } - - var r0 error - if rf, ok := ret.Get(0).(func(orm.Event) error); ok { - r0 = rf(_a0) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Observer_Deleting_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Deleting' -type Observer_Deleting_Call struct { - *mock.Call -} - -// Deleting is a helper method to define mock.On call -// - _a0 orm.Event -func (_e *Observer_Expecter) Deleting(_a0 interface{}) *Observer_Deleting_Call { - return &Observer_Deleting_Call{Call: _e.mock.On("Deleting", _a0)} -} - -func (_c *Observer_Deleting_Call) Run(run func(_a0 orm.Event)) *Observer_Deleting_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(orm.Event)) - }) - return _c -} - -func (_c *Observer_Deleting_Call) Return(_a0 error) *Observer_Deleting_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Observer_Deleting_Call) RunAndReturn(run func(orm.Event) error) *Observer_Deleting_Call { - _c.Call.Return(run) - return _c -} - // ForceDeleted provides a mock function with given fields: _a0 func (_m *Observer) ForceDeleted(_a0 orm.Event) error { ret := _m.Called(_a0) @@ -250,190 +158,6 @@ func (_c *Observer_ForceDeleted_Call) RunAndReturn(run func(orm.Event) error) *O return _c } -// ForceDeleting provides a mock function with given fields: _a0 -func (_m *Observer) ForceDeleting(_a0 orm.Event) error { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for ForceDeleting") - } - - var r0 error - if rf, ok := ret.Get(0).(func(orm.Event) error); ok { - r0 = rf(_a0) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Observer_ForceDeleting_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ForceDeleting' -type Observer_ForceDeleting_Call struct { - *mock.Call -} - -// ForceDeleting is a helper method to define mock.On call -// - _a0 orm.Event -func (_e *Observer_Expecter) ForceDeleting(_a0 interface{}) *Observer_ForceDeleting_Call { - return &Observer_ForceDeleting_Call{Call: _e.mock.On("ForceDeleting", _a0)} -} - -func (_c *Observer_ForceDeleting_Call) Run(run func(_a0 orm.Event)) *Observer_ForceDeleting_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(orm.Event)) - }) - return _c -} - -func (_c *Observer_ForceDeleting_Call) Return(_a0 error) *Observer_ForceDeleting_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Observer_ForceDeleting_Call) RunAndReturn(run func(orm.Event) error) *Observer_ForceDeleting_Call { - _c.Call.Return(run) - return _c -} - -// Retrieved provides a mock function with given fields: _a0 -func (_m *Observer) Retrieved(_a0 orm.Event) error { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for Retrieved") - } - - var r0 error - if rf, ok := ret.Get(0).(func(orm.Event) error); ok { - r0 = rf(_a0) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Observer_Retrieved_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Retrieved' -type Observer_Retrieved_Call struct { - *mock.Call -} - -// Retrieved is a helper method to define mock.On call -// - _a0 orm.Event -func (_e *Observer_Expecter) Retrieved(_a0 interface{}) *Observer_Retrieved_Call { - return &Observer_Retrieved_Call{Call: _e.mock.On("Retrieved", _a0)} -} - -func (_c *Observer_Retrieved_Call) Run(run func(_a0 orm.Event)) *Observer_Retrieved_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(orm.Event)) - }) - return _c -} - -func (_c *Observer_Retrieved_Call) Return(_a0 error) *Observer_Retrieved_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Observer_Retrieved_Call) RunAndReturn(run func(orm.Event) error) *Observer_Retrieved_Call { - _c.Call.Return(run) - return _c -} - -// Saved provides a mock function with given fields: _a0 -func (_m *Observer) Saved(_a0 orm.Event) error { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for Saved") - } - - var r0 error - if rf, ok := ret.Get(0).(func(orm.Event) error); ok { - r0 = rf(_a0) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Observer_Saved_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Saved' -type Observer_Saved_Call struct { - *mock.Call -} - -// Saved is a helper method to define mock.On call -// - _a0 orm.Event -func (_e *Observer_Expecter) Saved(_a0 interface{}) *Observer_Saved_Call { - return &Observer_Saved_Call{Call: _e.mock.On("Saved", _a0)} -} - -func (_c *Observer_Saved_Call) Run(run func(_a0 orm.Event)) *Observer_Saved_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(orm.Event)) - }) - return _c -} - -func (_c *Observer_Saved_Call) Return(_a0 error) *Observer_Saved_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Observer_Saved_Call) RunAndReturn(run func(orm.Event) error) *Observer_Saved_Call { - _c.Call.Return(run) - return _c -} - -// Saving provides a mock function with given fields: _a0 -func (_m *Observer) Saving(_a0 orm.Event) error { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for Saving") - } - - var r0 error - if rf, ok := ret.Get(0).(func(orm.Event) error); ok { - r0 = rf(_a0) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Observer_Saving_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Saving' -type Observer_Saving_Call struct { - *mock.Call -} - -// Saving is a helper method to define mock.On call -// - _a0 orm.Event -func (_e *Observer_Expecter) Saving(_a0 interface{}) *Observer_Saving_Call { - return &Observer_Saving_Call{Call: _e.mock.On("Saving", _a0)} -} - -func (_c *Observer_Saving_Call) Run(run func(_a0 orm.Event)) *Observer_Saving_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(orm.Event)) - }) - return _c -} - -func (_c *Observer_Saving_Call) Return(_a0 error) *Observer_Saving_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Observer_Saving_Call) RunAndReturn(run func(orm.Event) error) *Observer_Saving_Call { - _c.Call.Return(run) - return _c -} - // Updated provides a mock function with given fields: _a0 func (_m *Observer) Updated(_a0 orm.Event) error { ret := _m.Called(_a0) @@ -480,52 +204,6 @@ func (_c *Observer_Updated_Call) RunAndReturn(run func(orm.Event) error) *Observ return _c } -// Updating provides a mock function with given fields: _a0 -func (_m *Observer) Updating(_a0 orm.Event) error { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for Updating") - } - - var r0 error - if rf, ok := ret.Get(0).(func(orm.Event) error); ok { - r0 = rf(_a0) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Observer_Updating_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Updating' -type Observer_Updating_Call struct { - *mock.Call -} - -// Updating is a helper method to define mock.On call -// - _a0 orm.Event -func (_e *Observer_Expecter) Updating(_a0 interface{}) *Observer_Updating_Call { - return &Observer_Updating_Call{Call: _e.mock.On("Updating", _a0)} -} - -func (_c *Observer_Updating_Call) Run(run func(_a0 orm.Event)) *Observer_Updating_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(orm.Event)) - }) - return _c -} - -func (_c *Observer_Updating_Call) Return(_a0 error) *Observer_Updating_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Observer_Updating_Call) RunAndReturn(run func(orm.Event) error) *Observer_Updating_Call { - _c.Call.Return(run) - return _c -} - // NewObserver creates a new instance of Observer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewObserver(t interface { diff --git a/mocks/database/orm/ObserverWithCreating.go b/mocks/database/orm/ObserverWithCreating.go new file mode 100644 index 000000000..f717aa62a --- /dev/null +++ b/mocks/database/orm/ObserverWithCreating.go @@ -0,0 +1,81 @@ +// Code generated by mockery. DO NOT EDIT. + +package orm + +import ( + orm "github.com/goravel/framework/contracts/database/orm" + mock "github.com/stretchr/testify/mock" +) + +// ObserverWithCreating is an autogenerated mock type for the ObserverWithCreating type +type ObserverWithCreating struct { + mock.Mock +} + +type ObserverWithCreating_Expecter struct { + mock *mock.Mock +} + +func (_m *ObserverWithCreating) EXPECT() *ObserverWithCreating_Expecter { + return &ObserverWithCreating_Expecter{mock: &_m.Mock} +} + +// Creating provides a mock function with given fields: _a0 +func (_m *ObserverWithCreating) Creating(_a0 orm.Event) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Creating") + } + + var r0 error + if rf, ok := ret.Get(0).(func(orm.Event) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ObserverWithCreating_Creating_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Creating' +type ObserverWithCreating_Creating_Call struct { + *mock.Call +} + +// Creating is a helper method to define mock.On call +// - _a0 orm.Event +func (_e *ObserverWithCreating_Expecter) Creating(_a0 interface{}) *ObserverWithCreating_Creating_Call { + return &ObserverWithCreating_Creating_Call{Call: _e.mock.On("Creating", _a0)} +} + +func (_c *ObserverWithCreating_Creating_Call) Run(run func(_a0 orm.Event)) *ObserverWithCreating_Creating_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orm.Event)) + }) + return _c +} + +func (_c *ObserverWithCreating_Creating_Call) Return(_a0 error) *ObserverWithCreating_Creating_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ObserverWithCreating_Creating_Call) RunAndReturn(run func(orm.Event) error) *ObserverWithCreating_Creating_Call { + _c.Call.Return(run) + return _c +} + +// NewObserverWithCreating creates a new instance of ObserverWithCreating. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewObserverWithCreating(t interface { + mock.TestingT + Cleanup(func()) +}) *ObserverWithCreating { + mock := &ObserverWithCreating{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/database/orm/ObserverWithDeleting.go b/mocks/database/orm/ObserverWithDeleting.go new file mode 100644 index 000000000..061ddc9d4 --- /dev/null +++ b/mocks/database/orm/ObserverWithDeleting.go @@ -0,0 +1,81 @@ +// Code generated by mockery. DO NOT EDIT. + +package orm + +import ( + orm "github.com/goravel/framework/contracts/database/orm" + mock "github.com/stretchr/testify/mock" +) + +// ObserverWithDeleting is an autogenerated mock type for the ObserverWithDeleting type +type ObserverWithDeleting struct { + mock.Mock +} + +type ObserverWithDeleting_Expecter struct { + mock *mock.Mock +} + +func (_m *ObserverWithDeleting) EXPECT() *ObserverWithDeleting_Expecter { + return &ObserverWithDeleting_Expecter{mock: &_m.Mock} +} + +// Deleting provides a mock function with given fields: _a0 +func (_m *ObserverWithDeleting) Deleting(_a0 orm.Event) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Deleting") + } + + var r0 error + if rf, ok := ret.Get(0).(func(orm.Event) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ObserverWithDeleting_Deleting_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Deleting' +type ObserverWithDeleting_Deleting_Call struct { + *mock.Call +} + +// Deleting is a helper method to define mock.On call +// - _a0 orm.Event +func (_e *ObserverWithDeleting_Expecter) Deleting(_a0 interface{}) *ObserverWithDeleting_Deleting_Call { + return &ObserverWithDeleting_Deleting_Call{Call: _e.mock.On("Deleting", _a0)} +} + +func (_c *ObserverWithDeleting_Deleting_Call) Run(run func(_a0 orm.Event)) *ObserverWithDeleting_Deleting_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orm.Event)) + }) + return _c +} + +func (_c *ObserverWithDeleting_Deleting_Call) Return(_a0 error) *ObserverWithDeleting_Deleting_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ObserverWithDeleting_Deleting_Call) RunAndReturn(run func(orm.Event) error) *ObserverWithDeleting_Deleting_Call { + _c.Call.Return(run) + return _c +} + +// NewObserverWithDeleting creates a new instance of ObserverWithDeleting. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewObserverWithDeleting(t interface { + mock.TestingT + Cleanup(func()) +}) *ObserverWithDeleting { + mock := &ObserverWithDeleting{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/database/orm/ObserverWithForceDeleting.go b/mocks/database/orm/ObserverWithForceDeleting.go new file mode 100644 index 000000000..70a8e888d --- /dev/null +++ b/mocks/database/orm/ObserverWithForceDeleting.go @@ -0,0 +1,81 @@ +// Code generated by mockery. DO NOT EDIT. + +package orm + +import ( + orm "github.com/goravel/framework/contracts/database/orm" + mock "github.com/stretchr/testify/mock" +) + +// ObserverWithForceDeleting is an autogenerated mock type for the ObserverWithForceDeleting type +type ObserverWithForceDeleting struct { + mock.Mock +} + +type ObserverWithForceDeleting_Expecter struct { + mock *mock.Mock +} + +func (_m *ObserverWithForceDeleting) EXPECT() *ObserverWithForceDeleting_Expecter { + return &ObserverWithForceDeleting_Expecter{mock: &_m.Mock} +} + +// ForceDeleting provides a mock function with given fields: _a0 +func (_m *ObserverWithForceDeleting) ForceDeleting(_a0 orm.Event) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for ForceDeleting") + } + + var r0 error + if rf, ok := ret.Get(0).(func(orm.Event) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ObserverWithForceDeleting_ForceDeleting_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ForceDeleting' +type ObserverWithForceDeleting_ForceDeleting_Call struct { + *mock.Call +} + +// ForceDeleting is a helper method to define mock.On call +// - _a0 orm.Event +func (_e *ObserverWithForceDeleting_Expecter) ForceDeleting(_a0 interface{}) *ObserverWithForceDeleting_ForceDeleting_Call { + return &ObserverWithForceDeleting_ForceDeleting_Call{Call: _e.mock.On("ForceDeleting", _a0)} +} + +func (_c *ObserverWithForceDeleting_ForceDeleting_Call) Run(run func(_a0 orm.Event)) *ObserverWithForceDeleting_ForceDeleting_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orm.Event)) + }) + return _c +} + +func (_c *ObserverWithForceDeleting_ForceDeleting_Call) Return(_a0 error) *ObserverWithForceDeleting_ForceDeleting_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ObserverWithForceDeleting_ForceDeleting_Call) RunAndReturn(run func(orm.Event) error) *ObserverWithForceDeleting_ForceDeleting_Call { + _c.Call.Return(run) + return _c +} + +// NewObserverWithForceDeleting creates a new instance of ObserverWithForceDeleting. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewObserverWithForceDeleting(t interface { + mock.TestingT + Cleanup(func()) +}) *ObserverWithForceDeleting { + mock := &ObserverWithForceDeleting{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/database/orm/ObserverWithRestored.go b/mocks/database/orm/ObserverWithRestored.go new file mode 100644 index 000000000..fb9ebdc98 --- /dev/null +++ b/mocks/database/orm/ObserverWithRestored.go @@ -0,0 +1,81 @@ +// Code generated by mockery. DO NOT EDIT. + +package orm + +import ( + orm "github.com/goravel/framework/contracts/database/orm" + mock "github.com/stretchr/testify/mock" +) + +// ObserverWithRestored is an autogenerated mock type for the ObserverWithRestored type +type ObserverWithRestored struct { + mock.Mock +} + +type ObserverWithRestored_Expecter struct { + mock *mock.Mock +} + +func (_m *ObserverWithRestored) EXPECT() *ObserverWithRestored_Expecter { + return &ObserverWithRestored_Expecter{mock: &_m.Mock} +} + +// Restored provides a mock function with given fields: _a0 +func (_m *ObserverWithRestored) Restored(_a0 orm.Event) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Restored") + } + + var r0 error + if rf, ok := ret.Get(0).(func(orm.Event) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ObserverWithRestored_Restored_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Restored' +type ObserverWithRestored_Restored_Call struct { + *mock.Call +} + +// Restored is a helper method to define mock.On call +// - _a0 orm.Event +func (_e *ObserverWithRestored_Expecter) Restored(_a0 interface{}) *ObserverWithRestored_Restored_Call { + return &ObserverWithRestored_Restored_Call{Call: _e.mock.On("Restored", _a0)} +} + +func (_c *ObserverWithRestored_Restored_Call) Run(run func(_a0 orm.Event)) *ObserverWithRestored_Restored_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orm.Event)) + }) + return _c +} + +func (_c *ObserverWithRestored_Restored_Call) Return(_a0 error) *ObserverWithRestored_Restored_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ObserverWithRestored_Restored_Call) RunAndReturn(run func(orm.Event) error) *ObserverWithRestored_Restored_Call { + _c.Call.Return(run) + return _c +} + +// NewObserverWithRestored creates a new instance of ObserverWithRestored. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewObserverWithRestored(t interface { + mock.TestingT + Cleanup(func()) +}) *ObserverWithRestored { + mock := &ObserverWithRestored{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/database/orm/ObserverWithRestoring.go b/mocks/database/orm/ObserverWithRestoring.go new file mode 100644 index 000000000..db0e725ce --- /dev/null +++ b/mocks/database/orm/ObserverWithRestoring.go @@ -0,0 +1,81 @@ +// Code generated by mockery. DO NOT EDIT. + +package orm + +import ( + orm "github.com/goravel/framework/contracts/database/orm" + mock "github.com/stretchr/testify/mock" +) + +// ObserverWithRestoring is an autogenerated mock type for the ObserverWithRestoring type +type ObserverWithRestoring struct { + mock.Mock +} + +type ObserverWithRestoring_Expecter struct { + mock *mock.Mock +} + +func (_m *ObserverWithRestoring) EXPECT() *ObserverWithRestoring_Expecter { + return &ObserverWithRestoring_Expecter{mock: &_m.Mock} +} + +// Restoring provides a mock function with given fields: _a0 +func (_m *ObserverWithRestoring) Restoring(_a0 orm.Event) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Restoring") + } + + var r0 error + if rf, ok := ret.Get(0).(func(orm.Event) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ObserverWithRestoring_Restoring_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Restoring' +type ObserverWithRestoring_Restoring_Call struct { + *mock.Call +} + +// Restoring is a helper method to define mock.On call +// - _a0 orm.Event +func (_e *ObserverWithRestoring_Expecter) Restoring(_a0 interface{}) *ObserverWithRestoring_Restoring_Call { + return &ObserverWithRestoring_Restoring_Call{Call: _e.mock.On("Restoring", _a0)} +} + +func (_c *ObserverWithRestoring_Restoring_Call) Run(run func(_a0 orm.Event)) *ObserverWithRestoring_Restoring_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orm.Event)) + }) + return _c +} + +func (_c *ObserverWithRestoring_Restoring_Call) Return(_a0 error) *ObserverWithRestoring_Restoring_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ObserverWithRestoring_Restoring_Call) RunAndReturn(run func(orm.Event) error) *ObserverWithRestoring_Restoring_Call { + _c.Call.Return(run) + return _c +} + +// NewObserverWithRestoring creates a new instance of ObserverWithRestoring. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewObserverWithRestoring(t interface { + mock.TestingT + Cleanup(func()) +}) *ObserverWithRestoring { + mock := &ObserverWithRestoring{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/database/orm/ObserverWithRetrieved.go b/mocks/database/orm/ObserverWithRetrieved.go new file mode 100644 index 000000000..becc17dec --- /dev/null +++ b/mocks/database/orm/ObserverWithRetrieved.go @@ -0,0 +1,81 @@ +// Code generated by mockery. DO NOT EDIT. + +package orm + +import ( + orm "github.com/goravel/framework/contracts/database/orm" + mock "github.com/stretchr/testify/mock" +) + +// ObserverWithRetrieved is an autogenerated mock type for the ObserverWithRetrieved type +type ObserverWithRetrieved struct { + mock.Mock +} + +type ObserverWithRetrieved_Expecter struct { + mock *mock.Mock +} + +func (_m *ObserverWithRetrieved) EXPECT() *ObserverWithRetrieved_Expecter { + return &ObserverWithRetrieved_Expecter{mock: &_m.Mock} +} + +// Retrieved provides a mock function with given fields: _a0 +func (_m *ObserverWithRetrieved) Retrieved(_a0 orm.Event) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Retrieved") + } + + var r0 error + if rf, ok := ret.Get(0).(func(orm.Event) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ObserverWithRetrieved_Retrieved_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Retrieved' +type ObserverWithRetrieved_Retrieved_Call struct { + *mock.Call +} + +// Retrieved is a helper method to define mock.On call +// - _a0 orm.Event +func (_e *ObserverWithRetrieved_Expecter) Retrieved(_a0 interface{}) *ObserverWithRetrieved_Retrieved_Call { + return &ObserverWithRetrieved_Retrieved_Call{Call: _e.mock.On("Retrieved", _a0)} +} + +func (_c *ObserverWithRetrieved_Retrieved_Call) Run(run func(_a0 orm.Event)) *ObserverWithRetrieved_Retrieved_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orm.Event)) + }) + return _c +} + +func (_c *ObserverWithRetrieved_Retrieved_Call) Return(_a0 error) *ObserverWithRetrieved_Retrieved_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ObserverWithRetrieved_Retrieved_Call) RunAndReturn(run func(orm.Event) error) *ObserverWithRetrieved_Retrieved_Call { + _c.Call.Return(run) + return _c +} + +// NewObserverWithRetrieved creates a new instance of ObserverWithRetrieved. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewObserverWithRetrieved(t interface { + mock.TestingT + Cleanup(func()) +}) *ObserverWithRetrieved { + mock := &ObserverWithRetrieved{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/database/orm/ObserverWithSaved.go b/mocks/database/orm/ObserverWithSaved.go new file mode 100644 index 000000000..97eaecb01 --- /dev/null +++ b/mocks/database/orm/ObserverWithSaved.go @@ -0,0 +1,81 @@ +// Code generated by mockery. DO NOT EDIT. + +package orm + +import ( + orm "github.com/goravel/framework/contracts/database/orm" + mock "github.com/stretchr/testify/mock" +) + +// ObserverWithSaved is an autogenerated mock type for the ObserverWithSaved type +type ObserverWithSaved struct { + mock.Mock +} + +type ObserverWithSaved_Expecter struct { + mock *mock.Mock +} + +func (_m *ObserverWithSaved) EXPECT() *ObserverWithSaved_Expecter { + return &ObserverWithSaved_Expecter{mock: &_m.Mock} +} + +// Saved provides a mock function with given fields: _a0 +func (_m *ObserverWithSaved) Saved(_a0 orm.Event) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Saved") + } + + var r0 error + if rf, ok := ret.Get(0).(func(orm.Event) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ObserverWithSaved_Saved_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Saved' +type ObserverWithSaved_Saved_Call struct { + *mock.Call +} + +// Saved is a helper method to define mock.On call +// - _a0 orm.Event +func (_e *ObserverWithSaved_Expecter) Saved(_a0 interface{}) *ObserverWithSaved_Saved_Call { + return &ObserverWithSaved_Saved_Call{Call: _e.mock.On("Saved", _a0)} +} + +func (_c *ObserverWithSaved_Saved_Call) Run(run func(_a0 orm.Event)) *ObserverWithSaved_Saved_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orm.Event)) + }) + return _c +} + +func (_c *ObserverWithSaved_Saved_Call) Return(_a0 error) *ObserverWithSaved_Saved_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ObserverWithSaved_Saved_Call) RunAndReturn(run func(orm.Event) error) *ObserverWithSaved_Saved_Call { + _c.Call.Return(run) + return _c +} + +// NewObserverWithSaved creates a new instance of ObserverWithSaved. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewObserverWithSaved(t interface { + mock.TestingT + Cleanup(func()) +}) *ObserverWithSaved { + mock := &ObserverWithSaved{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/database/orm/ObserverWithSaving.go b/mocks/database/orm/ObserverWithSaving.go new file mode 100644 index 000000000..4c8d86acb --- /dev/null +++ b/mocks/database/orm/ObserverWithSaving.go @@ -0,0 +1,81 @@ +// Code generated by mockery. DO NOT EDIT. + +package orm + +import ( + orm "github.com/goravel/framework/contracts/database/orm" + mock "github.com/stretchr/testify/mock" +) + +// ObserverWithSaving is an autogenerated mock type for the ObserverWithSaving type +type ObserverWithSaving struct { + mock.Mock +} + +type ObserverWithSaving_Expecter struct { + mock *mock.Mock +} + +func (_m *ObserverWithSaving) EXPECT() *ObserverWithSaving_Expecter { + return &ObserverWithSaving_Expecter{mock: &_m.Mock} +} + +// Saving provides a mock function with given fields: _a0 +func (_m *ObserverWithSaving) Saving(_a0 orm.Event) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Saving") + } + + var r0 error + if rf, ok := ret.Get(0).(func(orm.Event) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ObserverWithSaving_Saving_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Saving' +type ObserverWithSaving_Saving_Call struct { + *mock.Call +} + +// Saving is a helper method to define mock.On call +// - _a0 orm.Event +func (_e *ObserverWithSaving_Expecter) Saving(_a0 interface{}) *ObserverWithSaving_Saving_Call { + return &ObserverWithSaving_Saving_Call{Call: _e.mock.On("Saving", _a0)} +} + +func (_c *ObserverWithSaving_Saving_Call) Run(run func(_a0 orm.Event)) *ObserverWithSaving_Saving_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orm.Event)) + }) + return _c +} + +func (_c *ObserverWithSaving_Saving_Call) Return(_a0 error) *ObserverWithSaving_Saving_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ObserverWithSaving_Saving_Call) RunAndReturn(run func(orm.Event) error) *ObserverWithSaving_Saving_Call { + _c.Call.Return(run) + return _c +} + +// NewObserverWithSaving creates a new instance of ObserverWithSaving. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewObserverWithSaving(t interface { + mock.TestingT + Cleanup(func()) +}) *ObserverWithSaving { + mock := &ObserverWithSaving{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/database/orm/ObserverWithUpdating.go b/mocks/database/orm/ObserverWithUpdating.go new file mode 100644 index 000000000..93cdd5393 --- /dev/null +++ b/mocks/database/orm/ObserverWithUpdating.go @@ -0,0 +1,81 @@ +// Code generated by mockery. DO NOT EDIT. + +package orm + +import ( + orm "github.com/goravel/framework/contracts/database/orm" + mock "github.com/stretchr/testify/mock" +) + +// ObserverWithUpdating is an autogenerated mock type for the ObserverWithUpdating type +type ObserverWithUpdating struct { + mock.Mock +} + +type ObserverWithUpdating_Expecter struct { + mock *mock.Mock +} + +func (_m *ObserverWithUpdating) EXPECT() *ObserverWithUpdating_Expecter { + return &ObserverWithUpdating_Expecter{mock: &_m.Mock} +} + +// Updating provides a mock function with given fields: _a0 +func (_m *ObserverWithUpdating) Updating(_a0 orm.Event) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Updating") + } + + var r0 error + if rf, ok := ret.Get(0).(func(orm.Event) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ObserverWithUpdating_Updating_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Updating' +type ObserverWithUpdating_Updating_Call struct { + *mock.Call +} + +// Updating is a helper method to define mock.On call +// - _a0 orm.Event +func (_e *ObserverWithUpdating_Expecter) Updating(_a0 interface{}) *ObserverWithUpdating_Updating_Call { + return &ObserverWithUpdating_Updating_Call{Call: _e.mock.On("Updating", _a0)} +} + +func (_c *ObserverWithUpdating_Updating_Call) Run(run func(_a0 orm.Event)) *ObserverWithUpdating_Updating_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orm.Event)) + }) + return _c +} + +func (_c *ObserverWithUpdating_Updating_Call) Return(_a0 error) *ObserverWithUpdating_Updating_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ObserverWithUpdating_Updating_Call) RunAndReturn(run func(orm.Event) error) *ObserverWithUpdating_Updating_Call { + _c.Call.Return(run) + return _c +} + +// NewObserverWithUpdating creates a new instance of ObserverWithUpdating. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewObserverWithUpdating(t interface { + mock.TestingT + Cleanup(func()) +}) *ObserverWithUpdating { + mock := &ObserverWithUpdating{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +}