From 4981135ec3c49d592cf6ba6fe38896bf748fbd03 Mon Sep 17 00:00:00 2001 From: Toby Twigger Date: Fri, 24 Apr 2020 17:36:35 +0100 Subject: [PATCH 1/7] Cache control models --- CHANGELOG.md | 6 + src/Bootstrap/RegistersCachedRepositories.php | 151 ++++++++++++++++++ src/Bootstrap/RegistersObserverFramework.php | 151 ++++++++++++++++++ src/Cache/DataGroup.php | 87 ++++++++++ src/Cache/DataPosition.php | 87 ++++++++++ src/Cache/DataRole.php | 86 ++++++++++ src/Cache/DataUser.php | 93 +++++++++++ src/Cache/Group.php | 121 ++++++++++++++ src/Cache/Pivots/Tags/GroupGroupTag.php | 77 +++++++++ src/Cache/Pivots/Tags/PositionPositionTag.php | 77 +++++++++ src/Cache/Pivots/Tags/RoleRoleTag.php | 77 +++++++++ src/Cache/Pivots/Tags/UserUserTag.php | 77 +++++++++ src/Cache/Pivots/UserGroup.php | 77 +++++++++ src/Cache/Pivots/UserRole.php | 78 +++++++++ src/Cache/Position.php | 122 ++++++++++++++ src/Cache/Role.php | 31 +++- src/Cache/Tags/GroupTag.php | 116 ++++++++++++++ src/Cache/Tags/GroupTagCategory.php | 100 ++++++++++++ src/Cache/Tags/PositionTag.php | 116 ++++++++++++++ src/Cache/Tags/PositionTagCategory.php | 100 ++++++++++++ src/Cache/Tags/RoleTag.php | 116 ++++++++++++++ src/Cache/Tags/RoleTagCategory.php | 100 ++++++++++++ src/Cache/Tags/UserTag.php | 117 ++++++++++++++ src/Cache/Tags/UserTagCategory.php | 100 ++++++++++++ src/Cache/User.php | 121 ++++++++++++++ src/Contracts/Repositories/DataGroup.php | 12 ++ src/Contracts/Repositories/DataPosition.php | 12 ++ src/Contracts/Repositories/DataRole.php | 12 +- src/Contracts/Repositories/DataUser.php | 13 ++ src/Contracts/Repositories/Group.php | 9 ++ src/Contracts/Repositories/Position.php | 11 +- src/Contracts/Repositories/Role.php | 11 ++ src/Contracts/Repositories/Tags/GroupTag.php | 14 +- .../Repositories/Tags/GroupTagCategory.php | 11 ++ .../Repositories/Tags/PositionTag.php | 12 ++ .../Repositories/Tags/PositionTagCategory.php | 11 ++ src/Contracts/Repositories/Tags/RoleTag.php | 12 ++ .../Repositories/Tags/RoleTagCategory.php | 11 ++ src/Contracts/Repositories/Tags/UserTag.php | 12 ++ .../Repositories/Tags/UserTagCategory.php | 11 ++ src/Contracts/Repositories/User.php | 9 ++ src/ControlDBServiceProvider.php | 101 ++++++++++-- src/Export/ExportControlCommand.php | 5 +- .../Formatter/Group/SimpleGroupFormatter.php | 5 +- .../Formatter/Role/SimpleRoleFormatter.php | 10 +- src/Models/DataGroup.php | 16 +- src/Models/DataPosition.php | 15 +- src/Models/DataRole.php | 49 +++--- src/Models/DataUser.php | 38 +++-- src/Models/Group.php | 28 ++-- src/Models/Position.php | 23 +-- src/Models/Role.php | 42 ++--- src/Models/Tags/GroupTag.php | 33 ++-- src/Models/Tags/GroupTagCategory.php | 25 +-- src/Models/Tags/PositionTag.php | 25 +-- src/Models/Tags/PositionTagCategory.php | 19 ++- src/Models/Tags/RoleTag.php | 25 +-- src/Models/Tags/RoleTagCategory.php | 19 ++- src/Models/Tags/UserTag.php | 26 +-- src/Models/Tags/UserTagCategory.php | 20 ++- src/Models/User.php | 21 ++- src/Observers/DataGroupObserverClearCache.php | 27 ++++ .../DataPositionObserverClearCache.php | 27 ++++ src/Observers/DataRoleObserverClearCache.php | 27 ++++ src/Observers/DataUserObserverClearCache.php | 27 ++++ src/Observers/GroupObserverCascadeDelete.php | 61 +++++++ src/Observers/GroupObserverClearCache.php | 43 +++++ .../NotifyObservers/DataGroupNotifier.php | 86 ++++++++++ .../NotifyObservers/DataPositionNotifier.php | 86 ++++++++++ .../NotifyObservers/DataRoleNotifier.php | 88 ++++++++++ .../NotifyObservers/DataUserNotifier.php | 94 +++++++++++ .../NotifyObservers/Framework/Notifier.php | 43 +++++ .../NotifyObservers/Framework/Observe.php | 18 +++ .../Framework/ObserverStore.php | 34 ++++ .../NotifyObservers/GroupNotifier.php | 119 ++++++++++++++ .../Pivots/Tags/GroupGroupTagNotifier.php | 73 +++++++++ .../Tags/PositionPositionTagNotifier.php | 73 +++++++++ .../Pivots/Tags/RoleRoleTagNotifier.php | 73 +++++++++ .../Pivots/Tags/UserUserTagNotifier.php | 73 +++++++++ .../Pivots/UserGroupNotifier.php | 72 +++++++++ .../Pivots/UserRoleNotifier.php | 72 +++++++++ .../NotifyObservers/PositionNotifier.php | 119 ++++++++++++++ .../NotifyObservers/RoleNotifier.php | 145 +++++++++++++++++ .../Tags/GroupTagCategoryNotifier.php | 100 ++++++++++++ .../NotifyObservers/Tags/GroupTagNotifier.php | 114 +++++++++++++ .../Tags/PositionTagCategoryNotifier.php | 100 ++++++++++++ .../Tags/PositionTagNotifier.php | 114 +++++++++++++ .../Tags/RoleTagCategoryNotifier.php | 100 ++++++++++++ .../NotifyObservers/Tags/RoleTagNotifier.php | 114 +++++++++++++ .../Tags/UserTagCategoryNotifier.php | 100 ++++++++++++ .../NotifyObservers/Tags/UserTagNotifier.php | 114 +++++++++++++ .../NotifyObservers/UserNotifier.php | 119 ++++++++++++++ .../Tags/GroupGroupTagObserverClearCache.php | 35 ++++ .../PositionPositionTagObserverClearCache.php | 35 ++++ .../Tags/RoleRoleTagObserverClearCache.php | 35 ++++ .../Tags/UserUserTagObserverClearCache.php | 35 ++++ .../Pivots/UserGroupObserverClearCache.php | 35 ++++ .../Pivots/UserRoleObserverClearCache.php | 35 ++++ .../PositionObserverCascadeDelete.php | 47 ++++++ src/Observers/PositionObserverClearCache.php | 43 +++++ src/Observers/RoleObserverCascadeDelete.php | 47 ++++++ src/Observers/RoleObserverClearCache.php | 49 ++++++ .../GroupTagCategoryObserverCascadeDelete.php | 29 ++++ .../GroupTagCategoryObserverClearCache.php | 35 ++++ .../Tags/GroupTagObserverCascadeDelete.php | 29 ++++ .../Tags/GroupTagObserverClearCache.php | 43 +++++ ...sitionTagCategoryObserverCascadeDelete.php | 29 ++++ .../PositionTagCategoryObserverClearCache.php | 35 ++++ .../Tags/PositionTagObserverCascadeDelete.php | 29 ++++ .../Tags/PositionTagObserverClearCache.php | 43 +++++ .../RoleTagCategoryObserverCascadeDelete.php | 29 ++++ .../RoleTagCategoryObserverClearCache.php | 35 ++++ .../Tags/RoleTagObserverCascadeDelete.php | 29 ++++ .../Tags/RoleTagObserverClearCache.php | 43 +++++ .../UserTagCategoryObserverCascadeDelete.php | 29 ++++ .../UserTagCategoryObserverClearCache.php | 35 ++++ .../Tags/UserTagObserverCascadeDelete.php | 29 ++++ .../Tags/UserTagObserverClearCache.php | 43 +++++ src/Observers/UserObserverCascadeDelete.php | 61 +++++++ src/Observers/UserObserverClearCache.php | 43 +++++ src/Repositories/DataGroup.php | 17 ++ src/Repositories/DataPosition.php | 17 ++ src/Repositories/DataRole.php | 17 ++ src/Repositories/DataUser.php | 24 +++ src/Repositories/Group.php | 13 ++ src/Repositories/Position.php | 15 +- src/Repositories/Role.php | 16 ++ src/Repositories/Tags/GroupTag.php | 19 +++ src/Repositories/Tags/GroupTagCategory.php | 19 ++- src/Repositories/Tags/PositionTag.php | 19 +++ src/Repositories/Tags/PositionTagCategory.php | 17 ++ src/Repositories/Tags/RoleTag.php | 19 +++ src/Repositories/Tags/RoleTagCategory.php | 17 ++ src/Repositories/Tags/UserTag.php | 19 +++ src/Repositories/Tags/UserTagCategory.php | 17 ++ src/Repositories/User.php | 13 ++ src/Traits/DataGroupTrait.php | 21 +++ src/Traits/DataPositionTrait.php | 22 +++ src/Traits/DataRoleTrait.php | 23 +++ src/Traits/DataUserTrait.php | 61 +++++++ src/Traits/GroupTrait.php | 11 ++ src/Traits/PositionTrait.php | 11 ++ src/Traits/RoleTrait.php | 31 ++++ src/Traits/Tags/GroupTagCategoryTrait.php | 31 ++++ src/Traits/Tags/GroupTagTrait.php | 41 +++++ src/Traits/Tags/PositionTagCategoryTrait.php | 31 ++++ src/Traits/Tags/PositionTagTrait.php | 40 +++++ src/Traits/Tags/RoleTagCategoryTrait.php | 31 ++++ src/Traits/Tags/RoleTagTrait.php | 40 +++++ src/Traits/Tags/UserTagCategoryTrait.php | 31 ++++ src/Traits/Tags/UserTagTrait.php | 41 +++++ src/Traits/UserTrait.php | 11 ++ tests/Unit/Models/DataRoleTest.php | 2 +- tests/Unit/Models/GroupTest.php | 2 +- tests/Unit/Models/PositionTest.php | 2 +- tests/Unit/Models/RoleTest.php | 4 +- tests/Unit/Models/Tags/GroupTagTest.php | 8 +- tests/Unit/Models/Tags/PositionTagTest.php | 8 +- tests/Unit/Models/Tags/RoleTagTest.php | 8 +- tests/Unit/Models/Tags/UserTagTest.php | 8 +- tests/Unit/Models/UserTest.php | 4 +- tests/Unit/Repositories/DataGroupTest.php | 45 ++++++ tests/Unit/Repositories/DataPositionTest.php | 45 ++++++ tests/Unit/Repositories/DataRoleTest.php | 45 ++++++ tests/Unit/Repositories/DataUserTest.php | 121 +++++++++++--- tests/Unit/Repositories/GroupTest.php | 35 ++++ tests/Unit/Repositories/PositionTest.php | 35 ++++ tests/Unit/Repositories/RoleTest.php | 47 ++++++ tests/Unit/Repositories/UserTest.php | 34 ++++ tests/Unit/Traits/UserTraitTest.php | 2 - 170 files changed, 7579 insertions(+), 242 deletions(-) create mode 100644 src/Bootstrap/RegistersCachedRepositories.php create mode 100644 src/Bootstrap/RegistersObserverFramework.php create mode 100644 src/Cache/DataGroup.php create mode 100644 src/Cache/DataPosition.php create mode 100644 src/Cache/DataRole.php create mode 100644 src/Cache/DataUser.php create mode 100644 src/Cache/Group.php create mode 100644 src/Cache/Pivots/Tags/GroupGroupTag.php create mode 100644 src/Cache/Pivots/Tags/PositionPositionTag.php create mode 100644 src/Cache/Pivots/Tags/RoleRoleTag.php create mode 100644 src/Cache/Pivots/Tags/UserUserTag.php create mode 100644 src/Cache/Pivots/UserGroup.php create mode 100644 src/Cache/Pivots/UserRole.php create mode 100644 src/Cache/Position.php create mode 100644 src/Cache/Tags/GroupTag.php create mode 100644 src/Cache/Tags/GroupTagCategory.php create mode 100644 src/Cache/Tags/PositionTag.php create mode 100644 src/Cache/Tags/PositionTagCategory.php create mode 100644 src/Cache/Tags/RoleTag.php create mode 100644 src/Cache/Tags/RoleTagCategory.php create mode 100644 src/Cache/Tags/UserTag.php create mode 100644 src/Cache/Tags/UserTagCategory.php create mode 100644 src/Cache/User.php create mode 100644 src/Observers/DataGroupObserverClearCache.php create mode 100644 src/Observers/DataPositionObserverClearCache.php create mode 100644 src/Observers/DataRoleObserverClearCache.php create mode 100644 src/Observers/DataUserObserverClearCache.php create mode 100644 src/Observers/GroupObserverCascadeDelete.php create mode 100644 src/Observers/GroupObserverClearCache.php create mode 100644 src/Observers/NotifyObservers/DataGroupNotifier.php create mode 100644 src/Observers/NotifyObservers/DataPositionNotifier.php create mode 100644 src/Observers/NotifyObservers/DataRoleNotifier.php create mode 100644 src/Observers/NotifyObservers/DataUserNotifier.php create mode 100644 src/Observers/NotifyObservers/Framework/Notifier.php create mode 100644 src/Observers/NotifyObservers/Framework/Observe.php create mode 100644 src/Observers/NotifyObservers/Framework/ObserverStore.php create mode 100644 src/Observers/NotifyObservers/GroupNotifier.php create mode 100644 src/Observers/NotifyObservers/Pivots/Tags/GroupGroupTagNotifier.php create mode 100644 src/Observers/NotifyObservers/Pivots/Tags/PositionPositionTagNotifier.php create mode 100644 src/Observers/NotifyObservers/Pivots/Tags/RoleRoleTagNotifier.php create mode 100644 src/Observers/NotifyObservers/Pivots/Tags/UserUserTagNotifier.php create mode 100644 src/Observers/NotifyObservers/Pivots/UserGroupNotifier.php create mode 100644 src/Observers/NotifyObservers/Pivots/UserRoleNotifier.php create mode 100644 src/Observers/NotifyObservers/PositionNotifier.php create mode 100644 src/Observers/NotifyObservers/RoleNotifier.php create mode 100644 src/Observers/NotifyObservers/Tags/GroupTagCategoryNotifier.php create mode 100644 src/Observers/NotifyObservers/Tags/GroupTagNotifier.php create mode 100644 src/Observers/NotifyObservers/Tags/PositionTagCategoryNotifier.php create mode 100644 src/Observers/NotifyObservers/Tags/PositionTagNotifier.php create mode 100644 src/Observers/NotifyObservers/Tags/RoleTagCategoryNotifier.php create mode 100644 src/Observers/NotifyObservers/Tags/RoleTagNotifier.php create mode 100644 src/Observers/NotifyObservers/Tags/UserTagCategoryNotifier.php create mode 100644 src/Observers/NotifyObservers/Tags/UserTagNotifier.php create mode 100644 src/Observers/NotifyObservers/UserNotifier.php create mode 100644 src/Observers/Pivots/Tags/GroupGroupTagObserverClearCache.php create mode 100644 src/Observers/Pivots/Tags/PositionPositionTagObserverClearCache.php create mode 100644 src/Observers/Pivots/Tags/RoleRoleTagObserverClearCache.php create mode 100644 src/Observers/Pivots/Tags/UserUserTagObserverClearCache.php create mode 100644 src/Observers/Pivots/UserGroupObserverClearCache.php create mode 100644 src/Observers/Pivots/UserRoleObserverClearCache.php create mode 100644 src/Observers/PositionObserverCascadeDelete.php create mode 100644 src/Observers/PositionObserverClearCache.php create mode 100644 src/Observers/RoleObserverCascadeDelete.php create mode 100644 src/Observers/RoleObserverClearCache.php create mode 100644 src/Observers/Tags/GroupTagCategoryObserverCascadeDelete.php create mode 100644 src/Observers/Tags/GroupTagCategoryObserverClearCache.php create mode 100644 src/Observers/Tags/GroupTagObserverCascadeDelete.php create mode 100644 src/Observers/Tags/GroupTagObserverClearCache.php create mode 100644 src/Observers/Tags/PositionTagCategoryObserverCascadeDelete.php create mode 100644 src/Observers/Tags/PositionTagCategoryObserverClearCache.php create mode 100644 src/Observers/Tags/PositionTagObserverCascadeDelete.php create mode 100644 src/Observers/Tags/PositionTagObserverClearCache.php create mode 100644 src/Observers/Tags/RoleTagCategoryObserverCascadeDelete.php create mode 100644 src/Observers/Tags/RoleTagCategoryObserverClearCache.php create mode 100644 src/Observers/Tags/RoleTagObserverCascadeDelete.php create mode 100644 src/Observers/Tags/RoleTagObserverClearCache.php create mode 100644 src/Observers/Tags/UserTagCategoryObserverCascadeDelete.php create mode 100644 src/Observers/Tags/UserTagCategoryObserverClearCache.php create mode 100644 src/Observers/Tags/UserTagObserverCascadeDelete.php create mode 100644 src/Observers/Tags/UserTagObserverClearCache.php create mode 100644 src/Observers/UserObserverCascadeDelete.php create mode 100644 src/Observers/UserObserverClearCache.php diff --git a/CHANGELOG.md b/CHANGELOG.md index f2cf463..78b2c96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Repositories to cache all get repository calls +- Observer framework for repositories +- Clear cache when needed +- Cascade deletes to preserve data integrity + ## [2.0] - (22/04/2020) ### Added diff --git a/src/Bootstrap/RegistersCachedRepositories.php b/src/Bootstrap/RegistersCachedRepositories.php new file mode 100644 index 0000000..1311002 --- /dev/null +++ b/src/Bootstrap/RegistersCachedRepositories.php @@ -0,0 +1,151 @@ +registerBase($app); + $this->registerData($app); + $this->registerTags($app); + $this->registerTagCategories($app); + $this->registerPivots($app); + + + } + + private function registerBase($app) + { + $app->extend(RoleRepositoryContract::class, function(RoleRepositoryContract $service, $app) { + return new RoleCacher($service, $app->make(Repository::class)); + }); + $app->extend(UserRepositoryContract::class, function(UserRepositoryContract $service, $app) { + return new UserCacher($service, $app->make(Repository::class)); + }); + $app->extend(GroupRepositoryContract::class, function(GroupRepositoryContract $service, $app) { + return new GroupCacher($service, $app->make(Repository::class)); + }); + $app->extend(PositionRepositoryContract::class, function(PositionRepositoryContract $service, $app) { + return new PositionCacher($service, $app->make(Repository::class)); + }); + } + + private function registerData($app) + { + $app->extend(DataRoleRepositoryContract::class, function(DataRoleRepositoryContract $service, $app) { + return new DataRoleCacher($service, $app->make(Repository::class)); + }); + $app->extend(DataUserRepositoryContract::class, function(DataUserRepositoryContract $service, $app) { + return new DataUserCacher($service, $app->make(Repository::class)); + }); + $app->extend(DataGroupRepositoryContract::class, function(DataGroupRepositoryContract $service, $app) { + return new DataGroupCacher($service, $app->make(Repository::class)); + }); + $app->extend(DataPositionRepositoryContract::class, function(DataPositionRepositoryContract $service, $app) { + return new DataPositionCacher($service, $app->make(Repository::class)); + }); + } + + private function registerTags($app) + { + $app->extend(GroupTag::class, function(GroupTag $service, $app) { + return new GroupTagCacher($service, $app->make(Repository::class)); + }); + $app->extend(UserTag::class, function(UserTag $service, $app) { + return new UserTagCacher($service, $app->make(Repository::class)); + }); + $app->extend(RoleTag::class, function(RoleTag $service, $app) { + return new RoleTagCacher($service, $app->make(Repository::class)); + }); + $app->extend(PositionTag::class, function(PositionTag $service, $app) { + return new PositionTagCacher($service, $app->make(Repository::class)); + }); + } + + private function registerTagCategories($app) + { + $app->extend(GroupTagCategory::class, function(GroupTagCategory $service, $app) { + return new GroupTagCategoryCacher($service, $app->make(Repository::class)); + }); + $app->extend(UserTagCategory::class, function(UserTagCategory $service, $app) { + return new UserTagCategoryCacher($service, $app->make(Repository::class)); + }); + $app->extend(RoleTagCategory::class, function(RoleTagCategory $service, $app) { + return new RoleTagCategoryCacher($service, $app->make(Repository::class)); + }); + $app->extend(PositionTagCategory::class, function(PositionTagCategory $service, $app) { + return new PositionTagCategoryCacher($service, $app->make(Repository::class)); + }); + } + + private function registerPivots($app) + { + $app->extend(GroupGroupTag::class, function(GroupGroupTag $service, $app) { + return new GroupGroupTagCacher($service, $app->make(Repository::class)); + }); + $app->extend(RoleRoleTag::class, function(RoleRoleTag $service, $app) { + return new RoleRoleTagCacher($service, $app->make(Repository::class)); + }); + $app->extend(UserUserTag::class, function(UserUserTag $service, $app) { + return new UserUserTagCacher($service, $app->make(Repository::class)); + }); + $app->extend(PositionPositionTag::class, function(PositionPositionTag $service, $app) { + return new PositionPositionTagCacher($service, $app->make(Repository::class)); + }); + $app->extend(UserGroup::class, function(UserGroup $service, $app) { + return new UserGroupCacher($service, $app->make(Repository::class)); + }); + $app->extend(UserRole::class, function(UserRole $service, $app) { + return new UserRoleCacher($service, $app->make(Repository::class)); + }); + } +} \ No newline at end of file diff --git a/src/Bootstrap/RegistersObserverFramework.php b/src/Bootstrap/RegistersObserverFramework.php new file mode 100644 index 0000000..723803a --- /dev/null +++ b/src/Bootstrap/RegistersObserverFramework.php @@ -0,0 +1,151 @@ +registerBaseObserver($app); + $this->registerDataObserver($app); + $this->registerTagsObserver($app); + $this->registerTagCategoriesObserver($app); + $this->registerPivotsObserver($app); + + + } + + private function registerBaseObserver($app) + { + $app->extend(RoleRepositoryContract::class, function(RoleRepositoryContract $service, $app) { + return new RoleNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(UserRepositoryContract::class, function(UserRepositoryContract $service, $app) { + return new UserNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(GroupRepositoryContract::class, function(GroupRepositoryContract $service, $app) { + return new GroupNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(PositionRepositoryContract::class, function(PositionRepositoryContract $service, $app) { + return new PositionNotifier($service, $app->make(ObserverStore::class)); + }); + } + + private function registerDataObserver($app) + { + $app->extend(DataRoleRepositoryContract::class, function(DataRoleRepositoryContract $service, $app) { + return new DataRoleNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(DataUserRepositoryContract::class, function(DataUserRepositoryContract $service, $app) { + return new DataUserNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(DataGroupRepositoryContract::class, function(DataGroupRepositoryContract $service, $app) { + return new DataGroupNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(DataPositionRepositoryContract::class, function(DataPositionRepositoryContract $service, $app) { + return new DataPositionNotifier($service, $app->make(ObserverStore::class)); + }); + } + + private function registerTagsObserver($app) + { + $app->extend(GroupTag::class, function(GroupTag $service, $app) { + return new GroupTagNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(UserTag::class, function(UserTag $service, $app) { + return new UserTagNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(RoleTag::class, function(RoleTag $service, $app) { + return new RoleTagNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(PositionTag::class, function(PositionTag $service, $app) { + return new PositionTagNotifier($service, $app->make(ObserverStore::class)); + }); + } + + private function registerTagCategoriesObserver($app) + { + $app->extend(GroupTagCategory::class, function(GroupTagCategory $service, $app) { + return new GroupTagCategoryNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(UserTagCategory::class, function(UserTagCategory $service, $app) { + return new UserTagCategoryNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(RoleTagCategory::class, function(RoleTagCategory $service, $app) { + return new RoleTagCategoryNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(PositionTagCategory::class, function(PositionTagCategory $service, $app) { + return new PositionTagCategoryNotifier($service, $app->make(ObserverStore::class)); + }); + } + + private function registerPivotsObserver($app) + { + $app->extend(GroupGroupTag::class, function(GroupGroupTag $service, $app) { + return new GroupGroupTagNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(RoleRoleTag::class, function(RoleRoleTag $service, $app) { + return new RoleRoleTagNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(UserUserTag::class, function(UserUserTag $service, $app) { + return new UserUserTagNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(PositionPositionTag::class, function(PositionPositionTag $service, $app) { + return new PositionPositionTagNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(UserGroup::class, function(UserGroup $service, $app) { + return new UserGroupNotifier($service, $app->make(ObserverStore::class)); + }); + $app->extend(UserRole::class, function(UserRole $service, $app) { + return new UserRoleNotifier($service, $app->make(ObserverStore::class)); + }); + } +} \ No newline at end of file diff --git a/src/Cache/DataGroup.php b/src/Cache/DataGroup.php new file mode 100644 index 0000000..99215de --- /dev/null +++ b/src/Cache/DataGroup.php @@ -0,0 +1,87 @@ +dataGroupRepository = $dataGroupRepository; + $this->cache = $cache; + } + + /** + * Get a data group by ID + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\DataGroup + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataGroup + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->dataGroupRepository->getById($id); + }); + } + + /** + * Get a data group where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return \BristolSU\ControlDB\Contracts\Models\DataGroup + */ + public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Models\DataGroup + { + return $this->dataGroupRepository->getWhere($attributes); + } + + /** + * Get all data groups where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return Collection|\BristolSU\ControlDB\Contracts\Models\DataGroup[] + */ + public function getAllWhere($attributes = []): Collection + { + return $this->dataGroupRepository->getAllWhere($attributes); + } + + /** + * Create a data group with the given attributes + * + * @param string|null $name Name of the group + * @param string|null $email Email of the group + * + * @return \BristolSU\ControlDB\Contracts\Models\DataGroup + */ + public function create(?string $name = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataGroup + { + return $this->dataGroupRepository->create($name, $email); + } + + /** + * Update a group with the given attributes + * + * @param int $id + * @param string|null $name Name of the group + * @param string|null $email Email of the group + * @return \BristolSU\ControlDB\Contracts\Models\DataGroup + */ + public function update(int $id, ?string $name = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataGroup + { + return $this->dataGroupRepository->update($id, $name, $email); + } +} \ No newline at end of file diff --git a/src/Cache/DataPosition.php b/src/Cache/DataPosition.php new file mode 100644 index 0000000..ca60584 --- /dev/null +++ b/src/Cache/DataPosition.php @@ -0,0 +1,87 @@ +dataPositionRepository = $dataPositionRepository; + $this->cache = $cache; + } + + /** + * Get a data position by ID + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\DataPosition + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataPosition + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->dataPositionRepository->getById($id); + }); + } + + /** + * Get a data position where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return \BristolSU\ControlDB\Contracts\Models\DataPosition + */ + public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Models\DataPosition + { + return $this->dataPositionRepository->getWhere($attributes); + } + + /** + * Get all data positions where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return Collection|\BristolSU\ControlDB\Contracts\Models\DataPosition[] + */ + public function getAllWhere($attributes = []): Collection + { + return $this->dataPositionRepository->getAllWhere($attributes); + } + + + /** + * Create a data position with the given attributes + * + * @param string|null $name Name of the position + * @param string|null $description Description of the position + * @return \BristolSU\ControlDB\Contracts\Models\DataPosition + */ + public function create(?string $name = null, ?string $description = null): \BristolSU\ControlDB\Contracts\Models\DataPosition + { + return $this->dataPositionRepository->create($name, $description); + } + + /** + * Update a data position with the given attributes + * + * @param int $id + * @param string|null $name Name of the position + * @param string|null $description Description of the position + * @return \BristolSU\ControlDB\Contracts\Models\DataPosition + */ + public function update(int $id, ?string $name = null, ?string $description = null): \BristolSU\ControlDB\Contracts\Models\DataPosition + { + return $this->dataPositionRepository->update($id, $name, $description); + } +} \ No newline at end of file diff --git a/src/Cache/DataRole.php b/src/Cache/DataRole.php new file mode 100644 index 0000000..6891c4a --- /dev/null +++ b/src/Cache/DataRole.php @@ -0,0 +1,86 @@ +dataRoleRepository = $dataRoleRepository; + $this->cache = $cache; + } + + /** + * Get a data role by ID + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\DataRole + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataRole + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->dataRoleRepository->getById($id); + }); + } + + /** + * Get a data role where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return \BristolSU\ControlDB\Contracts\Models\DataRole + */ + public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Models\DataRole + { + return $this->dataRoleRepository->getWhere($attributes); + } + + /** + * Get all data roles where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return Collection|\BristolSU\ControlDB\Contracts\Models\DataRole[] + */ + public function getAllWhere($attributes = []): Collection + { + return $this->dataRoleRepository->getAllWhere($attributes); + } + + /** + * Create a data position with the given attributes + * + * @param string|null $roleName Custom name for the role + * @param string|null $email Email of the role + * @return \BristolSU\ControlDB\Contracts\Models\DataRole + */ + public function create(?string $roleName = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataRole + { + return $this->dataRoleRepository->create($roleName, $email); + } + + /** + * Update a data position with the given attributes + * + * @param int $id + * @param string|null $roleName Custom name for the role + * @param string|null $email Email of the role + * @return \BristolSU\ControlDB\Contracts\Models\DataRole + */ + public function update(int $id, ?string $roleName = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataRole + { + return $this->dataRoleRepository->update($id, $roleName, $email); + } +} \ No newline at end of file diff --git a/src/Cache/DataUser.php b/src/Cache/DataUser.php new file mode 100644 index 0000000..11d3e66 --- /dev/null +++ b/src/Cache/DataUser.php @@ -0,0 +1,93 @@ +dataUserRepository = $dataUserRepository; + $this->cache = $cache; + } + + /** + * Get a data user by ID + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\DataUser + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataUser + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->dataUserRepository->getById($id); + }); + } + + /** + * Get a data user where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return \BristolSU\ControlDB\Contracts\Models\DataUser + */ + public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Models\DataUser + { + return $this->dataUserRepository->getWhere($attributes); + } + + /** + * Get all data users where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return Collection|\BristolSU\ControlDB\Contracts\Models\DataUser[] + */ + public function getAllWhere($attributes = []): Collection + { + return $this->dataUserRepository->getAllWhere($attributes); + } + + /** + * Create a data user with the given attributes + * + * @param string|null $firstName First name of the user + * @param string|null $lastName Last name of the user + * @param string|null $email Email of the user + * @param \DateTime|null $dob Date of birth of the user + * @param string|null $preferredName Preferred name of the user + * + * @return \BristolSU\ControlDB\Contracts\Models\DataUser + */ + public function create(?string $firstName = null, ?string $lastName = null, ?string $email = null, ?\DateTime $dob = null, ?string $preferredName = null): \BristolSU\ControlDB\Contracts\Models\DataUser + { + return $this->dataUserRepository->create($firstName, $lastName, $email, $dob, $preferredName); + } + + /** + * Update a data user + * + * @param int $id + * @param string|null $firstName + * @param string|null $lastName + * @param string|null $email + * @param \DateTime|null $dob + * @param string|null $preferredName + * @return \BristolSU\ControlDB\Contracts\Models\DataUser + */ + public function update(int $id, ?string $firstName = null, ?string $lastName = null, ?string $email = null, ?\DateTime $dob = null, ?string $preferredName = null): \BristolSU\ControlDB\Contracts\Models\DataUser + { + return $this->dataUserRepository->update($id, $firstName, $lastName, $email, $dob, $preferredName); + } +} \ No newline at end of file diff --git a/src/Cache/Group.php b/src/Cache/Group.php new file mode 100644 index 0000000..dd1e25f --- /dev/null +++ b/src/Cache/Group.php @@ -0,0 +1,121 @@ +groupRepository = $groupRepository; + $this->cache = $cache; + } + + /** + * Get a group by ID + * + * @param int $id ID of the group + * @return GroupModel + */ + public function getById(int $id): GroupModel + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->groupRepository->getById($id); + }); + } + + /** + * Get a group by its data provider ID + * + * @param int $dataProviderId + * @return GroupModel + */ + public function getByDataProviderId(int $dataProviderId): GroupModel + { + return $this->cache->rememberForever(static::class . '@getByDataProviderId:' . $dataProviderId, function() use ($dataProviderId) { + return $this->groupRepository->getByDataProviderId($dataProviderId); + }); + } + + /** + * Get all groups + * + * @return Collection|GroupModel[] + */ + public function all(): Collection + { + return $this->groupRepository->all(); + } + + /** + * Create a new group + * + * @param int $dataProviderId + * @return GroupModel + */ + public function create(int $dataProviderId): GroupModel + { + return $this->groupRepository->create($dataProviderId); + } + + /** + * Delete a group by ID + * + * @param int $id + */ + public function delete(int $id): void + { + $this->groupRepository->delete($id); + } + + /** + * Paginate through all the groups + * + * @param int $page The page number to return + * @param int $perPage The number of results to return per page + * + * @return Collection|GroupModel[] + */ + public function paginate(int $page, int $perPage): Collection + { + return $this->groupRepository->paginate($page, $perPage); + } + + /** + * Get the number of groups + * + * @return int + */ + public function count(): int + { + return $this->cache->rememberForever(static::class . '@count', function() { + return $this->groupRepository->count(); + }); + } + + /** + * Update the group model + * + * @param int $id + * @param int $dataProviderId New data provider ID + * @return GroupModel + */ + public function update(int $id, int $dataProviderId): GroupModel + { + return $this->groupRepository->update($id, $dataProviderId); + } +} \ No newline at end of file diff --git a/src/Cache/Pivots/Tags/GroupGroupTag.php b/src/Cache/Pivots/Tags/GroupGroupTag.php new file mode 100644 index 0000000..aefa40e --- /dev/null +++ b/src/Cache/Pivots/Tags/GroupGroupTag.php @@ -0,0 +1,77 @@ +groupGroupTagRepository = $groupGroupTagRepository; + $this->cache = $cache; + } + + /** + * Tag a group + * + * @param GroupTag $groupTag Tag to tag the group with + * @param Group $group Group to tag + * @return void + */ + public function addTagToGroup(GroupTag $groupTag, Group $group): void + { + $this->groupGroupTagRepository->addTagToGroup($groupTag, $group); + } + + /** + * Remove a tag from a group + * + * @param GroupTag $groupTag Tag to remove from the group + * @param Group $group Group to remove the tag from + * @return void + */ + public function removeTagFromGroup(GroupTag $groupTag, Group $group): void + { + $this->groupGroupTagRepository->removeTagFromGroup($groupTag, $group); + } + + /** + * Get all tags a group is tagged with + * + * @param Group $group Group to retrieve tags from + * @return Collection|GroupTag[] Tags the group is tagged with + */ + public function getTagsThroughGroup(Group $group): Collection + { + return $this->cache->rememberForever(static::class . '@getTagsThroughGroup:' . $group->id(), function() use ($group) { + return $this->groupGroupTagRepository->getTagsThroughGroup($group); + }); + } + + /** + * Get all groups tagged with a tag + * + * @param GroupTag $groupTag Tag to use to retrieve groups + * @return Collection|Group[] Groups tagged with the given tag + */ + public function getGroupsThroughTag(GroupTag $groupTag): Collection + { + return $this->cache->rememberForever(static::class . '@getGroupsThroughTag:' . $groupTag->id(), function() use ($groupTag) { + return $this->groupGroupTagRepository->getGroupsThroughTag($groupTag); + }); + } +} \ No newline at end of file diff --git a/src/Cache/Pivots/Tags/PositionPositionTag.php b/src/Cache/Pivots/Tags/PositionPositionTag.php new file mode 100644 index 0000000..b20eb6b --- /dev/null +++ b/src/Cache/Pivots/Tags/PositionPositionTag.php @@ -0,0 +1,77 @@ +positionPositionTagRepository = $positionPositionTagRepository; + $this->cache = $cache; + } + + /** + * Tag a position + * + * @param PositionTag $positionTag Tag to tag the position with + * @param Position $position Position to tag + * @return void + */ + public function addTagToPosition(PositionTag $positionTag, Position $position): void + { + $this->positionPositionTagRepository->addTagToPosition($positionTag, $position); + } + + /** + * Remove a tag from a position + * + * @param PositionTag $positionTag Tag to remove from the position + * @param Position $position Position to remove the tag from + * @return void + */ + public function removeTagFromPosition(PositionTag $positionTag, Position $position): void + { + $this->positionPositionTagRepository->removeTagFromPosition($positionTag, $position); + } + + /** + * Get all tags a position is tagged with + * + * @param Position $position Position to retrieve tags from + * @return Collection|PositionTag[] Tags the position is tagged with + */ + public function getTagsThroughPosition(Position $position): Collection + { + return $this->cache->rememberForever(static::class . '@getTagsThroughPosition:' . $position->id(), function() use ($position) { + return $this->positionPositionTagRepository->getTagsThroughPosition($position); + }); + } + + /** + * Get all positions tagged with a tag + * + * @param PositionTag $positionTag Tag to use to retrieve positions + * @return Collection|Position[] Positions tagged with the given tag + */ + public function getPositionsThroughTag(PositionTag $positionTag): Collection + { + return $this->cache->rememberForever(static::class . '@getPositionsThroughTag:' . $positionTag->id(), function() use ($positionTag) { + return $this->positionPositionTagRepository->getPositionsThroughTag($positionTag); + }); + } +} \ No newline at end of file diff --git a/src/Cache/Pivots/Tags/RoleRoleTag.php b/src/Cache/Pivots/Tags/RoleRoleTag.php new file mode 100644 index 0000000..b2f9840 --- /dev/null +++ b/src/Cache/Pivots/Tags/RoleRoleTag.php @@ -0,0 +1,77 @@ +roleRoleTagRepository = $roleRoleTagRepository; + $this->cache = $cache; + } + + /** + * Tag a role + * + * @param RoleTag $roleTag Tag to tag the role with + * @param Role $role Role to tag + * @return void + */ + public function addTagToRole(RoleTag $roleTag, Role $role): void + { + $this->roleRoleTagRepository->addTagToRole($roleTag, $role); + } + + /** + * Remove a tag from a role + * + * @param RoleTag $roleTag Tag to remove from the role + * @param Role $role Role to remove the tag from + * @return void + */ + public function removeTagFromRole(RoleTag $roleTag, Role $role): void + { + $this->roleRoleTagRepository->removeTagFromRole($roleTag, $role); + } + + /** + * Get all tags a role is tagged with + * + * @param Role $role Role to retrieve tags from + * @return Collection|RoleTag[] Tags the role is tagged with + */ + public function getTagsThroughRole(Role $role): Collection + { + return $this->cache->rememberForever(static::class . '@getTagsThroughRole:' . $role->id(), function() use ($role) { + return $this->roleRoleTagRepository->getTagsThroughRole($role); + }); + } + + /** + * Get all roles tagged with a tag + * + * @param RoleTag $roleTag Tag to use to retrieve roles + * @return Collection|Role[] Roles tagged with the given tag + */ + public function getRolesThroughTag(RoleTag $roleTag): Collection + { + return $this->cache->rememberForever(static::class . '@getRolesThroughTag:' . $roleTag->id(), function() use ($roleTag) { + return $this->roleRoleTagRepository->getRolesThroughTag($roleTag); + }); + } +} \ No newline at end of file diff --git a/src/Cache/Pivots/Tags/UserUserTag.php b/src/Cache/Pivots/Tags/UserUserTag.php new file mode 100644 index 0000000..bf11976 --- /dev/null +++ b/src/Cache/Pivots/Tags/UserUserTag.php @@ -0,0 +1,77 @@ +userUserTagRepository = $userUserTagRepository; + $this->cache = $cache; + } + + /** + * Tag a user + * + * @param UserTag $userTag Tag to tag the user with + * @param User $user User to tag + * @return void + */ + public function addTagToUser(UserTag $userTag, User $user): void + { + $this->userUserTagRepository->addTagToUser($userTag, $user); + } + + /** + * Remove a tag from a user + * + * @param UserTag $userTag Tag to remove from the user + * @param User $user User to remove the tag from + * @return void + */ + public function removeTagFromUser(UserTag $userTag, User $user): void + { + $this->userUserTagRepository->removeTagFromUser($userTag, $user); + } + + /** + * Get all tags a user is tagged with + * + * @param User $user User to retrieve tags from + * @return Collection|UserTag[] Tags the user is tagged with + */ + public function getTagsThroughUser(User $user): Collection + { + return $this->cache->rememberForever(static::class . '@getTagsThroughUser:' . $user->id(), function() use ($user) { + return $this->userUserTagRepository->getTagsThroughUser($user); + }); + } + + /** + * Get all users tagged with a tag + * + * @param UserTag $userTag Tag to use to retrieve users + * @return Collection|User[] Users tagged with the given tag + */ + public function getUsersThroughTag(UserTag $userTag): Collection + { + return $this->cache->rememberForever(static::class . '@getUsersThroughTag:' . $userTag->id(), function() use ($userTag) { + return $this->userUserTagRepository->getUsersThroughTag($userTag); + }); + } +} \ No newline at end of file diff --git a/src/Cache/Pivots/UserGroup.php b/src/Cache/Pivots/UserGroup.php new file mode 100644 index 0000000..156a240 --- /dev/null +++ b/src/Cache/Pivots/UserGroup.php @@ -0,0 +1,77 @@ +userGroup = $userGroup; + $this->cache = $cache; + } + + /** + * Get all users who are members of a group + * + * @param Group $group + * @return User[]|Collection Users who are members of the group + */ + public function getUsersThroughGroup(Group $group): Collection + { + return $this->cache->rememberForever(static::class . '@getUsersThroughGroup:' . $group->id(), function() use ($group) { + return $this->userGroup->getUsersThroughGroup($group); + }); + } + + /** + * Get all groups a user belongs to + * + * @param User $user + * @return Group[]|Collection Groups the user is a member of + */ + public function getGroupsThroughUser(User $user): Collection + { + return $this->cache->rememberForever(static::class . '@getGroupsThroughUser:' . $user->id(), function() use ($user) { + return $this->userGroup->getGroupsThroughUser($user); + }); + } + + /** + * Add a user to a group + * + * @param User $user User to add to the group + * @param Group $group Group to add the user to + * @return void + */ + public function addUserToGroup(User $user, Group $group): void + { + $this->userGroup->addUserToGroup($user, $group); + } + + /** + * Remove a user from a group + * @param User $user User to remove from the group + * @param Group $group Group to remove the user from + * @return void + */ + public function removeUserFromGroup(User $user, Group $group): void + { + $this->userGroup->removeUserFromGroup($user, $group); + } +} \ No newline at end of file diff --git a/src/Cache/Pivots/UserRole.php b/src/Cache/Pivots/UserRole.php new file mode 100644 index 0000000..4044269 --- /dev/null +++ b/src/Cache/Pivots/UserRole.php @@ -0,0 +1,78 @@ +userRole = $userRole; + $this->cache = $cache; + } + + /** + * Get all users who are members of a role + * + * @param Role $role + * @return User[]|Collection Users who are members of the role + */ + public function getUsersThroughRole(Role $role): Collection + { + return $this->cache->rememberForever(static::class . '@getUsersThroughRole:' . $role->id(), function() use ($role) { + return $this->userRole->getUsersThroughRole($role); + }); + } + + /** + * Get all roles a user belongs to + * + * @param User $user + * @return Role[]|Collection Roles the user is a member of + */ + public function getRolesThroughUser(User $user): Collection + { + return $this->cache->rememberForever(static::class . '@getRolesThroughUser:' . $user->id(), function() use ($user) { + return $this->userRole->getRolesThroughUser($user); + }); + } + + /** + * Add a user to a role + * + * @param User $user User to add to the role + * @param Role $role Role to add the user to + * @return void + */ + public function addUserToRole(User $user, Role $role): void + { + $this->userRole->addUserToRole($user, $role); + } + + /** + * Remove a user from a role + * @param User $user User to remove from the role + * @param Role $role Role to remove the user from + * @return void + */ + public function removeUserFromRole(User $user, Role $role): void + { + $this->userRole->removeUserFromRole($user, $role); + } + +} \ No newline at end of file diff --git a/src/Cache/Position.php b/src/Cache/Position.php new file mode 100644 index 0000000..600686a --- /dev/null +++ b/src/Cache/Position.php @@ -0,0 +1,122 @@ +positionRepository = $positionRepository; + $this->cache = $cache; + } + + /** + * Get a position by ID + * + * @param int $id ID of the position + * @return PositionModel + */ + public function getById(int $id): PositionModel + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->positionRepository->getById($id); + }); + } + + /** + * Get a position by its data provider ID + * + * @param int $dataProviderId + * @return PositionModel + */ + public function getByDataProviderId(int $dataProviderId): PositionModel + { + return $this->cache->rememberForever(static::class . '@getByDataProviderId:' . $dataProviderId, function() use ($dataProviderId) { + return $this->positionRepository->getByDataProviderId($dataProviderId); + }); + } + + /** + * Get all positions + * + * @return Collection|PositionModel[] + */ + public function all(): Collection + { + return $this->positionRepository->all(); + } + + /** + * Create a new position + * + * @param int $dataProviderId + * @return PositionModel + */ + public function create(int $dataProviderId): PositionModel + { + return $this->positionRepository->create($dataProviderId); + } + + /** + * Delete a position by ID + * + * @param int $id + */ + public function delete(int $id): void + { + $this->positionRepository->delete($id); + } + + /** + * Paginate through all the positions + * + * @param int $page The page number to return + * @param int $perPage The number of results to return per page + * + * @return Collection|PositionModel[] + */ + public function paginate(int $page, int $perPage): Collection + { + return $this->positionRepository->paginate($page, $perPage); + } + + /** + * Get the number of positions + * + * @return int + */ + public function count(): int + { + return $this->cache->rememberForever(static::class . '@count', function() { + return $this->positionRepository->count(); + }); + } + + /** + * Update the position model + * + * @param int $id + * @param int $dataProviderId New data provider ID + * @return PositionModel + */ + public function update(int $id, int $dataProviderId): PositionModel + { + return $this->positionRepository->update($id, $dataProviderId); + } +} \ No newline at end of file diff --git a/src/Cache/Role.php b/src/Cache/Role.php index c79fd18..e9c760b 100644 --- a/src/Cache/Role.php +++ b/src/Cache/Role.php @@ -30,7 +30,7 @@ public function __construct(RoleRepositoryContract $roleRepository, Repository $ */ public function getById(int $id): RoleModel { - return $this->cache->remember(static::class . '@getById:' . $id, 5000, function() use ($id) { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { return $this->roleRepository->getById($id); }); } @@ -48,7 +48,7 @@ public function all(): Collection */ public function getByDataProviderId(int $dataProviderId): RoleModel { - return $this->cache->remember(static::class . '@getByDataProviderId:' . $dataProviderId, 5000, function() use ($dataProviderId) { + return $this->cache->rememberForever(static::class . '@getByDataProviderId:' . $dataProviderId, function() use ($dataProviderId) { return $this->roleRepository->getByDataProviderId($dataProviderId); }); } @@ -74,7 +74,9 @@ public function delete(int $id): void */ public function allThroughGroup(\BristolSU\ControlDB\Contracts\Models\Group $group): Collection { - return $this->roleRepository->allThroughGroup($group); + return $this->cache->rememberForever(static::class . '@allThroughGroup:' . $group->id(), function() use ($group) { + return $this->roleRepository->allThroughGroup($group); + }); } /** @@ -82,7 +84,9 @@ public function allThroughGroup(\BristolSU\ControlDB\Contracts\Models\Group $gro */ public function allThroughPosition(\BristolSU\ControlDB\Contracts\Models\Position $position): Collection { - return $this->roleRepository->allThroughPosition($position); + return $this->cache->rememberForever(static::class . '@allThroughPosition:' . $position->id(), function() use ($position) { + return $this->roleRepository->allThroughPosition($position); + }); } /** @@ -105,6 +109,23 @@ public function paginate(int $page, int $perPage): Collection */ public function count(): int { - return $this->roleRepository->count(); + return $this->cache->rememberForever(static::class . '@count', function() { + return $this->roleRepository->count(); + }); + + } + + /** + * Update the role model + * + * @param int $id + * @param int $positionId + * @param int $groupId + * @param int $dataProviderId New data provider ID + * @return RoleModel + */ + public function update(int $id, int $positionId, int $groupId, int $dataProviderId): RoleModel + { + return $this->roleRepository->update($id, $positionId, $groupId, $dataProviderId); } } \ No newline at end of file diff --git a/src/Cache/Tags/GroupTag.php b/src/Cache/Tags/GroupTag.php new file mode 100644 index 0000000..d7ddc99 --- /dev/null +++ b/src/Cache/Tags/GroupTag.php @@ -0,0 +1,116 @@ +groupTagRepository = $groupTagRepository; + $this->cache = $cache; + } + + /** + * Get all group tags + * + * @return Collection|\BristolSU\ControlDB\Contracts\Models\Tags\GroupTag[] + */ + public function all(): Collection + { + return $this->groupTagRepository->all(); + } + + /** + * Get a tag by the full reference + * + * The full reference looks like 'tag_category_ref.tag_ref' + * + * @param string $reference + * @return \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + */ + public function getTagByFullReference(string $reference): \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + { + return $this->cache->rememberForever(static::class . '@getTagByFullReference:' . $reference, function() use ($reference) { + return $this->groupTagRepository->getTagByFullReference($reference); + }); + } + + /** + * Get a group tag by id + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->groupTagRepository->getById($id); + }); + } + + /** + * Create a group tag + * + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + */ + public function create(string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + { + return $this->groupTagRepository->create($name, $description, $reference, $tagCategoryId); + } + + /** + * Delete a group tag + * + * @param int $id ID of the tag to delete + */ + public function delete(int $id): void + { + $this->groupTagRepository->delete($id); + } + + /** + * Get all tags through a tag category + * + * @param \BristolSU\ControlDB\Contracts\Models\Tags\GroupTagCategory $groupTagCategory + * @return Collection|GroupTagRepository Tags with the given group tag category + */ + public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags\GroupTagCategory $groupTagCategory): Collection + { + return $this->cache->rememberForever(static::class . '@allThroughTagCategory:' . $groupTagCategory->id(), function() use ($groupTagCategory) { + return $this->groupTagRepository->allThroughTagCategory($groupTagCategory); + }); + } + + /** + * Update a group tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + { + return $this->groupTagRepository->update($id, $name, $description, $reference, $tagCategoryId); + } +} \ No newline at end of file diff --git a/src/Cache/Tags/GroupTagCategory.php b/src/Cache/Tags/GroupTagCategory.php new file mode 100644 index 0000000..ffcd85e --- /dev/null +++ b/src/Cache/Tags/GroupTagCategory.php @@ -0,0 +1,100 @@ +groupTagCategoryRepository = $groupTagCategoryRepository; + $this->cache = $cache; + } + + /** + * Get all group tag categories + * + * @return Collection|GroupTagCategoryModel[] + */ + public function all(): Collection + { + return $this->groupTagCategoryRepository->all(); + } + + /** + * Get a tag category by the reference + * + * @param string $reference Reference of the tag + * @return GroupTagCategoryModel + */ + public function getByReference(string $reference): GroupTagCategoryModel + { + return $this->cache->rememberForever(static::class . '@getByReference:' . $reference, function() use ($reference) { + return $this->groupTagCategoryRepository->getByReference($reference); + }); + } + + /** + * Get a group tag category by id + * + * @param int $id + * @return GroupTagCategoryModel + */ + public function getById(int $id): GroupTagCategoryModel + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->groupTagCategoryRepository->getById($id); + }); + } + + /** + * Delete a group tag category + * + * @param int $id ID of the group tag category to delete + */ + public function delete(int $id): void + { + $this->groupTagCategoryRepository->delete($id); + } + + /** + * Create a group tag category + * + * @param string $name Name of the group tag category + * @param string $description Description of the group tag category + * @param string $reference Reference of the group tag category + * @return GroupTagCategoryModel New group tag category + */ + public function create(string $name, string $description, string $reference): GroupTagCategoryModel + { + return $this->groupTagCategoryRepository->create($name, $description, $reference); + } + + /** + * Update a group tag category + * + * @param int $id + * @param string $name Name of the group tag category + * @param string $description Description of the group tag category + * @param string $reference Reference of the group tag category + * @return GroupTagCategoryModel Updated group tag category + */ + public function update(int $id, string $name, string $description, string $reference): GroupTagCategoryModel + { + return $this->groupTagCategoryRepository->update($id, $name, $description, $reference); + } +} \ No newline at end of file diff --git a/src/Cache/Tags/PositionTag.php b/src/Cache/Tags/PositionTag.php new file mode 100644 index 0000000..5a876ef --- /dev/null +++ b/src/Cache/Tags/PositionTag.php @@ -0,0 +1,116 @@ +positionTagRepository = $positionTagRepository; + $this->cache = $cache; + } + + /** + * Get all position tags + * + * @return Collection|\BristolSU\ControlDB\Contracts\Models\Tags\PositionTag[] + */ + public function all(): Collection + { + return $this->positionTagRepository->all(); + } + + /** + * Get a tag by the full reference + * + * The full reference looks like 'tag_category_ref.tag_ref' + * + * @param string $reference + * @return \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + */ + public function getTagByFullReference(string $reference): \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + { + return $this->cache->rememberForever(static::class . '@getTagByFullReference:' . $reference, function() use ($reference) { + return $this->positionTagRepository->getTagByFullReference($reference); + }); + } + + /** + * Get a position tag by id + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->positionTagRepository->getById($id); + }); + } + + /** + * Create a position tag + * + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + */ + public function create(string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + { + return $this->positionTagRepository->create($name, $description, $reference, $tagCategoryId); + } + + /** + * Delete a position tag + * + * @param int $id ID of the tag to delete + */ + public function delete(int $id): void + { + $this->positionTagRepository->delete($id); + } + + /** + * Get all tags through a tag category + * + * @param \BristolSU\ControlDB\Contracts\Models\Tags\PositionTagCategory $positionTagCategory + * @return Collection|PositionTagRepository Tags with the given position tag category + */ + public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags\PositionTagCategory $positionTagCategory): Collection + { + return $this->cache->rememberForever(static::class . '@allThroughTagCategory:' . $positionTagCategory->id(), function() use ($positionTagCategory) { + return $this->positionTagRepository->allThroughTagCategory($positionTagCategory); + }); + } + + /** + * Update a position tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + { + return $this->positionTagRepository->update($id, $name, $description, $reference, $tagCategoryId); + } +} \ No newline at end of file diff --git a/src/Cache/Tags/PositionTagCategory.php b/src/Cache/Tags/PositionTagCategory.php new file mode 100644 index 0000000..19c1975 --- /dev/null +++ b/src/Cache/Tags/PositionTagCategory.php @@ -0,0 +1,100 @@ +positionTagCategoryRepository = $positionTagCategoryRepository; + $this->cache = $cache; + } + + /** + * Get all position tag categories + * + * @return Collection|PositionTagCategoryModel[] + */ + public function all(): Collection + { + return $this->positionTagCategoryRepository->all(); + } + + /** + * Get a tag category by the reference + * + * @param string $reference Reference of the tag + * @return PositionTagCategoryModel + */ + public function getByReference(string $reference): PositionTagCategoryModel + { + return $this->cache->rememberForever(static::class . '@getByReference:' . $reference, function() use ($reference) { + return $this->positionTagCategoryRepository->getByReference($reference); + }); + } + + /** + * Get a position tag category by id + * + * @param int $id + * @return PositionTagCategoryModel + */ + public function getById(int $id): PositionTagCategoryModel + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->positionTagCategoryRepository->getById($id); + }); + } + + /** + * Delete a position tag category + * + * @param int $id ID of the position tag category to delete + */ + public function delete(int $id): void + { + $this->positionTagCategoryRepository->delete($id); + } + + /** + * Create a position tag category + * + * @param string $name Name of the position tag category + * @param string $description Description of the position tag category + * @param string $reference Reference of the position tag category + * @return PositionTagCategoryModel New position tag category + */ + public function create(string $name, string $description, string $reference): PositionTagCategoryModel + { + return $this->positionTagCategoryRepository->create($name, $description, $reference); + } + + /** + * Update a position tag category + * + * @param int $id + * @param string $name Name of the position tag category + * @param string $description Description of the position tag category + * @param string $reference Reference of the position tag category + * @return PositionTagCategoryModel Updated position tag category + */ + public function update(int $id, string $name, string $description, string $reference): PositionTagCategoryModel + { + return $this->positionTagCategoryRepository->update($id, $name, $description, $reference); + } +} \ No newline at end of file diff --git a/src/Cache/Tags/RoleTag.php b/src/Cache/Tags/RoleTag.php new file mode 100644 index 0000000..d1ab7e4 --- /dev/null +++ b/src/Cache/Tags/RoleTag.php @@ -0,0 +1,116 @@ +roleTagRepository = $roleTagRepository; + $this->cache = $cache; + } + + /** + * Get all role tags + * + * @return Collection|\BristolSU\ControlDB\Contracts\Models\Tags\RoleTag[] + */ + public function all(): Collection + { + return $this->roleTagRepository->all(); + } + + /** + * Get a tag by the full reference + * + * The full reference looks like 'tag_category_ref.tag_ref' + * + * @param string $reference + * @return \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + */ + public function getTagByFullReference(string $reference): \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + { + return $this->cache->rememberForever(static::class . '@getTagByFullReference:' . $reference, function() use ($reference) { + return $this->roleTagRepository->getTagByFullReference($reference); + }); + } + + /** + * Get a role tag by id + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->roleTagRepository->getById($id); + }); + } + + /** + * Create a role tag + * + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + */ + public function create(string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + { + return $this->roleTagRepository->create($name, $description, $reference, $tagCategoryId); + } + + /** + * Delete a role tag + * + * @param int $id ID of the tag to delete + */ + public function delete(int $id): void + { + $this->roleTagRepository->delete($id); + } + + /** + * Get all tags through a tag category + * + * @param \BristolSU\ControlDB\Contracts\Models\Tags\RoleTagCategory $roleTagCategory + * @return Collection|RoleTagRepository Tags with the given role tag category + */ + public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags\RoleTagCategory $roleTagCategory): Collection + { + return $this->cache->rememberForever(static::class . '@allThroughTagCategory:' . $roleTagCategory->id(), function() use ($roleTagCategory) { + return $this->roleTagRepository->allThroughTagCategory($roleTagCategory); + }); + } + + /** + * Update a role tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + { + return $this->roleTagRepository->update($id, $name, $description, $reference, $tagCategoryId); + } +} \ No newline at end of file diff --git a/src/Cache/Tags/RoleTagCategory.php b/src/Cache/Tags/RoleTagCategory.php new file mode 100644 index 0000000..e0f03bb --- /dev/null +++ b/src/Cache/Tags/RoleTagCategory.php @@ -0,0 +1,100 @@ +roleTagCategoryRepository = $roleTagCategoryRepository; + $this->cache = $cache; + } + + /** + * Get all role tag categories + * + * @return Collection|RoleTagCategoryModel[] + */ + public function all(): Collection + { + return $this->roleTagCategoryRepository->all(); + } + + /** + * Get a tag category by the reference + * + * @param string $reference Reference of the tag + * @return RoleTagCategoryModel + */ + public function getByReference(string $reference): RoleTagCategoryModel + { + return $this->cache->rememberForever(static::class . '@getByReference:' . $reference, function() use ($reference) { + return $this->roleTagCategoryRepository->getByReference($reference); + }); + } + + /** + * Get a role tag category by id + * + * @param int $id + * @return RoleTagCategoryModel + */ + public function getById(int $id): RoleTagCategoryModel + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->roleTagCategoryRepository->getById($id); + }); + } + + /** + * Delete a role tag category + * + * @param int $id ID of the role tag category to delete + */ + public function delete(int $id): void + { + $this->roleTagCategoryRepository->delete($id); + } + + /** + * Create a role tag category + * + * @param string $name Name of the role tag category + * @param string $description Description of the role tag category + * @param string $reference Reference of the role tag category + * @return RoleTagCategoryModel New role tag category + */ + public function create(string $name, string $description, string $reference): RoleTagCategoryModel + { + return $this->roleTagCategoryRepository->create($name, $description, $reference); + } + + /** + * Update a role tag category + * + * @param int $id + * @param string $name Name of the role tag category + * @param string $description Description of the role tag category + * @param string $reference Reference of the role tag category + * @return RoleTagCategoryModel Updated role tag category + */ + public function update(int $id, string $name, string $description, string $reference): RoleTagCategoryModel + { + return $this->roleTagCategoryRepository->update($id, $name, $description, $reference); + } +} \ No newline at end of file diff --git a/src/Cache/Tags/UserTag.php b/src/Cache/Tags/UserTag.php new file mode 100644 index 0000000..d0e0b81 --- /dev/null +++ b/src/Cache/Tags/UserTag.php @@ -0,0 +1,117 @@ +userTagRepository = $userTagRepository; + $this->cache = $cache; + } + + /** + * Get all user tags + * + * @return Collection|\BristolSU\ControlDB\Contracts\Models\Tags\UserTag[] + */ + public function all(): Collection + { + return $this->userTagRepository->all(); + } + + /** + * Get a tag by the full reference + * + * The full reference looks like 'tag_category_ref.tag_ref' + * + * @param string $reference + * @return \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + */ + public function getTagByFullReference(string $reference): \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + { + return $this->cache->rememberForever(static::class . '@getTagByFullReference:' . $reference, function() use ($reference) { + return $this->userTagRepository->getTagByFullReference($reference); + }); + } + + /** + * Get a user tag by id + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->userTagRepository->getById($id); + }); + } + + /** + * Create a user tag + * + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + */ + public function create(string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + { + return $this->userTagRepository->create($name, $description, $reference, $tagCategoryId); + } + + /** + * Delete a user tag + * + * @param int $id ID of the tag to delete + */ + public function delete(int $id): void + { + $this->userTagRepository->delete($id); + } + + /** + * Get all tags through a tag category + * + * @param \BristolSU\ControlDB\Contracts\Models\Tags\UserTagCategory $userTagCategory + * @return Collection|UserTagRepository Tags with the given user tag category + */ + public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags\UserTagCategory $userTagCategory): Collection + { + return $this->cache->rememberForever(static::class . '@allThroughTagCategory:' . $userTagCategory->id(), function() use ($userTagCategory) { + return $this->userTagRepository->allThroughTagCategory($userTagCategory); + }); + } + + /** + * Update a user tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + { + return $this->userTagRepository->update($id, $name, $description, $reference, $tagCategoryId); + } + +} \ No newline at end of file diff --git a/src/Cache/Tags/UserTagCategory.php b/src/Cache/Tags/UserTagCategory.php new file mode 100644 index 0000000..161849a --- /dev/null +++ b/src/Cache/Tags/UserTagCategory.php @@ -0,0 +1,100 @@ +userTagCategoryRepository = $userTagCategoryRepository; + $this->cache = $cache; + } + + /** + * Get all user tag categories + * + * @return Collection|UserTagCategoryModel[] + */ + public function all(): Collection + { + return $this->userTagCategoryRepository->all(); + } + + /** + * Get a tag category by the reference + * + * @param string $reference Reference of the tag + * @return UserTagCategoryModel + */ + public function getByReference(string $reference): UserTagCategoryModel + { + return $this->cache->rememberForever(static::class . '@getByReference:' . $reference, function() use ($reference) { + return $this->userTagCategoryRepository->getByReference($reference); + }); + } + + /** + * Get a user tag category by id + * + * @param int $id + * @return UserTagCategoryModel + */ + public function getById(int $id): UserTagCategoryModel + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->userTagCategoryRepository->getById($id); + }); + } + + /** + * Delete a user tag category + * + * @param int $id ID of the user tag category to delete + */ + public function delete(int $id): void + { + $this->userTagCategoryRepository->delete($id); + } + + /** + * Create a user tag category + * + * @param string $name Name of the user tag category + * @param string $description Description of the user tag category + * @param string $reference Reference of the user tag category + * @return UserTagCategoryModel New user tag category + */ + public function create(string $name, string $description, string $reference): UserTagCategoryModel + { + return $this->userTagCategoryRepository->create($name, $description, $reference); + } + + /** + * Update a user tag category + * + * @param int $id + * @param string $name Name of the user tag category + * @param string $description Description of the user tag category + * @param string $reference Reference of the user tag category + * @return UserTagCategoryModel Updated user tag category + */ + public function update(int $id, string $name, string $description, string $reference): UserTagCategoryModel + { + return $this->userTagCategoryRepository->update($id, $name, $description, $reference); + } +} \ No newline at end of file diff --git a/src/Cache/User.php b/src/Cache/User.php new file mode 100644 index 0000000..bba87a9 --- /dev/null +++ b/src/Cache/User.php @@ -0,0 +1,121 @@ +userRepository = $userRepository; + $this->cache = $cache; + } + + /** + * Get a user by ID + * + * @param int $id ID of the user + * @return UserModel + */ + public function getById(int $id): UserModel + { + return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { + return $this->userRepository->getById($id); + }); + } + + /** + * Get a user by its data provider ID + * + * @param int $dataProviderId + * @return UserModel + */ + public function getByDataProviderId(int $dataProviderId): UserModel + { + return $this->cache->rememberForever(static::class . '@getByDataProviderId:' . $dataProviderId, function() use ($dataProviderId) { + return $this->userRepository->getByDataProviderId($dataProviderId); + }); + } + + /** + * Get all users + * + * @return Collection|UserModel[] + */ + public function all(): Collection + { + return $this->userRepository->all(); + } + + /** + * Create a new user + * + * @param int $dataProviderId + * @return UserModel + */ + public function create(int $dataProviderId): UserModel + { + return $this->userRepository->create($dataProviderId); + } + + /** + * Delete a user by ID + * + * @param int $id + */ + public function delete(int $id): void + { + $this->userRepository->delete($id); + } + + /** + * Paginate through all the users + * + * @param int $page The page number to return + * @param int $perPage The number of results to return per page + * + * @return Collection|UserModel[] + */ + public function paginate(int $page, int $perPage): Collection + { + return $this->userRepository->paginate($page, $perPage); + } + + /** + * Get the number of users + * + * @return int + */ + public function count(): int + { + return $this->cache->rememberForever(static::class . '@count', function() { + return $this->userRepository->count(); + }); + } + + /** + * Update the user model + * + * @param int $id + * @param int $dataProviderId New data provider ID + * @return UserModel + */ + public function update(int $id, int $dataProviderId): UserModel + { + return $this->userRepository->update($id, $dataProviderId); + } +} \ No newline at end of file diff --git a/src/Contracts/Repositories/DataGroup.php b/src/Contracts/Repositories/DataGroup.php index f575040..544bf56 100644 --- a/src/Contracts/Repositories/DataGroup.php +++ b/src/Contracts/Repositories/DataGroup.php @@ -33,6 +33,7 @@ public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Model * @return Collection|\BristolSU\ControlDB\Contracts\Models\DataGroup[] */ public function getAllWhere($attributes = []): Collection; + /** * Create a group with the given attributes * @@ -41,4 +42,15 @@ public function getAllWhere($attributes = []): Collection; * @return \BristolSU\ControlDB\Contracts\Models\DataGroup */ public function create(?string $name = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataGroup; + + + /** + * Update a group with the given attributes + * + * @param int $id + * @param string|null $name Name of the group + * @param string|null $email Email of the group + * @return \BristolSU\ControlDB\Contracts\Models\DataGroup + */ + public function update(int $id, ?string $name = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataGroup; } \ No newline at end of file diff --git a/src/Contracts/Repositories/DataPosition.php b/src/Contracts/Repositories/DataPosition.php index 15c6fe1..edd2744 100644 --- a/src/Contracts/Repositories/DataPosition.php +++ b/src/Contracts/Repositories/DataPosition.php @@ -35,6 +35,18 @@ public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Model */ public function create(?string $name = null, ?string $description = null): \BristolSU\ControlDB\Contracts\Models\DataPosition; + + /** + * Update a data position with the given attributes + * + * @param int $id + * @param string|null $name Name of the position + * @param string|null $description Description of the position + * @return \BristolSU\ControlDB\Contracts\Models\DataPosition + */ + public function update(int $id, ?string $name = null, ?string $description = null): \BristolSU\ControlDB\Contracts\Models\DataPosition; + + /** * Get all data positions where the given attributes match, including additional attributes. * diff --git a/src/Contracts/Repositories/DataRole.php b/src/Contracts/Repositories/DataRole.php index fab71db..dc4aca0 100644 --- a/src/Contracts/Repositories/DataRole.php +++ b/src/Contracts/Repositories/DataRole.php @@ -35,11 +35,21 @@ public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Model public function getAllWhere($attributes = []): Collection; /** - * Create a data position with the given attributes + * Create a data role with the given attributes * * @param string|null $roleName Custom name for the role * @param string|null $email Email of the role * @return \BristolSU\ControlDB\Contracts\Models\DataRole */ public function create(?string $roleName = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataRole; + + /** + * Update a data role with the given attributes + * + * @param int $id + * @param string|null $roleName Custom name for the role + * @param string|null $email Email of the role + * @return \BristolSU\ControlDB\Contracts\Models\DataRole + */ + public function update(int $id, ?string $roleName = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataRole; } \ No newline at end of file diff --git a/src/Contracts/Repositories/DataUser.php b/src/Contracts/Repositories/DataUser.php index 7fc85b7..89a7db0 100644 --- a/src/Contracts/Repositories/DataUser.php +++ b/src/Contracts/Repositories/DataUser.php @@ -48,4 +48,17 @@ public function getAllWhere($attributes = []): Collection; * @return \BristolSU\ControlDB\Contracts\Models\DataUser */ public function create(?string $firstName = null, ?string $lastName = null, ?string $email = null, ?\DateTime $dob = null, ?string $preferredName = null): \BristolSU\ControlDB\Contracts\Models\DataUser; + + /** + * Update a data user + * + * @param int $id + * @param string|null $firstName + * @param string|null $lastName + * @param string|null $email + * @param \DateTime|null $dob + * @param string|null $preferredName + * @return \BristolSU\ControlDB\Contracts\Models\DataUser + */ + public function update(int $id, ?string $firstName = null, ?string $lastName = null, ?string $email = null, ?\DateTime $dob = null, ?string $preferredName = null): \BristolSU\ControlDB\Contracts\Models\DataUser; } \ No newline at end of file diff --git a/src/Contracts/Repositories/Group.php b/src/Contracts/Repositories/Group.php index ef5dffd..e62d8b3 100644 --- a/src/Contracts/Repositories/Group.php +++ b/src/Contracts/Repositories/Group.php @@ -42,6 +42,15 @@ public function all(): Collection; */ public function create(int $dataProviderId): GroupModel; + /** + * Update the group model + * + * @param int $id + * @param int $dataProviderId New data provider ID + * @return GroupModel + */ + public function update(int $id, int $dataProviderId): GroupModel; + /** * Delete a group by ID * diff --git a/src/Contracts/Repositories/Position.php b/src/Contracts/Repositories/Position.php index 6c1146b..24f0310 100644 --- a/src/Contracts/Repositories/Position.php +++ b/src/Contracts/Repositories/Position.php @@ -41,6 +41,15 @@ public function all(): Collection; */ public function create(int $dataProviderId): PositionModel; + /** + * Update the position model + * + * @param int $id + * @param int $dataProviderId New data provider ID + * @return PositionModel + */ + public function update(int $id, int $dataProviderId): PositionModel; + /** * Delete a position by ID * @@ -64,4 +73,4 @@ public function paginate(int $page, int $perPage): Collection; * @return int */ public function count(): int; -} +} \ No newline at end of file diff --git a/src/Contracts/Repositories/Role.php b/src/Contracts/Repositories/Role.php index 710af14..3e72312 100644 --- a/src/Contracts/Repositories/Role.php +++ b/src/Contracts/Repositories/Role.php @@ -53,6 +53,17 @@ public function create(int $positionId, int $groupId, int $dataProviderId): Role */ public function delete(int $id): void; + /** + * Update the role model + * + * @param int $id + * @param int $positionId + * @param int $groupId + * @param int $dataProviderId New data provider ID + * @return RoleModel + */ + public function update(int $id, int $positionId, int $groupId, int $dataProviderId): RoleModel; + /** * Get all roles that belong to the given group * diff --git a/src/Contracts/Repositories/Tags/GroupTag.php b/src/Contracts/Repositories/Tags/GroupTag.php index d2f7e35..ffcf593 100644 --- a/src/Contracts/Repositories/Tags/GroupTag.php +++ b/src/Contracts/Repositories/Tags/GroupTag.php @@ -47,6 +47,18 @@ public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\Tags\Gro */ public function create(string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag; + /** + * Update a group tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag; + /** * Delete a group tag * @@ -58,7 +70,7 @@ public function delete(int $id): void; * Get all tags through a tag category * * @param \BristolSU\ControlDB\Contracts\Models\Tags\GroupTagCategory $groupTagCategory - * @return Collection|GroupTag[] Tags with the given group tag category + * @return Collection|\BristolSU\ControlDB\Contracts\Models\Tags\GroupTag[] Tags with the given group tag category */ public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags\GroupTagCategory $groupTagCategory): Collection; } diff --git a/src/Contracts/Repositories/Tags/GroupTagCategory.php b/src/Contracts/Repositories/Tags/GroupTagCategory.php index 7a9ac8d..9788df7 100644 --- a/src/Contracts/Repositories/Tags/GroupTagCategory.php +++ b/src/Contracts/Repositories/Tags/GroupTagCategory.php @@ -50,4 +50,15 @@ public function delete(int $id): void; * @return GroupTagCategoryModel New group tag category */ public function create(string $name, string $description, string $reference): GroupTagCategoryModel; + + /** + * Update a group tag category + * + * @param int $id + * @param string $name Name of the group tag category + * @param string $description Description of the group tag category + * @param string $reference Reference of the group tag category + * @return GroupTagCategoryModel New group tag category + */ + public function update(int $id, string $name, string $description, string $reference): GroupTagCategoryModel; } diff --git a/src/Contracts/Repositories/Tags/PositionTag.php b/src/Contracts/Repositories/Tags/PositionTag.php index 4a8e69a..aaae475 100644 --- a/src/Contracts/Repositories/Tags/PositionTag.php +++ b/src/Contracts/Repositories/Tags/PositionTag.php @@ -61,4 +61,16 @@ public function delete(int $id): void; * @return Collection|PositionTag[] Tags with the given position tag category */ public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags\PositionTagCategory $positionTagCategory): Collection; + + /** + * Update a position tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag; } diff --git a/src/Contracts/Repositories/Tags/PositionTagCategory.php b/src/Contracts/Repositories/Tags/PositionTagCategory.php index 92ffe29..9356ee6 100644 --- a/src/Contracts/Repositories/Tags/PositionTagCategory.php +++ b/src/Contracts/Repositories/Tags/PositionTagCategory.php @@ -51,4 +51,15 @@ public function delete(int $id): void; * @return PositionTagCategoryModel New position tag category */ public function create(string $name, string $description, string $reference): PositionTagCategoryModel; + + /** + * Update a position tag category + * + * @param int $id + * @param string $name Name of the position tag category + * @param string $description Description of the position tag category + * @param string $reference Reference of the position tag category + * @return PositionTagCategoryModel Updated position tag category + */ + public function update(int $id, string $name, string $description, string $reference): PositionTagCategoryModel; } diff --git a/src/Contracts/Repositories/Tags/RoleTag.php b/src/Contracts/Repositories/Tags/RoleTag.php index d7006e4..a32ea1e 100644 --- a/src/Contracts/Repositories/Tags/RoleTag.php +++ b/src/Contracts/Repositories/Tags/RoleTag.php @@ -61,4 +61,16 @@ public function delete(int $id): void; * @return Collection|RoleTag[] Tags with the given role tag category */ public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags\RoleTagCategory $roleTagCategory): Collection; + + /** + * Update a role tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag; } diff --git a/src/Contracts/Repositories/Tags/RoleTagCategory.php b/src/Contracts/Repositories/Tags/RoleTagCategory.php index 812d98f..5bbf8e7 100644 --- a/src/Contracts/Repositories/Tags/RoleTagCategory.php +++ b/src/Contracts/Repositories/Tags/RoleTagCategory.php @@ -51,4 +51,15 @@ public function delete(int $id): void; * @return RoleTagCategoryModel New role tag category */ public function create(string $name, string $description, string $reference): RoleTagCategoryModel; + + /** + * Update a role tag category + * + * @param int $id + * @param string $name Name of the role tag category + * @param string $description Description of the role tag category + * @param string $reference Reference of the role tag category + * @return RoleTagCategoryModel Updated role tag category + */ + public function update(int $id, string $name, string $description, string $reference): RoleTagCategoryModel; } diff --git a/src/Contracts/Repositories/Tags/UserTag.php b/src/Contracts/Repositories/Tags/UserTag.php index ee147c8..52396d4 100644 --- a/src/Contracts/Repositories/Tags/UserTag.php +++ b/src/Contracts/Repositories/Tags/UserTag.php @@ -60,4 +60,16 @@ public function delete(int $id): void; * @return Collection|UserTag[] Tags with the given user tag category */ public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags\UserTagCategory $userTagCategory): Collection; + + /** + * Update a user tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\UserTag; } diff --git a/src/Contracts/Repositories/Tags/UserTagCategory.php b/src/Contracts/Repositories/Tags/UserTagCategory.php index 080a310..6bce4d2 100644 --- a/src/Contracts/Repositories/Tags/UserTagCategory.php +++ b/src/Contracts/Repositories/Tags/UserTagCategory.php @@ -51,4 +51,15 @@ public function delete(int $id): void; * @return UserTagCategoryModel New user tag category */ public function create(string $name, string $description, string $reference): UserTagCategoryModel; + + /** + * Update a user tag category + * + * @param int $id + * @param string $name Name of the user tag category + * @param string $description Description of the user tag category + * @param string $reference Reference of the user tag category + * @return UserTagCategoryModel Updated user tag category + */ + public function update(int $id, string $name, string $description, string $reference): UserTagCategoryModel; } diff --git a/src/Contracts/Repositories/User.php b/src/Contracts/Repositories/User.php index ca6de3e..ed4b2f5 100644 --- a/src/Contracts/Repositories/User.php +++ b/src/Contracts/Repositories/User.php @@ -48,6 +48,15 @@ public function create(int $dataProviderId): UserModel; */ public function delete(int $id): void; + /** + * Update the user model + * + * @param int $id + * @param int $dataProviderId New data provider ID + * @return UserModel + */ + public function update(int $id, int $dataProviderId): UserModel; + /** * Paginate through all the users * diff --git a/src/ControlDBServiceProvider.php b/src/ControlDBServiceProvider.php index 8a8bca3..09b5712 100644 --- a/src/ControlDBServiceProvider.php +++ b/src/ControlDBServiceProvider.php @@ -4,7 +4,8 @@ use BristolSU\ControlDB\AdditionalProperties\AdditionalPropertySingletonStore; use BristolSU\ControlDB\AdditionalProperties\AdditionalPropertyStore; -use BristolSU\ControlDB\Cache\Role; +use BristolSU\ControlDB\Bootstrap\RegistersCachedRepositories; +use BristolSU\ControlDB\Bootstrap\RegistersObserverFramework; use BristolSU\ControlDB\Commands\SeedDatabase; use BristolSU\ControlDB\Contracts\Repositories\DataUser as DataUserRepositoryContract; use BristolSU\ControlDB\Contracts\Repositories\DataGroup as DataGroupRepositoryContract; @@ -38,6 +39,42 @@ use BristolSU\ControlDB\Models\Tags\UserTag as UserTagModel; use BristolSU\ControlDB\Models\Tags\UserTagCategory as UserTagCategoryModel; use BristolSU\ControlDB\Models\User as UserModel; +use BristolSU\ControlDB\Observers\DataGroupObserverClearCache; +use BristolSU\ControlDB\Observers\DataPositionObserverClearCache; +use BristolSU\ControlDB\Observers\DataRoleObserverClearCache; +use BristolSU\ControlDB\Observers\DataUserObserverClearCache; +use BristolSU\ControlDB\Observers\GroupObserverCascadeDelete; +use BristolSU\ControlDB\Observers\GroupObserverClearCache; +use BristolSU\ControlDB\Observers\NotifyObservers\Framework\Observe; +use BristolSU\ControlDB\Observers\NotifyObservers\Framework\ObserverStore; +use BristolSU\ControlDB\Observers\Pivots\Tags\GroupGroupTagObserverClearCache; +use BristolSU\ControlDB\Observers\Pivots\Tags\PositionPositionTagObserverClearCache; +use BristolSU\ControlDB\Observers\Pivots\Tags\RoleRoleTagObserverClearCache; +use BristolSU\ControlDB\Observers\Pivots\Tags\UserUserTagObserverClearCache; +use BristolSU\ControlDB\Observers\Pivots\UserGroupObserverClearCache; +use BristolSU\ControlDB\Observers\Pivots\UserRoleObserverClearCache; +use BristolSU\ControlDB\Observers\PositionObserverCascadeDelete; +use BristolSU\ControlDB\Observers\PositionObserverClearCache; +use BristolSU\ControlDB\Observers\RoleObserverCascadeDelete; +use BristolSU\ControlDB\Observers\RoleObserverClearCache; +use BristolSU\ControlDB\Observers\Tags\GroupTagCategoryObserverCascadeDelete; +use BristolSU\ControlDB\Observers\Tags\GroupTagCategoryObserverClearCache; +use BristolSU\ControlDB\Observers\Tags\GroupTagObserverCascadeDelete; +use BristolSU\ControlDB\Observers\Tags\GroupTagObserverClearCache; +use BristolSU\ControlDB\Observers\Tags\PositionTagCategoryObserverCascadeDelete; +use BristolSU\ControlDB\Observers\Tags\PositionTagCategoryObserverClearCache; +use BristolSU\ControlDB\Observers\Tags\PositionTagObserverCascadeDelete; +use BristolSU\ControlDB\Observers\Tags\PositionTagObserverClearCache; +use BristolSU\ControlDB\Observers\Tags\RoleTagCategoryObserverCascadeDelete; +use BristolSU\ControlDB\Observers\Tags\RoleTagCategoryObserverClearCache; +use BristolSU\ControlDB\Observers\Tags\RoleTagObserverCascadeDelete; +use BristolSU\ControlDB\Observers\Tags\RoleTagObserverClearCache; +use BristolSU\ControlDB\Observers\Tags\UserTagCategoryObserverCascadeDelete; +use BristolSU\ControlDB\Observers\Tags\UserTagCategoryObserverClearCache; +use BristolSU\ControlDB\Observers\Tags\UserTagObserverCascadeDelete; +use BristolSU\ControlDB\Observers\Tags\UserTagObserverClearCache; +use BristolSU\ControlDB\Observers\UserObserverCascadeDelete; +use BristolSU\ControlDB\Observers\UserObserverClearCache; use BristolSU\ControlDB\Repositories\DataUser as DataUserRepository; use BristolSU\ControlDB\Repositories\DataGroup as DataGroupRepository; use BristolSU\ControlDB\Repositories\DataRole as DataRoleRepository; @@ -84,8 +121,6 @@ use BristolSU\ControlDB\Contracts\Repositories\Tags\UserTag as UserTagRepositoryContract; use BristolSU\ControlDB\Contracts\Repositories\Tags\UserTagCategory as UserTagCategoryRepositoryContract; use BristolSU\ControlDB\Contracts\Repositories\User as UserRepositoryContract; - -use Illuminate\Contracts\Cache\Repository; use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Database\Eloquent\Factory; use Illuminate\Support\Facades\Route; @@ -93,15 +128,17 @@ class ControlDBServiceProvider extends ServiceProvider { - + use RegistersCachedRepositories, RegistersObserverFramework; + public function register() { $this->bindContracts(); + $this->registerObserversFramework($this->app); + $this->registerCachedRepositories($this->app); $this->registerCommands(); $this->registerMigrations(); $this->registerConfig(); $this->registerFactories(); - $this->app->singleton('control-exporter', function() { return new ExportManager($this->app); }); @@ -111,6 +148,7 @@ public function boot() { $this->setupRouteModelBinding(); $this->setupRoutes(); + $this->setupObservers(); } /** @@ -195,16 +233,15 @@ public function bindContracts() $this->app->bind(RoleRoleTagContract::class, RoleRoleTag::class); $this->app->bind(PositionPositionTagContract::class, PositionPositionTag::class); - $this->app->extend(RoleRepositoryContract::class, function(RoleRepositoryContract $service, $app) { - return new Role($service, $app->make(Repository::class)); - }); + $this->app->singleton(ObserverStore::class); + } public function registerCommands() { $this->commands([ SeedDatabase::class, - ExportControlCommand::class + ExportControlCommand::class, ]); } @@ -271,5 +308,51 @@ public function setupRoutes() ->group(__DIR__ . '/../routes/api.php'); } + private function setupObservers() + { + Observe::attach(RoleRepositoryContract::class, RoleObserverClearCache::class); + Observe::attach(UserRepositoryContract::class, UserObserverClearCache::class); + Observe::attach(GroupRepositoryContract::class, GroupObserverClearCache::class); + Observe::attach(PositionRepositoryContract::class, PositionObserverClearCache::class); + + Observe::attach(DataUserRepositoryContract::class, DataUserObserverClearCache::class); + Observe::attach(DataGroupRepositoryContract::class, DataGroupObserverClearCache::class); + Observe::attach(DataRoleRepositoryContract::class, DataRoleObserverClearCache::class); + Observe::attach(DataPositionRepositoryContract::class, DataPositionObserverClearCache::class); + + Observe::attach(GroupTagRepositoryContract::class, GroupTagObserverClearCache::class); + Observe::attach(RoleTagRepositoryContract::class, RoleTagObserverClearCache::class); + Observe::attach(UserTagRepositoryContract::class, UserTagObserverClearCache::class); + Observe::attach(PositionTagRepositoryContract::class, PositionTagObserverClearCache::class); + + Observe::attach(GroupTagCategoryRepositoryContract::class, GroupTagCategoryObserverClearCache::class); + Observe::attach(RoleTagCategoryRepositoryContract::class, RoleTagCategoryObserverClearCache::class); + Observe::attach(UserTagCategoryRepositoryContract::class, UserTagCategoryObserverClearCache::class); + Observe::attach(PositionTagCategoryRepositoryContract::class, PositionTagCategoryObserverClearCache::class); + + Observe::attach(UserGroup::class, UserGroupObserverClearCache::class); + Observe::attach(UserRole::class, UserRoleObserverClearCache::class); + + Observe::attach(GroupGroupTag::class, GroupGroupTagObserverClearCache::class); + Observe::attach(UserUserTag::class, UserUserTagObserverClearCache::class); + Observe::attach(RoleRoleTag::class, RoleRoleTagObserverClearCache::class); + Observe::attach(PositionPositionTag::class, PositionPositionTagObserverClearCache::class); + + Observe::attach(GroupTagRepositoryContract::class, GroupTagObserverCascadeDelete::class); + Observe::attach(UserTagRepositoryContract::class, UserTagObserverCascadeDelete::class); + Observe::attach(RoleTagRepositoryContract::class, RoleTagObserverCascadeDelete::class); + Observe::attach(PositionTagRepositoryContract::class, PositionTagObserverCascadeDelete::class); + + Observe::attach(GroupTagCategoryRepositoryContract::class, GroupTagCategoryObserverCascadeDelete::class); + Observe::attach(UserTagCategoryRepositoryContract::class, UserTagCategoryObserverCascadeDelete::class); + Observe::attach(RoleTagCategoryRepositoryContract::class, RoleTagCategoryObserverCascadeDelete::class); + Observe::attach(PositionTagCategoryRepositoryContract::class, PositionTagCategoryObserverCascadeDelete::class); + + Observe::attach(RoleRepositoryContract::class, RoleObserverCascadeDelete::class); + Observe::attach(UserRepositoryContract::class, UserObserverCascadeDelete::class); + Observe::attach(GroupRepositoryContract::class, GroupObserverCascadeDelete::class); + Observe::attach(PositionRepositoryContract::class, PositionObserverCascadeDelete::class); + } + } \ No newline at end of file diff --git a/src/Export/ExportControlCommand.php b/src/Export/ExportControlCommand.php index 3570a26..36e3a79 100644 --- a/src/Export/ExportControlCommand.php +++ b/src/Export/ExportControlCommand.php @@ -6,8 +6,6 @@ use BristolSU\ControlDB\Contracts\Repositories\Position; use BristolSU\ControlDB\Contracts\Repositories\Role; use BristolSU\ControlDB\Contracts\Repositories\User; -use BristolSU\ControlDB\Export\Formatter\Role\SortByGroupName; -use BristolSU\ControlDB\Export\Formatter\Shared\SortByColumn; use Illuminate\Console\Command; use Symfony\Component\Console\Exception\InvalidArgumentException; @@ -46,8 +44,11 @@ class ExportControlCommand extends Command */ public function handle() { + $time=-hrtime(true); Exporter::driver($this->option('exporter'))->export($this->exportData()); $this->info('Export complete'); + $time+=hrtime(true); + $this->info(sprintf('Export took %.2f s to run', $time / 1e+9)); } private function exportData() diff --git a/src/Export/Formatter/Group/SimpleGroupFormatter.php b/src/Export/Formatter/Group/SimpleGroupFormatter.php index f193bb5..90b52c7 100644 --- a/src/Export/Formatter/Group/SimpleGroupFormatter.php +++ b/src/Export/Formatter/Group/SimpleGroupFormatter.php @@ -10,9 +10,10 @@ class SimpleGroupFormatter extends Formatter public function formatItem(FormattedItem $formattedItem): FormattedItem { + $groupData = $formattedItem->original()->data(); $formattedItem->addRow('Group ID', $formattedItem->original()->id()); - $formattedItem->addRow('Group Name', $formattedItem->original()->data()->name()); - $formattedItem->addRow('Group Email', $formattedItem->original()->data()->email()); + $formattedItem->addRow('Group Name', $groupData->name()); + $formattedItem->addRow('Group Email', $groupData->email()); return $formattedItem; } diff --git a/src/Export/Formatter/Role/SimpleRoleFormatter.php b/src/Export/Formatter/Role/SimpleRoleFormatter.php index da71ec8..394cc17 100644 --- a/src/Export/Formatter/Role/SimpleRoleFormatter.php +++ b/src/Export/Formatter/Role/SimpleRoleFormatter.php @@ -8,11 +8,17 @@ class SimpleRoleFormatter extends Formatter { + public function __construct(array $config) + { + parent::__construct($config); + } + public function formatItem(FormattedItem $formattedItem): FormattedItem { + $roleData = $formattedItem->original()->data(); $formattedItem->addRow('Role ID', $formattedItem->original()->id()); - $formattedItem->addRow('Role Name', $formattedItem->original()->data()->roleName()); - $formattedItem->addRow('Role Email', $formattedItem->original()->data()->email()); + $formattedItem->addRow('Role Name', $roleData->roleName()); + $formattedItem->addRow('Role Email', $roleData->email()); return $formattedItem; } diff --git a/src/Models/DataGroup.php b/src/Models/DataGroup.php index 0283156..9f6d6be 100644 --- a/src/Models/DataGroup.php +++ b/src/Models/DataGroup.php @@ -12,7 +12,10 @@ */ class DataGroup extends Model implements \BristolSU\ControlDB\Contracts\Models\DataGroup { - use SoftDeletes, HasAdditionalProperties, DataGroupTrait; + use SoftDeletes, HasAdditionalProperties, DataGroupTrait { + setName as baseSetName; + setEmail as baseSetEmail; + } /** * Define the table to use @@ -67,8 +70,8 @@ public function email(): ?string */ public function setName(?string $name): void { - $this->name = $name; - $this->save(); + $this->baseSetName($name); + $this->refresh(); } /** @@ -78,7 +81,10 @@ public function setName(?string $name): void */ public function setEmail(?string $email): void { - $this->email = $email; - $this->save(); + $this->baseSetEmail($email); + $this->refresh(); + } + + } \ No newline at end of file diff --git a/src/Models/DataPosition.php b/src/Models/DataPosition.php index 19a3a0d..8172730 100644 --- a/src/Models/DataPosition.php +++ b/src/Models/DataPosition.php @@ -14,7 +14,10 @@ */ class DataPosition extends Model implements \BristolSU\ControlDB\Contracts\Models\DataPosition { - use SoftDeletes, HasAdditionalProperties, DataPositionTrait; + use SoftDeletes, HasAdditionalProperties, DataPositionTrait { + setName as baseSetName; + setDescription as baseSetDescription; + } /** * Defines the table @@ -69,8 +72,8 @@ public function description(): ?string */ public function setName(?string $name): void { - $this->name = $name; - $this->save(); + $this->baseSetName($name); + $this->refresh(); } /** @@ -80,7 +83,9 @@ public function setName(?string $name): void */ public function setDescription(?string $description): void { - $this->description = $description; - $this->save(); + $this->baseSetDescription($description); + $this->refresh(); } + + } \ No newline at end of file diff --git a/src/Models/DataRole.php b/src/Models/DataRole.php index 5c46296..32b9738 100644 --- a/src/Models/DataRole.php +++ b/src/Models/DataRole.php @@ -15,7 +15,10 @@ */ class DataRole extends Model implements \BristolSU\ControlDB\Contracts\Models\DataRole { - use SoftDeletes, HasAdditionalProperties, DataRoleTrait; + use SoftDeletes, HasAdditionalProperties, DataRoleTrait { + setRoleName as baseSetRoleName; + setEmail as baseSetEmail; + } /** * The table to use @@ -43,16 +46,7 @@ public function id(): int return $this->id; } - /** - * Set the email of the role - * - * @param string|null $email - */ - public function setEmail(?string $email): void - { - $this->email = $email; - $this->save(); - } + /** * Get the email of the role @@ -65,23 +59,36 @@ public function email(): ?string } /** - * Set a name for the role + * Get the name for the role * - * @param string|null $roleName + * @return string|null */ - public function setRoleName(?string $roleName): void + public function roleName(): ?string { - $this->role_name = $roleName; - $this->save(); + return $this->role_name; } /** - * Get the name for the role - * - * @return string|null + * Set the email of the role + * + * @param string|null $email */ - public function roleName(): ?string + public function setEmail(?string $email): void { - return $this->role_name; + $this->baseSetEmail($email); + $this->refresh(); + } + + /** + * Set a name for the role + * + * @param string|null $roleName + */ + public function setRoleName(?string $roleName): void + { + $this->baseSetRoleName($roleName); + $this->refresh(); } + + } \ No newline at end of file diff --git a/src/Models/DataUser.php b/src/Models/DataUser.php index 21db953..d4eac07 100644 --- a/src/Models/DataUser.php +++ b/src/Models/DataUser.php @@ -15,7 +15,13 @@ */ class DataUser extends Model implements \BristolSU\ControlDB\Contracts\Models\DataUser { - use SoftDeletes, HasAdditionalProperties, DataUserTrait; + use SoftDeletes, HasAdditionalProperties, DataUserTrait { + setFirstName as baseSetFirstName; + setLastName as baseSetLastName; + setEmail as baseSetEmail; + setDob as baseSetDob; + setPreferredName as baseSetPreferredName; + } /** * The table to use @@ -109,53 +115,53 @@ public function preferredName(): ?string */ public function setFirstName(?string $firstName): void { - $this->first_name = $firstName; - $this->save(); + $this->baseSetFirstName($firstName); + $this->refresh(); } /** * Set the users last name - * + * * @param string|null $lastName */ public function setLastName(?string $lastName): void { - $this->last_name = $lastName; - $this->save(); + $this->baseSetLastName($lastName); + $this->refresh(); } /** * Set the users email - * + * * @param string|null $email */ public function setEmail(?string $email): void { - $this->email = $email; - $this->save(); + $this->baseSetEmail($email); + $this->refresh(); } /** * Set the date of birth attribute - * + * * @param DateTime|null $dob */ public function setDob(?DateTime $dob): void { - $this->dob = $dob; - $this->save(); + $this->baseSetDob($dob); + $this->refresh(); } /** * Set the preferred name for the user - * + * * @param string|null $name */ public function setPreferredName(?string $name): void { - $this->preferred_name = $name; - $this->save(); + $this->baseSetPreferredName($name); + $this->refresh(); } - + } \ No newline at end of file diff --git a/src/Models/Group.php b/src/Models/Group.php index 9220920..086f964 100644 --- a/src/Models/Group.php +++ b/src/Models/Group.php @@ -11,7 +11,9 @@ */ class Group extends Model implements \BristolSU\ControlDB\Contracts\Models\Group { - use SoftDeletes, GroupTrait; + use SoftDeletes, GroupTrait { + setDataProviderId as baseSetDataProviderId; + } /** * Table to use @@ -55,17 +57,6 @@ public function dataProviderId(): int { return $this->data_provider_id; } - - /** - * Set the ID of the data provider - * - * @param int $dataProviderId - */ - public function setDataProviderId(int $dataProviderId): void - { - $this->data_provider_id = $dataProviderId; - $this->save(); - } /** * Laravel integration for a data property @@ -76,4 +67,17 @@ public function getDataAttribute(): \BristolSU\ControlDB\Contracts\Models\DataGr { return $this->data(); } + + /** + * Set the ID of the data provider + * + * @param int $dataProviderId + */ + public function setDataProviderId(int $dataProviderId): void + { + $this->baseSetDataProviderId($dataProviderId); + $this->refresh(); + } + + } diff --git a/src/Models/Position.php b/src/Models/Position.php index 96e5412..6d953ed 100644 --- a/src/Models/Position.php +++ b/src/Models/Position.php @@ -13,7 +13,9 @@ */ class Position extends Model implements \BristolSU\ControlDB\Contracts\Models\Position { - use SoftDeletes, PositionTrait; + use SoftDeletes, PositionTrait { + setDataProviderId as baseSetDataProviderId; + } /** * Table to use @@ -59,24 +61,25 @@ public function dataProviderId(): int } /** - * Set the ID of the data provider + * Laravel integration for a data property * - * @param int $dataProviderId + * @return \BristolSU\ControlDB\Contracts\Models\DataPosition */ - public function setDataProviderId(int $dataProviderId): void + public function getDataAttribute(): \BristolSU\ControlDB\Contracts\Models\DataPosition { - $this->data_provider_id = $dataProviderId; - $this->save(); + return $this->data(); } /** - * Laravel integration for a data property + * Set the ID of the data provider * - * @return \BristolSU\ControlDB\Contracts\Models\DataPosition + * @param int $dataProviderId */ - public function getDataAttribute(): \BristolSU\ControlDB\Contracts\Models\DataPosition + public function setDataProviderId(int $dataProviderId): void { - return $this->data(); + $this->baseSetDataProviderId($dataProviderId); + $this->refresh(); } + } diff --git a/src/Models/Role.php b/src/Models/Role.php index 4926fdd..ee9bf08 100644 --- a/src/Models/Role.php +++ b/src/Models/Role.php @@ -14,7 +14,11 @@ class Role extends Model implements \BristolSU\ControlDB\Contracts\Models\Role { - use SoftDeletes, RoleTrait; + use SoftDeletes, RoleTrait { + setDataProviderId as baseSetDataProviderId; + setGroupId as baseSetGroupId; + setPositionId as baseSetPositionId; + } /** * Table to use @@ -59,17 +63,6 @@ public function dataProviderId(): int return $this->data_provider_id; } - /** - * Set the ID of the data provider - * - * @param int $dataProviderId - */ - public function setDataProviderId(int $dataProviderId): void - { - $this->data_provider_id = $dataProviderId; - $this->save(); - } - /** * Laravel integration for a data property * @@ -100,25 +93,38 @@ public function groupId(): int return $this->group_id; } + /** + * Set the ID of the data provider + * + * @param int $dataProviderId + */ + public function setDataProviderId(int $dataProviderId): void + { + $this->baseSetDataProviderId($dataProviderId); + $this->refresh(); + } + /** * Set a group ID - * + * * @param int $groupId */ public function setGroupId(int $groupId): void { - $this->group_id = $groupId; - $this->save(); + $this->baseSetGroupId($groupId); + $this->refresh(); } /** * Set a position ID - * + * * @param int $positionId */ public function setPositionId(int $positionId): void { - $this->position_id = $positionId; - $this->save(); + $this->baseSetPositionId($positionId); + $this->refresh(); } + + } diff --git a/src/Models/Tags/GroupTag.php b/src/Models/Tags/GroupTag.php index 0c0d01b..68c9214 100644 --- a/src/Models/Tags/GroupTag.php +++ b/src/Models/Tags/GroupTag.php @@ -12,7 +12,12 @@ */ class GroupTag extends Model implements \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag { - use SoftDeletes, GroupTagTrait; + use SoftDeletes, GroupTagTrait { + setName as baseSetName; + setDescription as baseSetDescription; + setReference as baseSetReference; + setTagCategoryId as baseSetTagCategoryId; + } /** * Boot the model @@ -107,46 +112,46 @@ public function categoryId(): int /** * Set the name of the tag - * + * * @param string $name */ public function setName(string $name): void { - $this->name = $name; - $this->save(); + $this->baseSetName($name); + $this->refresh(); } /** - * Set the description of the tagTag Reference - * + * Set the description of the Tag + * * @param string $description */ public function setDescription(string $description): void { - $this->description = $description; - $this->save(); + $this->baseSetDescription($description); + $this->refresh(); } /** * Set the reference of the tag - * + * * @param string $reference */ public function setReference(string $reference): void { - $this->reference = $reference; - $this->save(); + $this->baseSetReference($reference); + $this->refresh(); } /** * Set the tag category ID - * + * * @param int $categoryId */ public function setTagCategoryId($categoryId): void { - $this->tag_category_id = $categoryId; - $this->save(); + $this->baseSetTagCategoryId($categoryId); + $this->refresh(); } } diff --git a/src/Models/Tags/GroupTagCategory.php b/src/Models/Tags/GroupTagCategory.php index 0124563..4a2783b 100644 --- a/src/Models/Tags/GroupTagCategory.php +++ b/src/Models/Tags/GroupTagCategory.php @@ -12,7 +12,11 @@ */ class GroupTagCategory extends Model implements \BristolSU\ControlDB\Contracts\Models\Tags\GroupTagCategory { - use SoftDeletes, GroupTagCategoryTrait; + use SoftDeletes, GroupTagCategoryTrait { + setName as baseSetName; + setDescription as baseSetDescription; + setReference as baseSetReference; + } /** * Boot the model @@ -86,34 +90,35 @@ public function reference(): string /** * Set the name of the tag category - * + * * @param string $name */ public function setName(string $name): void { - $this->name = $name; - $this->save(); + $this->baseSetName($name); + $this->refresh(); } /** * Set the description of the tag category - * + * * @param string $description */ public function setDescription(string $description): void { - $this->description = $description; - $this->save(); + $this->baseSetDescription($description); + $this->refresh(); } /** * Set the reference of the tag category - * + * * @param string $reference */ public function setReference(string $reference): void { - $this->reference = $reference; - $this->save(); + $this->baseSetReference($reference); + $this->refresh(); } + } diff --git a/src/Models/Tags/PositionTag.php b/src/Models/Tags/PositionTag.php index 57d9c5a..28f722a 100644 --- a/src/Models/Tags/PositionTag.php +++ b/src/Models/Tags/PositionTag.php @@ -12,7 +12,12 @@ */ class PositionTag extends Model implements \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag { - use SoftDeletes, PositionTagTrait; + use SoftDeletes, PositionTagTrait { + setName as baseSetName; + setDescription as baseSetDescription; + setReference as baseSetReference; + setTagCategoryId as baseSetTagCategoryId; + } /** * Boot the model @@ -112,19 +117,19 @@ public function categoryId(): int */ public function setName(string $name): void { - $this->name = $name; - $this->save(); + $this->baseSetName($name); + $this->refresh(); } /** - * Set the description of the tagTag Reference + * Set the description of the Tag * * @param string $description */ public function setDescription(string $description): void { - $this->description = $description; - $this->save(); + $this->baseSetDescription($description); + $this->refresh(); } /** @@ -134,8 +139,8 @@ public function setDescription(string $description): void */ public function setReference(string $reference): void { - $this->reference = $reference; - $this->save(); + $this->baseSetReference($reference); + $this->refresh(); } /** @@ -145,8 +150,8 @@ public function setReference(string $reference): void */ public function setTagCategoryId($categoryId): void { - $this->tag_category_id = $categoryId; - $this->save(); + $this->baseSetTagCategoryId($categoryId); + $this->refresh(); } } diff --git a/src/Models/Tags/PositionTagCategory.php b/src/Models/Tags/PositionTagCategory.php index 1b35f22..a572fa3 100644 --- a/src/Models/Tags/PositionTagCategory.php +++ b/src/Models/Tags/PositionTagCategory.php @@ -12,7 +12,11 @@ */ class PositionTagCategory extends Model implements \BristolSU\ControlDB\Contracts\Models\Tags\PositionTagCategory { - use SoftDeletes, PositionTagCategoryTrait; + use SoftDeletes, PositionTagCategoryTrait { + setName as baseSetName; + setDescription as baseSetDescription; + setReference as baseSetReference; + } /** * Boot the model @@ -91,8 +95,8 @@ public function reference(): string */ public function setName(string $name): void { - $this->name = $name; - $this->save(); + $this->baseSetName($name); + $this->refresh(); } /** @@ -102,8 +106,8 @@ public function setName(string $name): void */ public function setDescription(string $description): void { - $this->description = $description; - $this->save(); + $this->baseSetDescription($description); + $this->refresh(); } /** @@ -113,7 +117,8 @@ public function setDescription(string $description): void */ public function setReference(string $reference): void { - $this->reference = $reference; - $this->save(); + $this->baseSetReference($reference); + $this->refresh(); } + } diff --git a/src/Models/Tags/RoleTag.php b/src/Models/Tags/RoleTag.php index bc17d90..aa0f167 100644 --- a/src/Models/Tags/RoleTag.php +++ b/src/Models/Tags/RoleTag.php @@ -12,7 +12,12 @@ */ class RoleTag extends Model implements \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag { - use SoftDeletes, RoleTagTrait; + use SoftDeletes, RoleTagTrait { + setName as baseSetName; + setDescription as baseSetDescription; + setReference as baseSetReference; + setTagCategoryId as baseSetTagCategoryId; + } /** * Boot the model @@ -112,19 +117,19 @@ public function categoryId(): int */ public function setName(string $name): void { - $this->name = $name; - $this->save(); + $this->baseSetName($name); + $this->refresh(); } /** - * Set the description of the tagTag Reference + * Set the description of the Tag * * @param string $description */ public function setDescription(string $description): void { - $this->description = $description; - $this->save(); + $this->baseSetDescription($description); + $this->refresh(); } /** @@ -134,8 +139,8 @@ public function setDescription(string $description): void */ public function setReference(string $reference): void { - $this->reference = $reference; - $this->save(); + $this->baseSetReference($reference); + $this->refresh(); } /** @@ -145,8 +150,8 @@ public function setReference(string $reference): void */ public function setTagCategoryId($categoryId): void { - $this->tag_category_id = $categoryId; - $this->save(); + $this->baseSetTagCategoryId($categoryId); + $this->refresh(); } } diff --git a/src/Models/Tags/RoleTagCategory.php b/src/Models/Tags/RoleTagCategory.php index ffae53c..5cc50a1 100644 --- a/src/Models/Tags/RoleTagCategory.php +++ b/src/Models/Tags/RoleTagCategory.php @@ -12,7 +12,11 @@ */ class RoleTagCategory extends Model implements \BristolSU\ControlDB\Contracts\Models\Tags\RoleTagCategory { - use SoftDeletes, RoleTagCategoryTrait; + use SoftDeletes, RoleTagCategoryTrait { + setName as baseSetName; + setDescription as baseSetDescription; + setReference as baseSetReference; + } /** * Boot the model @@ -91,8 +95,8 @@ public function reference(): string */ public function setName(string $name): void { - $this->name = $name; - $this->save(); + $this->baseSetName($name); + $this->refresh(); } /** @@ -102,8 +106,8 @@ public function setName(string $name): void */ public function setDescription(string $description): void { - $this->description = $description; - $this->save(); + $this->baseSetDescription($description); + $this->refresh(); } /** @@ -113,7 +117,8 @@ public function setDescription(string $description): void */ public function setReference(string $reference): void { - $this->reference = $reference; - $this->save(); + $this->baseSetReference($reference); + $this->refresh(); } + } diff --git a/src/Models/Tags/UserTag.php b/src/Models/Tags/UserTag.php index 5faf0a6..6376423 100644 --- a/src/Models/Tags/UserTag.php +++ b/src/Models/Tags/UserTag.php @@ -12,7 +12,12 @@ */ class UserTag extends Model implements \BristolSU\ControlDB\Contracts\Models\Tags\UserTag { - use SoftDeletes, UserTagTrait; + use SoftDeletes, UserTagTrait { + setName as baseSetName; + setDescription as baseSetDescription; + setReference as baseSetReference; + setTagCategoryId as baseSetTagCategoryId; + } /** * Boot the model @@ -112,19 +117,19 @@ public function categoryId(): int */ public function setName(string $name): void { - $this->name = $name; - $this->save(); + $this->baseSetName($name); + $this->refresh(); } /** - * Set the description of the tagTag Reference + * Set the description of the Tag * * @param string $description */ public function setDescription(string $description): void { - $this->description = $description; - $this->save(); + $this->baseSetDescription($description); + $this->refresh(); } /** @@ -134,8 +139,8 @@ public function setDescription(string $description): void */ public function setReference(string $reference): void { - $this->reference = $reference; - $this->save(); + $this->baseSetReference($reference); + $this->refresh(); } /** @@ -145,8 +150,9 @@ public function setReference(string $reference): void */ public function setTagCategoryId($categoryId): void { - $this->tag_category_id = $categoryId; - $this->save(); + $this->baseSetTagCategoryId($categoryId); + $this->refresh(); } + } diff --git a/src/Models/Tags/UserTagCategory.php b/src/Models/Tags/UserTagCategory.php index 161c35e..f95cdde 100644 --- a/src/Models/Tags/UserTagCategory.php +++ b/src/Models/Tags/UserTagCategory.php @@ -12,7 +12,11 @@ */ class UserTagCategory extends Model implements \BristolSU\ControlDB\Contracts\Models\Tags\UserTagCategory { - use SoftDeletes, UserTagCategoryTrait; + use SoftDeletes, UserTagCategoryTrait { + setName as baseSetName; + setDescription as baseSetDescription; + setReference as baseSetReference; + } /** * Boot the model @@ -91,8 +95,8 @@ public function reference(): string */ public function setName(string $name): void { - $this->name = $name; - $this->save(); + $this->baseSetName($name); + $this->refresh(); } /** @@ -102,8 +106,8 @@ public function setName(string $name): void */ public function setDescription(string $description): void { - $this->description = $description; - $this->save(); + $this->baseSetDescription($description); + $this->refresh(); } /** @@ -113,7 +117,9 @@ public function setDescription(string $description): void */ public function setReference(string $reference): void { - $this->reference = $reference; - $this->save(); + $this->baseSetReference($reference); + $this->refresh(); } + + } diff --git a/src/Models/User.php b/src/Models/User.php index b98762b..bf56bc0 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -14,7 +14,9 @@ */ class User extends Model implements UserContract { - use SoftDeletes, UserTrait; + use SoftDeletes, UserTrait { + setDataProviderId as baseSetDataProviderId; + } /** * Table to use @@ -59,17 +61,6 @@ public function dataProviderId(): int return $this->data_provider_id; } - /** - * Set the ID of the data provider - * - * @param int $dataProviderId - */ - public function setDataProviderId(int $dataProviderId): void - { - $this->data_provider_id = $dataProviderId; - $this->save(); - } - /** * Laravel integration for a data property * @@ -79,4 +70,10 @@ public function getDataAttribute(): \BristolSU\ControlDB\Contracts\Models\DataUs { return $this->data(); } + + public function setDataProviderId(int $dataProviderId): void + { + $this->baseSetDataProviderId($dataProviderId); + $this->refresh(); + } } diff --git a/src/Observers/DataGroupObserverClearCache.php b/src/Observers/DataGroupObserverClearCache.php new file mode 100644 index 0000000..336631b --- /dev/null +++ b/src/Observers/DataGroupObserverClearCache.php @@ -0,0 +1,27 @@ +cache = $cache; + } + + public function update(DataGroup $oldDataGroup, DataGroup $newDataGroup) + { + $this->cache->forget(DataGroupCache::class . '@getById:' . $newDataGroup->id()); + } + +} \ No newline at end of file diff --git a/src/Observers/DataPositionObserverClearCache.php b/src/Observers/DataPositionObserverClearCache.php new file mode 100644 index 0000000..78008a4 --- /dev/null +++ b/src/Observers/DataPositionObserverClearCache.php @@ -0,0 +1,27 @@ +cache = $cache; + } + + public function update(DataPosition $oldDataPosition, DataPosition $newDataPosition) + { + $this->cache->forget(DataPositionCache::class . '@getById:' . $newDataPosition->id()); + } + +} \ No newline at end of file diff --git a/src/Observers/DataRoleObserverClearCache.php b/src/Observers/DataRoleObserverClearCache.php new file mode 100644 index 0000000..f52c70a --- /dev/null +++ b/src/Observers/DataRoleObserverClearCache.php @@ -0,0 +1,27 @@ +cache = $cache; + } + + public function update(DataRole $oldDataRole, DataRole $newDataRole) + { + $this->cache->forget(DataRoleCache::class . '@getById:' . $newDataRole->id()); + } + +} \ No newline at end of file diff --git a/src/Observers/DataUserObserverClearCache.php b/src/Observers/DataUserObserverClearCache.php new file mode 100644 index 0000000..dc6c99d --- /dev/null +++ b/src/Observers/DataUserObserverClearCache.php @@ -0,0 +1,27 @@ +cache = $cache; + } + + public function update(DataUser $oldDataUser, DataUser $newDataUser) + { + $this->cache->forget(DataUserCache::class . '@getById:' . $newDataUser->id()); + } + +} \ No newline at end of file diff --git a/src/Observers/GroupObserverCascadeDelete.php b/src/Observers/GroupObserverCascadeDelete.php new file mode 100644 index 0000000..2004bff --- /dev/null +++ b/src/Observers/GroupObserverCascadeDelete.php @@ -0,0 +1,61 @@ +userGroup = $userGroup; + $this->role = $role; + $this->groupGroupTag = $groupGroupTag; + } + + public function delete(Group $group) + { + $this->removeUsers($group); + $this->removeTags($group); + $this->deleteRoles($group); + } + + private function removeUsers(Group $group) + { + foreach($this->userGroup->getUsersThroughGroup($group) as $user) { + $this->userGroup->removeUserFromGroup($user, $group); + } + } + + private function removeTags(Group $group) + { + foreach($this->groupGroupTag->getTagsThroughGroup($group) as $tag) { + $this->groupGroupTag->removeTagFromGroup($tag, $group); + } + } + + private function deleteRoles(Group $group) + { + foreach($this->role->allThroughGroup($group) as $role) { + $this->role->delete($role->id()); + } + } + +} \ No newline at end of file diff --git a/src/Observers/GroupObserverClearCache.php b/src/Observers/GroupObserverClearCache.php new file mode 100644 index 0000000..4cc6e39 --- /dev/null +++ b/src/Observers/GroupObserverClearCache.php @@ -0,0 +1,43 @@ +cache = $cache; + } + + public function create(GroupModel $groupModel) + { + $this->cache->forget(GroupCache::class . '@count'); + $this->cache->forget(GroupCache::class . '@getByDataProviderId:' . $groupModel->dataProviderId()); + } + + public function delete(GroupModel $group) + { + $this->cache->forget(GroupCache::class . '@count'); + $this->cache->forget(GroupCache::class . '@getById:' . $group->id()); + $this->cache->forget(GroupCache::class . '@getByDataProviderId:' . $group->dataProviderId()); + } + + public function update(GroupModel $oldGroup, GroupModel $newGroup) + { + $this->cache->forget(GroupCache::class . '@count'); + $this->cache->forget(GroupCache::class . '@getById:' . $newGroup->id()); + $this->cache->forget(GroupCache::class . '@getByDataProviderId:' . $oldGroup->dataProviderId()); + $this->cache->forget(GroupCache::class . '@getByDataProviderId:' . $newGroup->dataProviderId()); + } + +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/DataGroupNotifier.php b/src/Observers/NotifyObservers/DataGroupNotifier.php new file mode 100644 index 0000000..4c0c93c --- /dev/null +++ b/src/Observers/NotifyObservers/DataGroupNotifier.php @@ -0,0 +1,86 @@ +dataGroupRepository = $dataGroupRepository; + } + + /** + * Get a data group by ID + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\DataGroup + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataGroup + { + return $this->dataGroupRepository->getById($id); + } + + /** + * Get a data group where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return \BristolSU\ControlDB\Contracts\Models\DataGroup + */ + public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Models\DataGroup + { + return $this->dataGroupRepository->getWhere($attributes); + } + + /** + * Get all data groups where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return Collection|\BristolSU\ControlDB\Contracts\Models\DataGroup[] + */ + public function getAllWhere($attributes = []): Collection + { + return $this->dataGroupRepository->getAllWhere($attributes); + } + + /** + * Create a group with the given attributes + * + * @param string|null $name Name of the group + * @param string|null $email Email of the group + * @return \BristolSU\ControlDB\Contracts\Models\DataGroup + */ + public function create(?string $name = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataGroup + { + $dataGroup = $this->dataGroupRepository->create($name, $email); + $this->notify('create', $dataGroup); + return $dataGroup; + } + + /** + * Update a group with the given attributes + * + * @param int $id + * @param string|null $name Name of the group + * @param string|null $email Email of the group + * @return \BristolSU\ControlDB\Contracts\Models\DataGroup + */ + public function update(int $id, ?string $name = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataGroup + { + $oldDataGroup = $this->getById($id); + $newDataGroup = $this->dataGroupRepository->update($id, $name, $email); + $this->notify('update', $oldDataGroup, $newDataGroup); + return $newDataGroup; + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/DataPositionNotifier.php b/src/Observers/NotifyObservers/DataPositionNotifier.php new file mode 100644 index 0000000..a5694d4 --- /dev/null +++ b/src/Observers/NotifyObservers/DataPositionNotifier.php @@ -0,0 +1,86 @@ +dataPositionRepository = $dataPositionRepository; + } + + /** + * Get a data position by ID + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\DataPosition + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataPosition + { + return $this->dataPositionRepository->getById($id); + } + + /** + * Get a data position where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return \BristolSU\ControlDB\Contracts\Models\DataPosition + */ + public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Models\DataPosition + { + return $this->dataPositionRepository->getWhere($attributes); + } + + /** + * Get all data positions where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return Collection|\BristolSU\ControlDB\Contracts\Models\DataPosition[] + */ + public function getAllWhere($attributes = []): Collection + { + return $this->dataPositionRepository->getAllWhere($attributes); + } + + /** + * Create a data position with the given attributes + * + * @param string|null $name Name of the position + * @param string|null $description Description of the position + * @return \BristolSU\ControlDB\Contracts\Models\DataPosition + */ + public function create(?string $name = null, ?string $description = null): \BristolSU\ControlDB\Contracts\Models\DataPosition + { + $dataPosition = $this->dataPositionRepository->create($name, $description); + $this->notify('create', $dataPosition); + return $dataPosition; + } + + /** + * Update a data position with the given attributes + * + * @param int $id + * @param string|null $name Name of the position + * @param string|null $description Description of the position + * @return \BristolSU\ControlDB\Contracts\Models\DataPosition + */ + public function update(int $id, ?string $name = null, ?string $description = null): \BristolSU\ControlDB\Contracts\Models\DataPosition + { + $oldDataPosition = $this->getById($id); + $newDataPosition = $this->dataPositionRepository->update($id, $name, $description); + $this->notify('update', $oldDataPosition, $newDataPosition); + return $newDataPosition; + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/DataRoleNotifier.php b/src/Observers/NotifyObservers/DataRoleNotifier.php new file mode 100644 index 0000000..9853029 --- /dev/null +++ b/src/Observers/NotifyObservers/DataRoleNotifier.php @@ -0,0 +1,88 @@ +dataRoleRepository = $dataRoleRepository; + } + + /** + * Get a data role by ID + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\DataRole + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataRole + { + return $this->dataRoleRepository->getById($id); + } + + /** + * Get a data role where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return \BristolSU\ControlDB\Contracts\Models\DataRole + */ + public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Models\DataRole + { + return $this->dataRoleRepository->getWhere($attributes); + } + + /** + * Get all data roles where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return Collection|\BristolSU\ControlDB\Contracts\Models\DataRole[] + */ + public function getAllWhere($attributes = []): Collection + { + return $this->dataRoleRepository->getAllWhere($attributes); + } + + /** + * Create a data role with the given attributes + * + * @param string|null $roleName Custom name for the role + * @param string|null $email Email of the role + * @return \BristolSU\ControlDB\Contracts\Models\DataRole + */ + public function create(?string $roleName = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataRole + { + $dataRole = $this->dataRoleRepository->create($roleName, $email); + $this->notify('create', $dataRole); + return $dataRole; + } + + /** + * Update a role with the given attributes + * + * @param int $id + * @param string|null $roleName Name of the role + * @param string|null $email Email of the role + * @return \BristolSU\ControlDB\Contracts\Models\DataRole + */ + public function update(int $id, ?string $roleName = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataRole + { + $oldDataRole = $this->getById($id); + $newDataRole = $this->dataRoleRepository->update($id, $roleName, $email); + $this->notify('update', $oldDataRole, $newDataRole); + return $newDataRole; + } + + +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/DataUserNotifier.php b/src/Observers/NotifyObservers/DataUserNotifier.php new file mode 100644 index 0000000..a0d4e7a --- /dev/null +++ b/src/Observers/NotifyObservers/DataUserNotifier.php @@ -0,0 +1,94 @@ +dataUserRepository = $dataUserRepository; + } + + /** + * Get a data user by ID + * + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\DataUser + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataUser + { + return $this->dataUserRepository->getById($id); + } + + /** + * Get a data user where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return \BristolSU\ControlDB\Contracts\Models\DataUser + */ + public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Models\DataUser + { + return $this->dataUserRepository->getWhere($attributes); + } + + /** + * Get all data users where the given attributes match, including additional attributes. + * + * @param array $attributes + * @return Collection|\BristolSU\ControlDB\Contracts\Models\DataUser[] + */ + public function getAllWhere($attributes = []): Collection + { + return $this->dataUserRepository->getAllWhere($attributes); + } + + /** + * Create a data user with the given attributes + * + * @param string|null $firstName First name of the user + * @param string|null $lastName Last name of the user + * @param string|null $email Email of the user + * @param \DateTime|null $dob Date of birth of the user + * @param string|null $preferredName Preferred name of the user + * + * @return \BristolSU\ControlDB\Contracts\Models\DataUser + */ + public function create(?string $firstName = null, ?string $lastName = null, ?string $email = null, ?\DateTime $dob = null, ?string $preferredName = null): \BristolSU\ControlDB\Contracts\Models\DataUser + { + $dataUser = $this->dataUserRepository->create($firstName, $lastName, $email, $dob, $preferredName); + $this->notify('create', $dataUser); + return $dataUser; + } + + /** + * Update a data user + * + * @param int $id + * @param string|null $firstName + * @param string|null $lastName + * @param string|null $email + * @param \DateTime|null $dob + * @param string|null $preferredName + * @return \BristolSU\ControlDB\Contracts\Models\DataUser + */ + public function update(int $id, ?string $firstName = null, ?string $lastName = null, ?string $email = null, ?\DateTime $dob = null, ?string $preferredName = null): \BristolSU\ControlDB\Contracts\Models\DataUser + { + $oldDataUser = $this->getById($id); + $newDataUser = $this->dataUserRepository->update($id, $firstName, $lastName, $email, $dob, $preferredName); + $this->notify('create', $oldDataUser, $newDataUser); + return $newDataUser; + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Framework/Notifier.php b/src/Observers/NotifyObservers/Framework/Notifier.php new file mode 100644 index 0000000..47a84c0 --- /dev/null +++ b/src/Observers/NotifyObservers/Framework/Notifier.php @@ -0,0 +1,43 @@ +observerStore = $observerStore; + $this->notifier = $notifier; + } + + public function attach($observer) + { + $this->observerStore->attach($this->notifier, $observer); + } + + public function detach($observer) + { + $this->observerStore->detach($this->notifier, $observer); + } + + public function notify($method, ...$params) + { + foreach($this->observerStore->forNotifier($this->notifier) as $notifierClass) { + $notifier = app($notifierClass); + if(method_exists($notifier, $method)) { + $notifier->{$method}(...$params); + } + } + } + +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Framework/Observe.php b/src/Observers/NotifyObservers/Framework/Observe.php new file mode 100644 index 0000000..cc51ebc --- /dev/null +++ b/src/Observers/NotifyObservers/Framework/Observe.php @@ -0,0 +1,18 @@ +observers)) { + $this->observers[$notifier] = []; + } + $this->observers[$notifier][] = $observer; + } + + public function detach($notifier, $observer): void + { + if (array_key_exists($notifier, $this->observers)) { + if (array_key_exists($observer, $this->observers[$notifier])) { + unset($this->observers[$notifier][$observer]); + } + } + } + + public function forNotifier($notifier): array + { + if(array_key_exists($notifier, $this->observers)) { + return $this->observers[$notifier]; + } + return []; + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/GroupNotifier.php b/src/Observers/NotifyObservers/GroupNotifier.php new file mode 100644 index 0000000..d23adcb --- /dev/null +++ b/src/Observers/NotifyObservers/GroupNotifier.php @@ -0,0 +1,119 @@ +groupRepository = $groupRepository; + } + + /** + * Get a group by ID + * + * @param int $id ID of the group + * @return GroupModel + */ + public function getById(int $id): GroupModel + { + return $this->groupRepository->getById($id); + } + + /** + * Get a group by its data provider ID + * + * @param int $dataProviderId + * @return GroupModel + */ + public function getByDataProviderId(int $dataProviderId): GroupModel + { + return $this->groupRepository->getByDataProviderId($dataProviderId); + } + + /** + * Get all groups + * + * @return Collection|GroupModel[] + */ + public function all(): Collection + { + return $this->groupRepository->all(); + } + + /** + * Create a new group + * + * @param int $dataProviderId + * @return GroupModel + */ + public function create(int $dataProviderId): GroupModel + { + $groupModel = $this->groupRepository->create($dataProviderId); + $this->notify('create', $groupModel); + return $groupModel; + } + + /** + * Delete a group by ID + * + * @param int $id + */ + public function delete(int $id): void + { + $groupModel = $this->getById($id); + $this->groupRepository->delete($id); + $this->notify('delete', $groupModel); + } + + /** + * Update the group model + * + * @param int $id + * @param int $dataProviderId New data provider ID + * @return GroupModel + */ + public function update(int $id, int $dataProviderId): GroupModel + { + $oldGroupModel = $this->getById($id); + $newGroupModel = $this->groupRepository->update($id, $dataProviderId); + $this->notify('update', $oldGroupModel, $newGroupModel); + return $newGroupModel; + } + + /** + * Paginate through all the groups + * + * @param int $page The page number to return + * @param int $perPage The number of results to return per page + * + * @return Collection|GroupModel[] + */ + public function paginate(int $page, int $perPage): Collection + { + return $this->groupRepository->paginate($page, $perPage); + } + + /** + * Get the number of groups + * + * @return int + */ + public function count(): int + { + return $this->groupRepository->count(); + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Pivots/Tags/GroupGroupTagNotifier.php b/src/Observers/NotifyObservers/Pivots/Tags/GroupGroupTagNotifier.php new file mode 100644 index 0000000..dda58d2 --- /dev/null +++ b/src/Observers/NotifyObservers/Pivots/Tags/GroupGroupTagNotifier.php @@ -0,0 +1,73 @@ +groupGroupTagRepository = $groupGroupTagRepository; + } + + /** + * Tag a group + * + * @param GroupTag $groupTag Tag to tag the group with + * @param Group $group Group to tag + * @return void + */ + public function addTagToGroup(GroupTag $groupTag, Group $group): void + { + $this->groupGroupTagRepository->addTagToGroup($groupTag, $group); + $this->notify('addTagToGroup', $groupTag, $group); + } + + /** + * Remove a tag from a group + * + * @param GroupTag $groupTag Tag to remove from the group + * @param Group $group Group to remove the tag from + * @return void + */ + public function removeTagFromGroup(GroupTag $groupTag, Group $group): void + { + $this->groupGroupTagRepository->removeTagFromGroup($groupTag, $group); + $this->notify('removeTagFromGroup', $groupTag, $group); + } + + /** + * Get all tags a group is tagged with + * + * @param Group $group Group to retrieve tags from + * @return Collection|GroupTag[] Tags the group is tagged with + */ + public function getTagsThroughGroup(Group $group): Collection + { + return $this->groupGroupTagRepository->getTagsThroughGroup($group); + } + + /** + * Get all groups tagged with a tag + * + * @param GroupTag $groupTag Tag to use to retrieve groups + * @return Collection|Group[] Groups tagged with the given tag + */ + public function getGroupsThroughTag(GroupTag $groupTag): Collection + { + return $this->groupGroupTagRepository->getGroupsThroughTag($groupTag); + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Pivots/Tags/PositionPositionTagNotifier.php b/src/Observers/NotifyObservers/Pivots/Tags/PositionPositionTagNotifier.php new file mode 100644 index 0000000..078f733 --- /dev/null +++ b/src/Observers/NotifyObservers/Pivots/Tags/PositionPositionTagNotifier.php @@ -0,0 +1,73 @@ +positionPositionTagRepository = $positionPositionTagRepository; + } + + /** + * Tag a position + * + * @param PositionTag $positionTag Tag to tag the position with + * @param Position $position Position to tag + * @return void + */ + public function addTagToPosition(PositionTag $positionTag, Position $position): void + { + $this->positionPositionTagRepository->addTagToPosition($positionTag, $position); + $this->notify('addTagToPosition', $positionTag, $position); + } + + /** + * Remove a tag from a position + * + * @param PositionTag $positionTag Tag to remove from the position + * @param Position $position Position to remove the tag from + * @return void + */ + public function removeTagFromPosition(PositionTag $positionTag, Position $position): void + { + $this->positionPositionTagRepository->removeTagFromPosition($positionTag, $position); + $this->notify('removeTagFromPosition', $positionTag, $position); + } + + /** + * Get all tags a position is tagged with + * + * @param Position $position Position to retrieve tags from + * @return Collection|PositionTag[] Tags the position is tagged with + */ + public function getTagsThroughPosition(Position $position): Collection + { + return $this->positionPositionTagRepository->getTagsThroughPosition($position); + } + + /** + * Get all positions tagged with a tag + * + * @param PositionTag $positionTag Tag to use to retrieve positions + * @return Collection|Position[] Positions tagged with the given tag + */ + public function getPositionsThroughTag(PositionTag $positionTag): Collection + { + return $this->positionPositionTagRepository->getPositionsThroughTag($positionTag); + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Pivots/Tags/RoleRoleTagNotifier.php b/src/Observers/NotifyObservers/Pivots/Tags/RoleRoleTagNotifier.php new file mode 100644 index 0000000..2b55259 --- /dev/null +++ b/src/Observers/NotifyObservers/Pivots/Tags/RoleRoleTagNotifier.php @@ -0,0 +1,73 @@ +roleRoleTagRepository = $roleRoleTagRepository; + } + + /** + * Tag a role + * + * @param RoleTag $roleTag Tag to tag the role with + * @param Role $role Role to tag + * @return void + */ + public function addTagToRole(RoleTag $roleTag, Role $role): void + { + $this->roleRoleTagRepository->addTagToRole($roleTag, $role); + $this->notify('addTagToRole', $roleTag, $role); + } + + /** + * Remove a tag from a role + * + * @param RoleTag $roleTag Tag to remove from the role + * @param Role $role Role to remove the tag from + * @return void + */ + public function removeTagFromRole(RoleTag $roleTag, Role $role): void + { + $this->roleRoleTagRepository->removeTagFromRole($roleTag, $role); + $this->notify('removeTagFromRole', $roleTag, $role); + } + + /** + * Get all tags a role is tagged with + * + * @param Role $role Role to retrieve tags from + * @return Collection|RoleTag[] Tags the role is tagged with + */ + public function getTagsThroughRole(Role $role): Collection + { + return $this->roleRoleTagRepository->getTagsThroughRole($role); + } + + /** + * Get all roles tagged with a tag + * + * @param RoleTag $roleTag Tag to use to retrieve roles + * @return Collection|Role[] Roles tagged with the given tag + */ + public function getRolesThroughTag(RoleTag $roleTag): Collection + { + return $this->roleRoleTagRepository->getRolesThroughTag($roleTag); + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Pivots/Tags/UserUserTagNotifier.php b/src/Observers/NotifyObservers/Pivots/Tags/UserUserTagNotifier.php new file mode 100644 index 0000000..b039903 --- /dev/null +++ b/src/Observers/NotifyObservers/Pivots/Tags/UserUserTagNotifier.php @@ -0,0 +1,73 @@ +userUserTagRepository = $userUserTagRepository; + } + + /** + * Tag a user + * + * @param UserTag $userTag Tag to tag the user with + * @param User $user User to tag + * @return void + */ + public function addTagToUser(UserTag $userTag, User $user): void + { + $this->userUserTagRepository->addTagToUser($userTag, $user); + $this->notify('addTagToUser', $userTag, $user); + } + + /** + * Remove a tag from a user + * + * @param UserTag $userTag Tag to remove from the user + * @param User $user User to remove the tag from + * @return void + */ + public function removeTagFromUser(UserTag $userTag, User $user): void + { + $this->userUserTagRepository->removeTagFromUser($userTag, $user); + $this->notify('removeTagFromUser', $userTag, $user); + } + + /** + * Get all tags a user is tagged with + * + * @param User $user User to retrieve tags from + * @return Collection|UserTag[] Tags the user is tagged with + */ + public function getTagsThroughUser(User $user): Collection + { + return $this->userUserTagRepository->getTagsThroughUser($user); + } + + /** + * Get all users tagged with a tag + * + * @param UserTag $userTag Tag to use to retrieve users + * @return Collection|User[] Users tagged with the given tag + */ + public function getUsersThroughTag(UserTag $userTag): Collection + { + return $this->userUserTagRepository->getUsersThroughTag($userTag); + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Pivots/UserGroupNotifier.php b/src/Observers/NotifyObservers/Pivots/UserGroupNotifier.php new file mode 100644 index 0000000..c02df95 --- /dev/null +++ b/src/Observers/NotifyObservers/Pivots/UserGroupNotifier.php @@ -0,0 +1,72 @@ +userGroupRepository = $userGroupRepository; + } + + /** + * Get all users who are members of a group + * + * @param Group $group + * @return User[]|Collection Users who are members of the group + */ + public function getUsersThroughGroup(Group $group): Collection + { + return $this->userGroupRepository->getUsersThroughGroup($group); + } + + /** + * Get all groups a user belongs to + * + * @param User $user + * @return Group[]|Collection Groups the user is a member of + */ + public function getGroupsThroughUser(User $user): Collection + { + return $this->userGroupRepository->getGroupsThroughUser($user); + } + + /** + * Add a user to a group + * + * @param User $user User to add to the group + * @param Group $group Group to add the user to + * @return void + */ + public function addUserToGroup(User $user, Group $group): void + { + $this->userGroupRepository->addUserToGroup($user, $group); + $this->notify('addUserToGroup', $user, $group); + } + + /** + * Remove a user from a group + * @param User $user User to remove from the group + * @param Group $group Group to remove the user from + * @return void + */ + public function removeUserFromGroup(User $user, Group $group): void + { + $this->userGroupRepository->removeUserFromGroup($user, $group); + $this->notify('removeUserFromGroup', $user, $group); + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Pivots/UserRoleNotifier.php b/src/Observers/NotifyObservers/Pivots/UserRoleNotifier.php new file mode 100644 index 0000000..31cf30d --- /dev/null +++ b/src/Observers/NotifyObservers/Pivots/UserRoleNotifier.php @@ -0,0 +1,72 @@ +userRoleRepository = $userRoleRepository; + } + + /** + * Get all users who are members of a role + * + * @param Role $role + * @return User[]|Collection Users who are members of the role + */ + public function getUsersThroughRole(Role $role): Collection + { + return $this->userRoleRepository->getUsersThroughRole($role); + } + + /** + * Get all roles a user belongs to + * + * @param User $user + * @return Role[]|Collection Roles the user is a member of + */ + public function getRolesThroughUser(User $user): Collection + { + return $this->userRoleRepository->getRolesThroughUser($user); + } + + /** + * Add a user to a role + * + * @param User $user User to add to the role + * @param Role $role Role to add the user to + * @return void + */ + public function addUserToRole(User $user, Role $role): void + { + $this->userRoleRepository->addUserToRole($user, $role); + $this->notify('addUserToRole', $user, $role); + } + + /** + * Remove a user from a role + * @param User $user User to remove from the role + * @param Role $role Role to remove the user from + * @return void + */ + public function removeUserFromRole(User $user, Role $role): void + { + $this->userRoleRepository->removeUserFromRole($user, $role); + $this->notify('removeUserFromRole', $user, $role); + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/PositionNotifier.php b/src/Observers/NotifyObservers/PositionNotifier.php new file mode 100644 index 0000000..aecc4ab --- /dev/null +++ b/src/Observers/NotifyObservers/PositionNotifier.php @@ -0,0 +1,119 @@ +positionRepository = $positionRepository; + } + + /** + * Get a position by ID + * + * @param int $id ID of the position + * @return PositionModel + */ + public function getById(int $id): PositionModel + { + return $this->positionRepository->getById($id); + } + + /** + * Get a position by its data provider ID + * + * @param int $dataProviderId + * @return PositionModel + */ + public function getByDataProviderId(int $dataProviderId): PositionModel + { + return $this->positionRepository->getByDataProviderId($dataProviderId); + } + + /** + * Get all positions + * + * @return Collection|PositionModel[] + */ + public function all(): Collection + { + return $this->positionRepository->all(); + } + + /** + * Create a new position + * + * @param int $dataProviderId + * @return PositionModel + */ + public function create(int $dataProviderId): PositionModel + { + $positionModel = $this->positionRepository->create($dataProviderId); + $this->notify('create', $positionModel); + return $positionModel; + } + + /** + * Delete a position by ID + * + * @param int $id + */ + public function delete(int $id): void + { + $positionModel = $this->getById($id); + $this->positionRepository->delete($id); + $this->notify('delete', $positionModel); + } + + /** + * Update the position model + * + * @param int $id + * @param int $dataProviderId New data provider ID + * @return PositionModel + */ + public function update(int $id, int $dataProviderId): PositionModel + { + $oldPositionModel = $this->getById($id); + $newPositionModel = $this->positionRepository->update($id, $dataProviderId); + $this->notify('update', $oldPositionModel, $newPositionModel); + return $newPositionModel; + } + + /** + * Paginate through all the positions + * + * @param int $page The page number to return + * @param int $perPage The number of results to return per page + * + * @return Collection|PositionModel[] + */ + public function paginate(int $page, int $perPage): Collection + { + return $this->positionRepository->paginate($page, $perPage); + } + + /** + * Get the number of positions + * + * @return int + */ + public function count(): int + { + return $this->positionRepository->count(); + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/RoleNotifier.php b/src/Observers/NotifyObservers/RoleNotifier.php new file mode 100644 index 0000000..35b1e57 --- /dev/null +++ b/src/Observers/NotifyObservers/RoleNotifier.php @@ -0,0 +1,145 @@ +roleRepository = $roleRepository; + } + + /** + * Get a role by ID + * + * @param int $id + * @return RoleModel + */ + public function getById(int $id): RoleModel + { + return $this->roleRepository->getById($id); + } + + /** + * Get all roles + * + * @return Collection|\BristolSU\ControlDB\Contracts\Models\Role[] + */ + public function all(): Collection + { + return $this->roleRepository->all(); + } + + /** + * Get a role by data provider ID + * + * @param int $dataProviderId + * @return RoleModel + */ + public function getByDataProviderId(int $dataProviderId): RoleModel + { + return $this->roleRepository->getByDataProviderId($dataProviderId); + } + + /** + * Create a new role + * + * @param int $positionId + * @param int $groupId + * @param int $dataProviderId + * @return RoleModel + */ + public function create(int $positionId, int $groupId, int $dataProviderId): RoleModel + { + $roleModel = $this->roleRepository->create($positionId, $groupId, $dataProviderId); + $this->notify('create', $roleModel); + return $roleModel; + } + + /** + * Delete a role + * + * @param int $id + */ + public function delete(int $id): void + { + $roleModel = $this->getById($id); + $this->roleRepository->delete($id); + $this->notify('delete', $roleModel); + } + + /** + * Update the role model + * + * @param int $id + * @param int $positionId + * @param int $groupId + * @param int $dataProviderId New data provider ID + * @return RoleModel + */ + public function update(int $id, int $positionId, int $groupId, int $dataProviderId): RoleModel + { + $oldRoleModel = $this->getById($id); + $newRoleModel = $this->roleRepository->update($id, $positionId, $groupId, $dataProviderId); + $this->notify('update', $oldRoleModel, $newRoleModel); + return $newRoleModel; + } + + /** + * Get all roles that belong to the given group + * + * @param \BristolSU\ControlDB\Contracts\Models\Group $group + * @return Collection|RoleModel[] + */ + public function allThroughGroup(\BristolSU\ControlDB\Contracts\Models\Group $group): Collection + { + return $this->roleRepository->allThroughGroup($group); + } + + /** + * Get all roles that belong to the given position + * @param \BristolSU\ControlDB\Contracts\Models\Position $position + * @return Collection|RoleModel[] + */ + public function allThroughPosition(\BristolSU\ControlDB\Contracts\Models\Position $position): Collection + { + return $this->roleRepository->allThroughPosition($position); + } + + /** + * Paginate through all the roles + * + * @param int $page The page number to return + * @param int $perPage The number of results to return per page + * + * @return Collection|RoleModel[] + */ + public function paginate(int $page, int $perPage): Collection + { + return $this->roleRepository->paginate($page, $perPage); + } + + /** + * Get the number of roles + * + * @return int + */ + public function count(): int + { + return $this->roleRepository->count(); + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Tags/GroupTagCategoryNotifier.php b/src/Observers/NotifyObservers/Tags/GroupTagCategoryNotifier.php new file mode 100644 index 0000000..07b7f3d --- /dev/null +++ b/src/Observers/NotifyObservers/Tags/GroupTagCategoryNotifier.php @@ -0,0 +1,100 @@ +groupTagCategoryRepository = $groupTagCategoryRepository; + } + + /** + * Get all group tag categories + * + * @return Collection|GroupTagCategoryModel[] + */ + public function all(): Collection + { + return $this->groupTagCategoryRepository->all(); + } + + /** + * Get a tag category by the reference + * + * @param string $reference Reference of the tag + * @return GroupTagCategoryModel + */ + public function getByReference(string $reference): GroupTagCategoryModel + { + return $this->groupTagCategoryRepository->getByReference($reference); + } + + /** + * Get a group tag category by id + * + * @param int $id + * @return GroupTagCategoryModel + */ + public function getById(int $id): GroupTagCategoryModel + { + return $this->groupTagCategoryRepository->getById($id); + } + + /** + * Delete a group tag category + * + * @param int $id ID of the group tag category to delete + */ + public function delete(int $id): void + { + $groupTagCategory = $this->getById($id); + $this->groupTagCategoryRepository->delete($id); + $this->notify('delete', $groupTagCategory); + } + + /** + * Create a group tag category + * + * @param string $name Name of the group tag category + * @param string $description Description of the group tag category + * @param string $reference Reference of the group tag category + * @return GroupTagCategoryModel New group tag category + */ + public function create(string $name, string $description, string $reference): GroupTagCategoryModel + { + $groupTagCategory = $this->groupTagCategoryRepository->create($name, $description, $reference); + $this->notify('create', $groupTagCategory); + return $groupTagCategory; + } + + /** + * Update a group tag category + * + * @param int $id + * @param string $name Name of the group tag category + * @param string $description Description of the group tag category + * @param string $reference Reference of the group tag category + * @return GroupTagCategoryModel New group tag category + */ + public function update(int $id, string $name, string $description, string $reference): GroupTagCategoryModel + { + $oldGroupTagCategory = $this->getById($id); + $newGroupTagCategory = $this->groupTagCategoryRepository->update($id, $name, $description, $reference); + $this->notify('update', $oldGroupTagCategory, $newGroupTagCategory); + return $newGroupTagCategory; + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Tags/GroupTagNotifier.php b/src/Observers/NotifyObservers/Tags/GroupTagNotifier.php new file mode 100644 index 0000000..b435d47 --- /dev/null +++ b/src/Observers/NotifyObservers/Tags/GroupTagNotifier.php @@ -0,0 +1,114 @@ +groupTagRepository = $groupTagRepository; + } + + /** + * Get all group tags + * + * @return Collection|\BristolSU\ControlDB\Contracts\Models\Tags\GroupTag[] + */ + public function all(): Collection + { + return $this->groupTagRepository->all(); + } + + /** + * Get a tag by the full reference + * + * The full reference looks like 'tag_category_ref.tag_ref' + * + * @param string $reference + * @return \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + */ + public function getTagByFullReference(string $reference): \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + { + return $this->groupTagRepository->getTagByFullReference($reference); + } + + /** + * Get a group tag by id + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + { + return $this->groupTagRepository->getById($id); + } + + /** + * Create a group tag + * + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + */ + public function create(string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + { + $groupTag = $this->groupTagRepository->create($name, $description, $reference, $tagCategoryId); + $this->notify('create', $groupTag); + return $groupTag; + } + + /** + * Update a group tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + { + $oldGroupTag = $this->getById($id); + $newGroupTag = $this->groupTagRepository->update($id, $name, $description, $reference, $tagCategoryId); + $this->notify('update', $oldGroupTag, $newGroupTag); + return $newGroupTag; + } + + /** + * Delete a group tag + * + * @param int $id ID of the tag to delete + */ + public function delete(int $id): void + { + $groupTag = $this->getById($id); + $this->groupTagRepository->delete($id); + $this->notify('delete', $groupTag); + } + + /** + * Get all tags through a tag category + * + * @param \BristolSU\ControlDB\Contracts\Models\Tags\GroupTagCategory $groupTagCategory + * @return Collection|GroupTagRepository Tags with the given group tag category + */ + public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags\GroupTagCategory $groupTagCategory): Collection + { + return $this->groupTagRepository->allThroughTagCategory($groupTagCategory); + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Tags/PositionTagCategoryNotifier.php b/src/Observers/NotifyObservers/Tags/PositionTagCategoryNotifier.php new file mode 100644 index 0000000..1a67dde --- /dev/null +++ b/src/Observers/NotifyObservers/Tags/PositionTagCategoryNotifier.php @@ -0,0 +1,100 @@ +positionTagCategoryRepository = $positionTagCategoryRepository; + } + + /** + * Get all position tag categories + * + * @return Collection|PositionTagCategoryModel[] + */ + public function all(): Collection + { + return $this->positionTagCategoryRepository->all(); + } + + /** + * Get a tag category by the reference + * + * @param string $reference Reference of the tag + * @return PositionTagCategoryModel + */ + public function getByReference(string $reference): PositionTagCategoryModel + { + return $this->positionTagCategoryRepository->getByReference($reference); + } + + /** + * Get a position tag category by id + * + * @param int $id + * @return PositionTagCategoryModel + */ + public function getById(int $id): PositionTagCategoryModel + { + return $this->positionTagCategoryRepository->getById($id); + } + + /** + * Delete a position tag category + * + * @param int $id ID of the position tag category to delete + */ + public function delete(int $id): void + { + $positionTagCategory = $this->getById($id); + $this->positionTagCategoryRepository->delete($id); + $this->notify('delete', $positionTagCategory); + } + + /** + * Create a position tag category + * + * @param string $name Name of the position tag category + * @param string $description Description of the position tag category + * @param string $reference Reference of the position tag category + * @return PositionTagCategoryModel New position tag category + */ + public function create(string $name, string $description, string $reference): PositionTagCategoryModel + { + $positionTagCategory = $this->positionTagCategoryRepository->create($name, $description, $reference); + $this->notify('create', $positionTagCategory); + return $positionTagCategory; + } + + /** + * Update a position tag category + * + * @param int $id + * @param string $name Name of the position tag category + * @param string $description Description of the position tag category + * @param string $reference Reference of the position tag category + * @return PositionTagCategoryModel New position tag category + */ + public function update(int $id, string $name, string $description, string $reference): PositionTagCategoryModel + { + $oldPositionTagCategory = $this->getById($id); + $newPositionTagCategory = $this->positionTagCategoryRepository->update($id, $name, $description, $reference); + $this->notify('update', $oldPositionTagCategory, $newPositionTagCategory); + return $newPositionTagCategory; + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Tags/PositionTagNotifier.php b/src/Observers/NotifyObservers/Tags/PositionTagNotifier.php new file mode 100644 index 0000000..e5fe98c --- /dev/null +++ b/src/Observers/NotifyObservers/Tags/PositionTagNotifier.php @@ -0,0 +1,114 @@ +positionTagRepository = $positionTagRepository; + } + + /** + * Get all position tags + * + * @return Collection|\BristolSU\ControlDB\Contracts\Models\Tags\PositionTag[] + */ + public function all(): Collection + { + return $this->positionTagRepository->all(); + } + + /** + * Get a tag by the full reference + * + * The full reference looks like 'tag_category_ref.tag_ref' + * + * @param string $reference + * @return \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + */ + public function getTagByFullReference(string $reference): \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + { + return $this->positionTagRepository->getTagByFullReference($reference); + } + + /** + * Get a position tag by id + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + { + return $this->positionTagRepository->getById($id); + } + + /** + * Create a position tag + * + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + */ + public function create(string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + { + $positionTag = $this->positionTagRepository->create($name, $description, $reference, $tagCategoryId); + $this->notify('create', $positionTag); + return $positionTag; + } + + /** + * Update a position tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + { + $oldPositionTag = $this->getById($id); + $newPositionTag = $this->positionTagRepository->update($id, $name, $description, $reference, $tagCategoryId); + $this->notify('update', $oldPositionTag, $newPositionTag); + return $newPositionTag; + } + + /** + * Delete a position tag + * + * @param int $id ID of the tag to delete + */ + public function delete(int $id): void + { + $positionTag = $this->getById($id); + $this->positionTagRepository->delete($id); + $this->notify('delete', $positionTag); + } + + /** + * Get all tags through a tag category + * + * @param \BristolSU\ControlDB\Contracts\Models\Tags\PositionTagCategory $positionTagCategory + * @return Collection|PositionTagRepository Tags with the given position tag category + */ + public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags\PositionTagCategory $positionTagCategory): Collection + { + return $this->positionTagRepository->allThroughTagCategory($positionTagCategory); + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Tags/RoleTagCategoryNotifier.php b/src/Observers/NotifyObservers/Tags/RoleTagCategoryNotifier.php new file mode 100644 index 0000000..cc3ec6c --- /dev/null +++ b/src/Observers/NotifyObservers/Tags/RoleTagCategoryNotifier.php @@ -0,0 +1,100 @@ +roleTagCategoryRepository = $roleTagCategoryRepository; + } + + /** + * Get all role tag categories + * + * @return Collection|RoleTagCategoryModel[] + */ + public function all(): Collection + { + return $this->roleTagCategoryRepository->all(); + } + + /** + * Get a tag category by the reference + * + * @param string $reference Reference of the tag + * @return RoleTagCategoryModel + */ + public function getByReference(string $reference): RoleTagCategoryModel + { + return $this->roleTagCategoryRepository->getByReference($reference); + } + + /** + * Get a role tag category by id + * + * @param int $id + * @return RoleTagCategoryModel + */ + public function getById(int $id): RoleTagCategoryModel + { + return $this->roleTagCategoryRepository->getById($id); + } + + /** + * Delete a role tag category + * + * @param int $id ID of the role tag category to delete + */ + public function delete(int $id): void + { + $roleTagCategory = $this->getById($id); + $this->roleTagCategoryRepository->delete($id); + $this->notify('delete', $roleTagCategory); + } + + /** + * Create a role tag category + * + * @param string $name Name of the role tag category + * @param string $description Description of the role tag category + * @param string $reference Reference of the role tag category + * @return RoleTagCategoryModel New role tag category + */ + public function create(string $name, string $description, string $reference): RoleTagCategoryModel + { + $roleTagCategory = $this->roleTagCategoryRepository->create($name, $description, $reference); + $this->notify('create', $roleTagCategory); + return $roleTagCategory; + } + + /** + * Update a role tag category + * + * @param int $id + * @param string $name Name of the role tag category + * @param string $description Description of the role tag category + * @param string $reference Reference of the role tag category + * @return RoleTagCategoryModel New role tag category + */ + public function update(int $id, string $name, string $description, string $reference): RoleTagCategoryModel + { + $oldRoleTagCategory = $this->getById($id); + $newRoleTagCategory = $this->roleTagCategoryRepository->update($id, $name, $description, $reference); + $this->notify('update', $oldRoleTagCategory, $newRoleTagCategory); + return $newRoleTagCategory; + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Tags/RoleTagNotifier.php b/src/Observers/NotifyObservers/Tags/RoleTagNotifier.php new file mode 100644 index 0000000..d76b613 --- /dev/null +++ b/src/Observers/NotifyObservers/Tags/RoleTagNotifier.php @@ -0,0 +1,114 @@ +roleTagRepository = $roleTagRepository; + } + + /** + * Get all role tags + * + * @return Collection|\BristolSU\ControlDB\Contracts\Models\Tags\RoleTag[] + */ + public function all(): Collection + { + return $this->roleTagRepository->all(); + } + + /** + * Get a tag by the full reference + * + * The full reference looks like 'tag_category_ref.tag_ref' + * + * @param string $reference + * @return \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + */ + public function getTagByFullReference(string $reference): \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + { + return $this->roleTagRepository->getTagByFullReference($reference); + } + + /** + * Get a role tag by id + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + { + return $this->roleTagRepository->getById($id); + } + + /** + * Create a role tag + * + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + */ + public function create(string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + { + $roleTag = $this->roleTagRepository->create($name, $description, $reference, $tagCategoryId); + $this->notify('create', $roleTag); + return $roleTag; + } + + /** + * Update a role tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + { + $oldRoleTag = $this->getById($id); + $newRoleTag = $this->roleTagRepository->update($id, $name, $description, $reference, $tagCategoryId); + $this->notify('update', $oldRoleTag, $newRoleTag); + return $newRoleTag; + } + + /** + * Delete a role tag + * + * @param int $id ID of the tag to delete + */ + public function delete(int $id): void + { + $roleTag = $this->getById($id); + $this->roleTagRepository->delete($id); + $this->notify('delete', $roleTag); + } + + /** + * Get all tags through a tag category + * + * @param \BristolSU\ControlDB\Contracts\Models\Tags\RoleTagCategory $roleTagCategory + * @return Collection|RoleTagRepository Tags with the given role tag category + */ + public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags\RoleTagCategory $roleTagCategory): Collection + { + return $this->roleTagRepository->allThroughTagCategory($roleTagCategory); + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Tags/UserTagCategoryNotifier.php b/src/Observers/NotifyObservers/Tags/UserTagCategoryNotifier.php new file mode 100644 index 0000000..c3039b3 --- /dev/null +++ b/src/Observers/NotifyObservers/Tags/UserTagCategoryNotifier.php @@ -0,0 +1,100 @@ +userTagCategoryRepository = $userTagCategoryRepository; + } + + /** + * Get all user tag categories + * + * @return Collection|UserTagCategoryModel[] + */ + public function all(): Collection + { + return $this->userTagCategoryRepository->all(); + } + + /** + * Get a tag category by the reference + * + * @param string $reference Reference of the tag + * @return UserTagCategoryModel + */ + public function getByReference(string $reference): UserTagCategoryModel + { + return $this->userTagCategoryRepository->getByReference($reference); + } + + /** + * Get a user tag category by id + * + * @param int $id + * @return UserTagCategoryModel + */ + public function getById(int $id): UserTagCategoryModel + { + return $this->userTagCategoryRepository->getById($id); + } + + /** + * Delete a user tag category + * + * @param int $id ID of the user tag category to delete + */ + public function delete(int $id): void + { + $userTagCategory = $this->getById($id); + $this->userTagCategoryRepository->delete($id); + $this->notify('delete', $userTagCategory); + } + + /** + * Create a user tag category + * + * @param string $name Name of the user tag category + * @param string $description Description of the user tag category + * @param string $reference Reference of the user tag category + * @return UserTagCategoryModel New user tag category + */ + public function create(string $name, string $description, string $reference): UserTagCategoryModel + { + $userTagCategory = $this->userTagCategoryRepository->create($name, $description, $reference); + $this->notify('create', $userTagCategory); + return $userTagCategory; + } + + /** + * Update a user tag category + * + * @param int $id + * @param string $name Name of the user tag category + * @param string $description Description of the user tag category + * @param string $reference Reference of the user tag category + * @return UserTagCategoryModel New user tag category + */ + public function update(int $id, string $name, string $description, string $reference): UserTagCategoryModel + { + $oldUserTagCategory = $this->getById($id); + $newUserTagCategory = $this->userTagCategoryRepository->update($id, $name, $description, $reference); + $this->notify('update', $oldUserTagCategory, $newUserTagCategory); + return $newUserTagCategory; + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/Tags/UserTagNotifier.php b/src/Observers/NotifyObservers/Tags/UserTagNotifier.php new file mode 100644 index 0000000..dbb35c7 --- /dev/null +++ b/src/Observers/NotifyObservers/Tags/UserTagNotifier.php @@ -0,0 +1,114 @@ +userTagRepository = $userTagRepository; + } + + /** + * Get all user tags + * + * @return Collection|\BristolSU\ControlDB\Contracts\Models\Tags\UserTag[] + */ + public function all(): Collection + { + return $this->userTagRepository->all(); + } + + /** + * Get a tag by the full reference + * + * The full reference looks like 'tag_category_ref.tag_ref' + * + * @param string $reference + * @return \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + */ + public function getTagByFullReference(string $reference): \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + { + return $this->userTagRepository->getTagByFullReference($reference); + } + + /** + * Get a user tag by id + * + * @param int $id + * @return \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + */ + public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + { + return $this->userTagRepository->getById($id); + } + + /** + * Create a user tag + * + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + */ + public function create(string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + { + $userTag = $this->userTagRepository->create($name, $description, $reference, $tagCategoryId); + $this->notify('create', $userTag); + return $userTag; + } + + /** + * Update a user tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + { + $oldUserTag = $this->getById($id); + $newUserTag = $this->userTagRepository->update($id, $name, $description, $reference, $tagCategoryId); + $this->notify('update', $oldUserTag, $newUserTag); + return $newUserTag; + } + + /** + * Delete a user tag + * + * @param int $id ID of the tag to delete + */ + public function delete(int $id): void + { + $userTag = $this->getById($id); + $this->userTagRepository->delete($id); + $this->notify('delete', $userTag); + } + + /** + * Get all tags through a tag category + * + * @param \BristolSU\ControlDB\Contracts\Models\Tags\UserTagCategory $userTagCategory + * @return Collection|UserTagRepository Tags with the given user tag category + */ + public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags\UserTagCategory $userTagCategory): Collection + { + return $this->userTagRepository->allThroughTagCategory($userTagCategory); + } +} \ No newline at end of file diff --git a/src/Observers/NotifyObservers/UserNotifier.php b/src/Observers/NotifyObservers/UserNotifier.php new file mode 100644 index 0000000..49b42c9 --- /dev/null +++ b/src/Observers/NotifyObservers/UserNotifier.php @@ -0,0 +1,119 @@ +userRepository = $userRepository; + } + + /** + * Get a user by ID + * + * @param int $id ID of the user + * @return UserModel + */ + public function getById(int $id): UserModel + { + return $this->userRepository->getById($id); + } + + /** + * Get a user by its data provider ID + * + * @param int $dataProviderId + * @return UserModel + */ + public function getByDataProviderId(int $dataProviderId): UserModel + { + return $this->userRepository->getByDataProviderId($dataProviderId); + } + + /** + * Get all users + * + * @return Collection|UserModel[] + */ + public function all(): Collection + { + return $this->userRepository->all(); + } + + /** + * Create a new user + * + * @param int $dataProviderId + * @return UserModel + */ + public function create(int $dataProviderId): UserModel + { + $userModel = $this->userRepository->create($dataProviderId); + $this->notify('create', $userModel); + return $userModel; + } + + /** + * Delete a user by ID + * + * @param int $id + */ + public function delete(int $id): void + { + $userModel = $this->getById($id); + $this->userRepository->delete($id); + $this->notify('delete', $userModel); + } + + /** + * Update the user model + * + * @param int $id + * @param int $dataProviderId New data provider ID + * @return UserModel + */ + public function update(int $id, int $dataProviderId): UserModel + { + $oldUserModel = $this->getById($id); + $newUserModel = $this->userRepository->update($id, $dataProviderId); + $this->notify('update', $oldUserModel, $newUserModel); + return $newUserModel; + } + + /** + * Paginate through all the users + * + * @param int $page The page number to return + * @param int $perPage The number of results to return per page + * + * @return Collection|UserModel[] + */ + public function paginate(int $page, int $perPage): Collection + { + return $this->userRepository->paginate($page, $perPage); + } + + /** + * Get the number of users + * + * @return int + */ + public function count(): int + { + return $this->userRepository->count(); + } +} \ No newline at end of file diff --git a/src/Observers/Pivots/Tags/GroupGroupTagObserverClearCache.php b/src/Observers/Pivots/Tags/GroupGroupTagObserverClearCache.php new file mode 100644 index 0000000..eeee5a6 --- /dev/null +++ b/src/Observers/Pivots/Tags/GroupGroupTagObserverClearCache.php @@ -0,0 +1,35 @@ +cache = $cache; + } + + public function addTagToGroup(GroupTag $groupTag, Group $group): void + { + $this->cache->forget(GroupGroupTagCache::class . '@getTagsThroughGroup:' . $group->id()); + $this->cache->forget(GroupGroupTagCache::class . '@getGroupsThroughTag:' . $groupTag->id()); + } + + public function removeTagFromGroup(GroupTag $groupTag, Group $group): void + { + $this->cache->forget(GroupGroupTagCache::class . '@getTagsThroughGroup:' . $group->id()); + $this->cache->forget(GroupGroupTagCache::class . '@getGroupsThroughTag:' . $groupTag->id()); + } + +} \ No newline at end of file diff --git a/src/Observers/Pivots/Tags/PositionPositionTagObserverClearCache.php b/src/Observers/Pivots/Tags/PositionPositionTagObserverClearCache.php new file mode 100644 index 0000000..eb30b7d --- /dev/null +++ b/src/Observers/Pivots/Tags/PositionPositionTagObserverClearCache.php @@ -0,0 +1,35 @@ +cache = $cache; + } + + public function addTagToPosition(PositionTag $positionTag, Position $position): void + { + $this->cache->forget(PositionPositionTagCache::class . '@getTagsThroughPosition:' . $position->id()); + $this->cache->forget(PositionPositionTagCache::class . '@getPositionsThroughTag:' . $positionTag->id()); + } + + public function removeTagFromPosition(PositionTag $positionTag, Position $position): void + { + $this->cache->forget(PositionPositionTagCache::class . '@getTagsThroughPosition:' . $position->id()); + $this->cache->forget(PositionPositionTagCache::class . '@getPositionsThroughTag:' . $positionTag->id()); + } + +} \ No newline at end of file diff --git a/src/Observers/Pivots/Tags/RoleRoleTagObserverClearCache.php b/src/Observers/Pivots/Tags/RoleRoleTagObserverClearCache.php new file mode 100644 index 0000000..1db3bdb --- /dev/null +++ b/src/Observers/Pivots/Tags/RoleRoleTagObserverClearCache.php @@ -0,0 +1,35 @@ +cache = $cache; + } + + public function addTagToRole(RoleTag $roleTag, Role $role): void + { + $this->cache->forget(RoleRoleTagCache::class . '@getTagsThroughRole:' . $role->id()); + $this->cache->forget(RoleRoleTagCache::class . '@getRolesThroughTag:' . $roleTag->id()); + } + + public function removeTagFromRole(RoleTag $roleTag, Role $role): void + { + $this->cache->forget(RoleRoleTagCache::class . '@getTagsThroughRole:' . $role->id()); + $this->cache->forget(RoleRoleTagCache::class . '@getRolesThroughTag:' . $roleTag->id()); + } + +} \ No newline at end of file diff --git a/src/Observers/Pivots/Tags/UserUserTagObserverClearCache.php b/src/Observers/Pivots/Tags/UserUserTagObserverClearCache.php new file mode 100644 index 0000000..0e15d9a --- /dev/null +++ b/src/Observers/Pivots/Tags/UserUserTagObserverClearCache.php @@ -0,0 +1,35 @@ +cache = $cache; + } + + public function addTagToUser(UserTag $userTag, User $user): void + { + $this->cache->forget(UserUserTagCache::class . '@getTagsThroughUser:' . $user->id()); + $this->cache->forget(UserUserTagCache::class . '@getUsersThroughTag:' . $userTag->id()); + } + + public function removeTagFromUser(UserTag $userTag, User $user): void + { + $this->cache->forget(UserUserTagCache::class . '@getTagsThroughUser:' . $user->id()); + $this->cache->forget(UserUserTagCache::class . '@getUsersThroughTag:' . $userTag->id()); + } + +} \ No newline at end of file diff --git a/src/Observers/Pivots/UserGroupObserverClearCache.php b/src/Observers/Pivots/UserGroupObserverClearCache.php new file mode 100644 index 0000000..49dfaaf --- /dev/null +++ b/src/Observers/Pivots/UserGroupObserverClearCache.php @@ -0,0 +1,35 @@ +cache = $cache; + } + + public function addUserToGroup(User $user, Group $group) + { + $this->cache->forget(UserGroupCache::class . '@getGroupsThroughUser:' . $user->id()); + $this->cache->forget(UserGroupCache::class . '@getUsersThroughGroup:' . $group->id()); + } + + public function removeUserFromGroup(User $user, Group $group): void + { + $this->cache->forget(UserGroupCache::class . '@getGroupsThroughUser:' . $user->id()); + $this->cache->forget(UserGroupCache::class . '@getUsersThroughGroup:' . $group->id()); + } + +} \ No newline at end of file diff --git a/src/Observers/Pivots/UserRoleObserverClearCache.php b/src/Observers/Pivots/UserRoleObserverClearCache.php new file mode 100644 index 0000000..5f64fb5 --- /dev/null +++ b/src/Observers/Pivots/UserRoleObserverClearCache.php @@ -0,0 +1,35 @@ +cache = $cache; + } + + public function addUserToRole(User $user, Role $role) + { + $this->cache->forget(UserRoleCache::class . '@getRolesThroughUser:' . $user->id()); + $this->cache->forget(UserRoleCache::class . '@getUsersThroughRole:' . $role->id()); + } + + public function removeUserFromRole(User $user, Role $role): void + { + $this->cache->forget(UserRoleCache::class . '@getRolesThroughUser:' . $user->id()); + $this->cache->forget(UserRoleCache::class . '@getUsersThroughRole:' . $role->id()); + } + +} \ No newline at end of file diff --git a/src/Observers/PositionObserverCascadeDelete.php b/src/Observers/PositionObserverCascadeDelete.php new file mode 100644 index 0000000..a60dad1 --- /dev/null +++ b/src/Observers/PositionObserverCascadeDelete.php @@ -0,0 +1,47 @@ +roleRepository = $roleRepository; + $this->positionPositionTag = $positionPositionTag; + } + + public function delete(Position $position) + { + $this->deleteRoles($position); + $this->removeTags($position); + } + + private function deleteRoles(Position $position) + { + foreach($this->roleRepository->allThroughPosition($position) as $role) { + $this->roleRepository->delete($role->id()); + } + } + + private function removeTags(Position $position) + { + foreach($this->positionPositionTag->getTagsThroughPosition($position) as $tag) { + $this->positionPositionTag->removeTagFromPosition($tag, $position); + } + } + +} \ No newline at end of file diff --git a/src/Observers/PositionObserverClearCache.php b/src/Observers/PositionObserverClearCache.php new file mode 100644 index 0000000..da9076e --- /dev/null +++ b/src/Observers/PositionObserverClearCache.php @@ -0,0 +1,43 @@ +cache = $cache; + } + + public function create(PositionModel $positionModel) + { + $this->cache->forget(PositionCache::class . '@count'); + $this->cache->forget(PositionCache::class . '@getByDataProviderId:' . $positionModel->dataProviderId()); + } + + public function delete(PositionModel $position) + { + $this->cache->forget(PositionCache::class . '@count'); + $this->cache->forget(PositionCache::class . '@getById:' . $position->id()); + $this->cache->forget(PositionCache::class . '@getByDataProviderId:' . $position->dataProviderId()); + } + + public function update(PositionModel $oldPosition, PositionModel $newPosition) + { + $this->cache->forget(PositionCache::class . '@count'); + $this->cache->forget(PositionCache::class . '@getById:' . $newPosition->id()); + $this->cache->forget(PositionCache::class . '@getByDataProviderId:' . $oldPosition->dataProviderId()); + $this->cache->forget(PositionCache::class . '@getByDataProviderId:' . $newPosition->dataProviderId()); + } + +} \ No newline at end of file diff --git a/src/Observers/RoleObserverCascadeDelete.php b/src/Observers/RoleObserverCascadeDelete.php new file mode 100644 index 0000000..884b4e5 --- /dev/null +++ b/src/Observers/RoleObserverCascadeDelete.php @@ -0,0 +1,47 @@ +userRole = $userRole; + $this->roleRoleTag = $roleRoleTag; + } + + public function delete(Role $role) + { + $this->removeUsers($role); + $this->removeTags($role); + } + + private function removeUsers(Role $role) + { + foreach($this->userRole->getUsersThroughRole($role) as $user) { + $this->userRole->removeUserFromRole($user, $role); + } + } + + private function removeTags(Role $role) + { + foreach($this->roleRoleTag->getTagsThroughRole($role) as $tag) { + $this->roleRoleTag->removeTagFromRole($tag, $role); + } + } + +} \ No newline at end of file diff --git a/src/Observers/RoleObserverClearCache.php b/src/Observers/RoleObserverClearCache.php new file mode 100644 index 0000000..f53ce8f --- /dev/null +++ b/src/Observers/RoleObserverClearCache.php @@ -0,0 +1,49 @@ +cache = $cache; + } + + public function create(RoleModel $roleModel) + { + $this->cache->forget(RoleCache::class . '@count'); + $this->cache->forget(RoleCache::class . '@getByDataProviderId:' . $roleModel->dataProviderId()); + } + + public function delete(RoleModel $role) + { + $this->cache->forget(RoleCache::class . '@count'); + $this->cache->forget(RoleCache::class . '@getById:' . $role->id()); + $this->cache->forget(RoleCache::class . '@getByDataProviderId:' . $role->dataProviderId()); + $this->cache->forget(RoleCache::class . '@allThroughGroup:' . $role->groupId()); + $this->cache->forget(RoleCache::class . '@allThroughPosition:' . $role->positionId()); + } + + public function update(RoleModel $oldRole, RoleModel $newRole) + { + $this->cache->forget(RoleCache::class . '@count'); + $this->cache->forget(RoleCache::class . '@getById:' . $newRole->id()); + $this->cache->forget(RoleCache::class . '@getByDataProviderId:' . $oldRole->dataProviderId()); + $this->cache->forget(RoleCache::class . '@getByDataProviderId:' . $newRole->dataProviderId()); + $this->cache->forget(RoleCache::class . '@allThroughPosition:' . $oldRole->positionId()); + $this->cache->forget(RoleCache::class . '@allThroughPosition:' . $newRole->positionId()); + $this->cache->forget(RoleCache::class . '@allThroughGroup:' . $oldRole->groupId()); + $this->cache->forget(RoleCache::class . '@allThroughGroup:' . $newRole->groupId()); + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/GroupTagCategoryObserverCascadeDelete.php b/src/Observers/Tags/GroupTagCategoryObserverCascadeDelete.php new file mode 100644 index 0000000..34dadfb --- /dev/null +++ b/src/Observers/Tags/GroupTagCategoryObserverCascadeDelete.php @@ -0,0 +1,29 @@ +groupTagRepository = $groupTagRepository; + } + + public function delete(GroupTagCategory $groupTagCategory) + { + $tags = $this->groupTagRepository->allThroughTagCategory($groupTagCategory); + foreach($tags as $tag) { + $this->groupTagRepository->delete($tag->id()); + } + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/GroupTagCategoryObserverClearCache.php b/src/Observers/Tags/GroupTagCategoryObserverClearCache.php new file mode 100644 index 0000000..7c74424 --- /dev/null +++ b/src/Observers/Tags/GroupTagCategoryObserverClearCache.php @@ -0,0 +1,35 @@ +cache = $cache; + } + + public function delete(GroupTagCategory $groupTagCategory) + { + $this->cache->forget(GroupTagCategoryCache::class . '@getByReference:' . $groupTagCategory->reference()); + $this->cache->forget(GroupTagCategoryCache::class . '@getById: ' . $groupTagCategory->id()); + } + + public function update(GroupTagCategory $oldGroupTagCategory, GroupTagCategory $newGroupTagCategory) + { + $this->cache->forget(GroupTagCategoryCache::class . '@getById:' . $newGroupTagCategory->id()); + $this->cache->forget(GroupTagCategoryCache::class . '@getByReference:' . $newGroupTagCategory->reference()); + $this->cache->forget(GroupTagCategoryCache::class . '@getByReference:' . $oldGroupTagCategory->reference()); + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/GroupTagObserverCascadeDelete.php b/src/Observers/Tags/GroupTagObserverCascadeDelete.php new file mode 100644 index 0000000..8145aa8 --- /dev/null +++ b/src/Observers/Tags/GroupTagObserverCascadeDelete.php @@ -0,0 +1,29 @@ +groupGroupTag = $groupGroupTag; + } + + public function delete(GroupTag $groupTag) + { + $groups = $this->groupGroupTag->getGroupsThroughTag($groupTag); + foreach($groups as $group) { + $this->groupGroupTag->removeTagFromGroup($groupTag, $group); + } + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/GroupTagObserverClearCache.php b/src/Observers/Tags/GroupTagObserverClearCache.php new file mode 100644 index 0000000..d7c1312 --- /dev/null +++ b/src/Observers/Tags/GroupTagObserverClearCache.php @@ -0,0 +1,43 @@ +cache = $cache; + } + + public function delete(GroupTag $groupTag) + { + $this->cache->forget(GroupTagCache::class . '@allThroughTagCategory:' . $groupTag->categoryId()); + $this->cache->forget(GroupTagCache::class . '@getById:' . $groupTag->id()); + $this->cache->forget(GroupTagCache::class . '@getTagByFullReference:' . $groupTag->fullReference()); + } + + public function create(GroupTag $groupTag) + { + return $this->cache->forget(GroupTagCache::class . '@allThroughTagCategory:' . $groupTag->categoryId()); + } + + public function update(GroupTag $oldGroupTag, GroupTag $newGroupTag) + { + $this->cache->forget(GroupTagCache::class . '@getById:' . $newGroupTag->id()); + $this->cache->forget(GroupTagCache::class . '@getTagByFullReference:' . $oldGroupTag->fullReference()); + $this->cache->forget(GroupTagCache::class . '@getTagByFullReference:' . $newGroupTag->fullReference()); + $this->cache->forget(GroupTagCache::class . '@allThroughTagCategory:' . $oldGroupTag->categoryId()); + $this->cache->forget(GroupTagCache::class . '@allThroughTagCategory:' . $newGroupTag->categoryId()); + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/PositionTagCategoryObserverCascadeDelete.php b/src/Observers/Tags/PositionTagCategoryObserverCascadeDelete.php new file mode 100644 index 0000000..325f5d7 --- /dev/null +++ b/src/Observers/Tags/PositionTagCategoryObserverCascadeDelete.php @@ -0,0 +1,29 @@ +positionTagRepository = $positionTagRepository; + } + + public function delete(PositionTagCategory $positionTagCategory) + { + $tags = $this->positionTagRepository->allThroughTagCategory($positionTagCategory); + foreach($tags as $tag) { + $this->positionTagRepository->delete($tag->id()); + } + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/PositionTagCategoryObserverClearCache.php b/src/Observers/Tags/PositionTagCategoryObserverClearCache.php new file mode 100644 index 0000000..a4c5c54 --- /dev/null +++ b/src/Observers/Tags/PositionTagCategoryObserverClearCache.php @@ -0,0 +1,35 @@ +cache = $cache; + } + + public function delete(PositionTagCategory $positionTagCategory) + { + $this->cache->forget(PositionTagCategoryCache::class . '@getByReference:' . $positionTagCategory->reference()); + $this->cache->forget(PositionTagCategoryCache::class . '@getById: ' . $positionTagCategory->id()); + } + + public function update(PositionTagCategory $oldPositionTagCategory, PositionTagCategory $newPositionTagCategory) + { + $this->cache->forget(PositionTagCategoryCache::class . '@getById:' . $newPositionTagCategory->id()); + $this->cache->forget(PositionTagCategoryCache::class . '@getByReference:' . $newPositionTagCategory->reference()); + $this->cache->forget(PositionTagCategoryCache::class . '@getByReference:' . $oldPositionTagCategory->reference()); + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/PositionTagObserverCascadeDelete.php b/src/Observers/Tags/PositionTagObserverCascadeDelete.php new file mode 100644 index 0000000..9617ec6 --- /dev/null +++ b/src/Observers/Tags/PositionTagObserverCascadeDelete.php @@ -0,0 +1,29 @@ +positionPositionTag = $positionPositionTag; + } + + public function delete(PositionTag $positionTag) + { + $positions = $this->positionPositionTag->getPositionsThroughTag($positionTag); + foreach($positions as $position) { + $this->positionPositionTag->removeTagFromPosition($positionTag, $position); + } + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/PositionTagObserverClearCache.php b/src/Observers/Tags/PositionTagObserverClearCache.php new file mode 100644 index 0000000..248a71a --- /dev/null +++ b/src/Observers/Tags/PositionTagObserverClearCache.php @@ -0,0 +1,43 @@ +cache = $cache; + } + + public function delete(PositionTag $positionTag) + { + $this->cache->forget(PositionTagCache::class . '@allThroughTagCategory:' . $positionTag->categoryId()); + $this->cache->forget(PositionTagCache::class . '@getById:' . $positionTag->id()); + $this->cache->forget(PositionTagCache::class . '@getTagByFullReference:' . $positionTag->fullReference()); + } + + public function create(PositionTag $positionTag) + { + return $this->cache->forget(PositionTagCache::class . '@allThroughTagCategory:' . $positionTag->categoryId()); + } + + public function update(PositionTag $oldPositionTag, PositionTag $newPositionTag) + { + $this->cache->forget(PositionTagCache::class . '@getById:' . $newPositionTag->id()); + $this->cache->forget(PositionTagCache::class . '@getTagByFullReference:' . $oldPositionTag->fullReference()); + $this->cache->forget(PositionTagCache::class . '@getTagByFullReference:' . $newPositionTag->fullReference()); + $this->cache->forget(PositionTagCache::class . '@allThroughTagCategory:' . $oldPositionTag->categoryId()); + $this->cache->forget(PositionTagCache::class . '@allThroughTagCategory:' . $newPositionTag->categoryId()); + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/RoleTagCategoryObserverCascadeDelete.php b/src/Observers/Tags/RoleTagCategoryObserverCascadeDelete.php new file mode 100644 index 0000000..b6b6170 --- /dev/null +++ b/src/Observers/Tags/RoleTagCategoryObserverCascadeDelete.php @@ -0,0 +1,29 @@ +roleTagRepository = $roleTagRepository; + } + + public function delete(RoleTagCategory $roleTagCategory) + { + $tags = $this->roleTagRepository->allThroughTagCategory($roleTagCategory); + foreach($tags as $tag) { + $this->roleTagRepository->delete($tag->id()); + } + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/RoleTagCategoryObserverClearCache.php b/src/Observers/Tags/RoleTagCategoryObserverClearCache.php new file mode 100644 index 0000000..7b595a9 --- /dev/null +++ b/src/Observers/Tags/RoleTagCategoryObserverClearCache.php @@ -0,0 +1,35 @@ +cache = $cache; + } + + public function delete(RoleTagCategory $roleTagCategory) + { + $this->cache->forget(RoleTagCategoryCache::class . '@getByReference:' . $roleTagCategory->reference()); + $this->cache->forget(RoleTagCategoryCache::class . '@getById: ' . $roleTagCategory->id()); + } + + public function update(RoleTagCategory $oldRoleTagCategory, RoleTagCategory $newRoleTagCategory) + { + $this->cache->forget(RoleTagCategoryCache::class . '@getById:' . $newRoleTagCategory->id()); + $this->cache->forget(RoleTagCategoryCache::class . '@getByReference:' . $newRoleTagCategory->reference()); + $this->cache->forget(RoleTagCategoryCache::class . '@getByReference:' . $oldRoleTagCategory->reference()); + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/RoleTagObserverCascadeDelete.php b/src/Observers/Tags/RoleTagObserverCascadeDelete.php new file mode 100644 index 0000000..a749907 --- /dev/null +++ b/src/Observers/Tags/RoleTagObserverCascadeDelete.php @@ -0,0 +1,29 @@ +roleRoleTag = $roleRoleTag; + } + + public function delete(RoleTag $roleTag) + { + $roles = $this->roleRoleTag->getRolesThroughTag($roleTag); + foreach($roles as $role) { + $this->roleRoleTag->removeTagFromRole($roleTag, $role); + } + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/RoleTagObserverClearCache.php b/src/Observers/Tags/RoleTagObserverClearCache.php new file mode 100644 index 0000000..47e9a8e --- /dev/null +++ b/src/Observers/Tags/RoleTagObserverClearCache.php @@ -0,0 +1,43 @@ +cache = $cache; + } + + public function delete(RoleTag $roleTag) + { + $this->cache->forget(RoleTagCache::class . '@allThroughTagCategory:' . $roleTag->categoryId()); + $this->cache->forget(RoleTagCache::class . '@getById:' . $roleTag->id()); + $this->cache->forget(RoleTagCache::class . '@getTagByFullReference:' . $roleTag->fullReference()); + } + + public function create(RoleTag $roleTag) + { + return $this->cache->forget(RoleTagCache::class . '@allThroughTagCategory:' . $roleTag->categoryId()); + } + + public function update(RoleTag $oldRoleTag, RoleTag $newRoleTag) + { + $this->cache->forget(RoleTagCache::class . '@getById:' . $newRoleTag->id()); + $this->cache->forget(RoleTagCache::class . '@getTagByFullReference:' . $oldRoleTag->fullReference()); + $this->cache->forget(RoleTagCache::class . '@getTagByFullReference:' . $newRoleTag->fullReference()); + $this->cache->forget(RoleTagCache::class . '@allThroughTagCategory:' . $oldRoleTag->categoryId()); + $this->cache->forget(RoleTagCache::class . '@allThroughTagCategory:' . $newRoleTag->categoryId()); + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/UserTagCategoryObserverCascadeDelete.php b/src/Observers/Tags/UserTagCategoryObserverCascadeDelete.php new file mode 100644 index 0000000..a138709 --- /dev/null +++ b/src/Observers/Tags/UserTagCategoryObserverCascadeDelete.php @@ -0,0 +1,29 @@ +userTagRepository = $userTagRepository; + } + + public function delete(UserTagCategory $userTagCategory) + { + $tags = $this->userTagRepository->allThroughTagCategory($userTagCategory); + foreach($tags as $tag) { + $this->userTagRepository->delete($tag->id()); + } + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/UserTagCategoryObserverClearCache.php b/src/Observers/Tags/UserTagCategoryObserverClearCache.php new file mode 100644 index 0000000..3c92504 --- /dev/null +++ b/src/Observers/Tags/UserTagCategoryObserverClearCache.php @@ -0,0 +1,35 @@ +cache = $cache; + } + + public function delete(UserTagCategory $userTagCategory) + { + $this->cache->forget(UserTagCategoryCache::class . '@getByReference:' . $userTagCategory->reference()); + $this->cache->forget(UserTagCategoryCache::class . '@getById: ' . $userTagCategory->id()); + } + + public function update(UserTagCategory $oldUserTagCategory, UserTagCategory $newUserTagCategory) + { + $this->cache->forget(UserTagCategoryCache::class . '@getById:' . $newUserTagCategory->id()); + $this->cache->forget(UserTagCategoryCache::class . '@getByReference:' . $newUserTagCategory->reference()); + $this->cache->forget(UserTagCategoryCache::class . '@getByReference:' . $oldUserTagCategory->reference()); + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/UserTagObserverCascadeDelete.php b/src/Observers/Tags/UserTagObserverCascadeDelete.php new file mode 100644 index 0000000..ea153d8 --- /dev/null +++ b/src/Observers/Tags/UserTagObserverCascadeDelete.php @@ -0,0 +1,29 @@ +userUserTag = $userUserTag; + } + + public function delete(UserTag $userTag) + { + $users = $this->userUserTag->getUsersThroughTag($userTag); + foreach($users as $user) { + $this->userUserTag->removeTagFromUser($userTag, $user); + } + } + +} \ No newline at end of file diff --git a/src/Observers/Tags/UserTagObserverClearCache.php b/src/Observers/Tags/UserTagObserverClearCache.php new file mode 100644 index 0000000..b556c79 --- /dev/null +++ b/src/Observers/Tags/UserTagObserverClearCache.php @@ -0,0 +1,43 @@ +cache = $cache; + } + + public function delete(UserTag $userTag) + { + $this->cache->forget(UserTagCache::class . '@allThroughTagCategory:' . $userTag->categoryId()); + $this->cache->forget(UserTagCache::class . '@getById:' . $userTag->id()); + $this->cache->forget(UserTagCache::class . '@getTagByFullReference:' . $userTag->fullReference()); + } + + public function create(UserTag $userTag) + { + return $this->cache->forget(UserTagCache::class . '@allThroughTagCategory:' . $userTag->categoryId()); + } + + public function update(UserTag $oldUserTag, UserTag $newUserTag) + { + $this->cache->forget(UserTagCache::class . '@getById:' . $newUserTag->id()); + $this->cache->forget(UserTagCache::class . '@getTagByFullReference:' . $oldUserTag->fullReference()); + $this->cache->forget(UserTagCache::class . '@getTagByFullReference:' . $newUserTag->fullReference()); + $this->cache->forget(UserTagCache::class . '@allThroughTagCategory:' . $oldUserTag->categoryId()); + $this->cache->forget(UserTagCache::class . '@allThroughTagCategory:' . $newUserTag->categoryId()); + } + +} \ No newline at end of file diff --git a/src/Observers/UserObserverCascadeDelete.php b/src/Observers/UserObserverCascadeDelete.php new file mode 100644 index 0000000..5b4b3ca --- /dev/null +++ b/src/Observers/UserObserverCascadeDelete.php @@ -0,0 +1,61 @@ +userGroup = $userGroup; + $this->userUserTag = $userUserTag; + $this->userRole = $userRole; + } + + public function delete(User $user) + { + $this->removeGroups($user); + $this->removeTags($user); + $this->removeRoles($user); + } + + private function removeGroups(User $user) + { + foreach($this->userGroup->getGroupsThroughUser($user) as $group) { + $this->userGroup->removeUserFromGroup($user, $group); + } + } + + private function removeTags(User $user) + { + foreach($this->userUserTag->getTagsThroughUser($user) as $tag) { + $this->userUserTag->removeTagFromUser($tag, $user); + } + } + + private function removeRoles(User $user) + { + foreach($this->userRole->getRolesThroughUser($user) as $role) { + $this->userRole->removeUserFromRole($user, $role); + } + } + +} \ No newline at end of file diff --git a/src/Observers/UserObserverClearCache.php b/src/Observers/UserObserverClearCache.php new file mode 100644 index 0000000..bb8589a --- /dev/null +++ b/src/Observers/UserObserverClearCache.php @@ -0,0 +1,43 @@ +cache = $cache; + } + + public function create(UserModel $userModel) + { + $this->cache->forget(UserCache::class . '@count'); + $this->cache->forget(UserCache::class . '@getByDataProviderId:' . $userModel->dataProviderId()); + } + + public function delete(UserModel $user) + { + $this->cache->forget(UserCache::class . '@count'); + $this->cache->forget(UserCache::class . '@getById:' . $user->id()); + $this->cache->forget(UserCache::class . '@getByDataProviderId:' . $user->dataProviderId()); + } + + public function update(UserModel $oldUser, UserModel $newUser) + { + $this->cache->forget(UserCache::class . '@count'); + $this->cache->forget(UserCache::class . '@getById:' . $newUser->id()); + $this->cache->forget(UserCache::class . '@getByDataProviderId:' . $oldUser->dataProviderId()); + $this->cache->forget(UserCache::class . '@getByDataProviderId:' . $newUser->dataProviderId()); + } + +} \ No newline at end of file diff --git a/src/Repositories/DataGroup.php b/src/Repositories/DataGroup.php index 4a1c232..82c90c7 100644 --- a/src/Repositories/DataGroup.php +++ b/src/Repositories/DataGroup.php @@ -80,4 +80,21 @@ public function getAllWhere($attributes = []): Collection return true; })->values(); } + + /** + * Update a group with the given attributes + * + * @param int $id + * @param string|null $name Name of the group + * @param string|null $email Email of the group + * @return \BristolSU\ControlDB\Contracts\Models\DataGroup + */ + public function update(int $id, ?string $name = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataGroup + { + $dataGroup = $this->getById($id)->fill([ + 'name' => $name, 'email' => $email + ]); + $dataGroup->save(); + return $dataGroup; + } } \ No newline at end of file diff --git a/src/Repositories/DataPosition.php b/src/Repositories/DataPosition.php index 61cb376..14738a8 100644 --- a/src/Repositories/DataPosition.php +++ b/src/Repositories/DataPosition.php @@ -82,4 +82,21 @@ public function getAllWhere($attributes = []): Collection return true; })->values(); } + + /** + * Update a data position with the given attributes + * + * @param int $id + * @param string|null $name Name of the position + * @param string|null $description Description of the position + * @return \BristolSU\ControlDB\Contracts\Models\DataPosition + */ + public function update(int $id, ?string $name = null, ?string $description = null): \BristolSU\ControlDB\Contracts\Models\DataPosition + { + $dataPosition = $this->getById($id)->fill([ + 'name' => $name, 'description' => $description + ]); + $dataPosition->save(); + return $dataPosition; + } } \ No newline at end of file diff --git a/src/Repositories/DataRole.php b/src/Repositories/DataRole.php index e637081..497fb8a 100644 --- a/src/Repositories/DataRole.php +++ b/src/Repositories/DataRole.php @@ -82,4 +82,21 @@ public function getAllWhere($attributes = []): Collection return true; })->values(); } + + /** + * Update a data position with the given attributes + * + * @param int $id + * @param string|null $roleName Custom name for the role + * @param string|null $email Email of the role + * @return \BristolSU\ControlDB\Contracts\Models\DataRole + */ + public function update(int $id, ?string $roleName = null, ?string $email = null): \BristolSU\ControlDB\Contracts\Models\DataRole + { + $dataRole = $this->getById($id)->fill([ + 'role_name' => $roleName, 'email' => $email + ]); + $dataRole->save(); + return $dataRole; + } } \ No newline at end of file diff --git a/src/Repositories/DataUser.php b/src/Repositories/DataUser.php index 05a3adc..d8055a0 100644 --- a/src/Repositories/DataUser.php +++ b/src/Repositories/DataUser.php @@ -87,4 +87,28 @@ public function getAllWhere($attributes = []): Collection return true; })->values(); } + + /** + * Update a data user + * + * @param int $id + * @param string|null $firstName + * @param string|null $lastName + * @param string|null $email + * @param \DateTime|null $dob + * @param string|null $preferredName + * @return \BristolSU\ControlDB\Contracts\Models\DataUser + */ + public function update(int $id, ?string $firstName = null, ?string $lastName = null, ?string $email = null, ?\DateTime $dob = null, ?string $preferredName = null): \BristolSU\ControlDB\Contracts\Models\DataUser + { + $dataUser = $this->getById($id)->fill([ + 'first_name' => $firstName, + 'last_name' => $lastName, + 'email' => $email, + 'dob' => $dob, + 'preferred_name' => $preferredName + ]); + $dataUser->save(); + return $dataUser; + } } \ No newline at end of file diff --git a/src/Repositories/Group.php b/src/Repositories/Group.php index a2ee1e4..6e192a3 100644 --- a/src/Repositories/Group.php +++ b/src/Repositories/Group.php @@ -89,4 +89,17 @@ public function count(): int return \BristolSU\ControlDB\Models\Group::count(); } + /** + * Update the group model + * + * @param int $id + * @param int $dataProviderId New data provider ID + * @return GroupModel + */ + public function update(int $id, int $dataProviderId): GroupModel + { + $group = $this->getById($id)->fill(['data_provider_id' => $dataProviderId]); + $group->save(); + return $group; + } } diff --git a/src/Repositories/Position.php b/src/Repositories/Position.php index 8603c93..7caa2c5 100644 --- a/src/Repositories/Position.php +++ b/src/Repositories/Position.php @@ -88,5 +88,18 @@ public function count(): int { return \BristolSU\ControlDB\Models\Position::count(); } - + + /** + * Update the position model + * + * @param int $id + * @param int $dataProviderId New data provider ID + * @return PositionModel + */ + public function update(int $id, int $dataProviderId): PositionModel + { + $position = $this->getById($id)->fill(['data_provider_id' => $dataProviderId]); + $position->save(); + return $position; + } } diff --git a/src/Repositories/Role.php b/src/Repositories/Role.php index f03dbbd..27eca1f 100644 --- a/src/Repositories/Role.php +++ b/src/Repositories/Role.php @@ -117,4 +117,20 @@ public function count(): int { return \BristolSU\ControlDB\Models\Role::count(); } + + /** + * Update the role model + * + * @param int $id + * @param int $positionId + * @param int $groupId + * @param int $dataProviderId New data provider ID + * @return RoleModel + */ + public function update(int $id, int $positionId, int $groupId, int $dataProviderId): RoleModel + { + $role = $this->getById($id)->fill(['position_id' => $positionId, 'group_id' => $groupId, 'data_provider_id' => $dataProviderId]); + $role->save(); + return $role; + } } diff --git a/src/Repositories/Tags/GroupTag.php b/src/Repositories/Tags/GroupTag.php index 61866b5..e4dbe70 100644 --- a/src/Repositories/Tags/GroupTag.php +++ b/src/Repositories/Tags/GroupTag.php @@ -94,4 +94,23 @@ public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags { return \BristolSU\ControlDB\Models\Tags\GroupTag::where('tag_category_id', $groupTagCategory->id())->get(); } + + /** + * Update a group tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\GroupTag + { + $groupTag = $this->getById($id)->fill([ + 'name' => $name, 'description' => $description, 'reference' => $reference, 'tag_category_id' => $tagCategoryId + ]); + $groupTag->save(); + return $groupTag; + } } diff --git a/src/Repositories/Tags/GroupTagCategory.php b/src/Repositories/Tags/GroupTagCategory.php index 5e11c14..99313e0 100644 --- a/src/Repositories/Tags/GroupTagCategory.php +++ b/src/Repositories/Tags/GroupTagCategory.php @@ -71,5 +71,22 @@ public function delete(int $id): void { $this->getById($id)->delete(); } - + + /** + * Update a group tag category + * + * @param int $id + * @param string $name Name of the group tag category + * @param string $description Description of the group tag category + * @param string $reference Reference of the group tag category + * @return GroupTagCategoryModel New group tag category + */ + public function update(int $id, string $name, string $description, string $reference): GroupTagCategoryModel + { + $groupTagCategory = $this->getById($id)->fill([ + 'name' => $name, 'description' => $description, 'reference' => $reference + ]); + $groupTagCategory->save(); + return $groupTagCategory; + } } diff --git a/src/Repositories/Tags/PositionTag.php b/src/Repositories/Tags/PositionTag.php index 6cfda92..a155ce3 100644 --- a/src/Repositories/Tags/PositionTag.php +++ b/src/Repositories/Tags/PositionTag.php @@ -94,4 +94,23 @@ public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags { return \BristolSU\ControlDB\Models\Tags\PositionTag::where('tag_category_id', $positionTagCategory->id())->get(); } + + /** + * Update a position tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\PositionTag + { + $positionTag = $this->getById($id)->fill([ + 'name' => $name, 'description' => $description, 'reference' => $reference, 'tag_category_id' => $tagCategoryId + ]); + $positionTag->save(); + return $positionTag; + } } diff --git a/src/Repositories/Tags/PositionTagCategory.php b/src/Repositories/Tags/PositionTagCategory.php index df92682..13891a8 100644 --- a/src/Repositories/Tags/PositionTagCategory.php +++ b/src/Repositories/Tags/PositionTagCategory.php @@ -72,4 +72,21 @@ public function delete(int $id): void $this->getById($id)->delete(); } + /** + * Update a position tag category + * + * @param int $id + * @param string $name Name of the position tag category + * @param string $description Description of the position tag category + * @param string $reference Reference of the position tag category + * @return PositionTagCategoryModel Updated position tag category + */ + public function update(int $id, string $name, string $description, string $reference): PositionTagCategoryModel + { + $positionTagCategory = $this->getById($id)->fill([ + 'name' => $name, 'description' => $description, 'reference' => $reference + ]); + $positionTagCategory->save(); + return $positionTagCategory; + } } diff --git a/src/Repositories/Tags/RoleTag.php b/src/Repositories/Tags/RoleTag.php index c1340a5..08e97da 100644 --- a/src/Repositories/Tags/RoleTag.php +++ b/src/Repositories/Tags/RoleTag.php @@ -94,4 +94,23 @@ public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags { return \BristolSU\ControlDB\Models\Tags\RoleTag::where('tag_category_id', $roleTagCategory->id())->get(); } + + /** + * Update a role tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag + { + $roleTag = $this->getById($id)->fill([ + 'name' => $name, 'description' => $description, 'reference' => $reference, 'tag_category_id' => $tagCategoryId + ]); + $roleTag->save(); + return $roleTag; + } } diff --git a/src/Repositories/Tags/RoleTagCategory.php b/src/Repositories/Tags/RoleTagCategory.php index 7f8efe3..d385942 100644 --- a/src/Repositories/Tags/RoleTagCategory.php +++ b/src/Repositories/Tags/RoleTagCategory.php @@ -72,4 +72,21 @@ public function delete(int $id): void $this->getById($id)->delete(); } + /** + * Update a role tag category + * + * @param int $id + * @param string $name Name of the role tag category + * @param string $description Description of the role tag category + * @param string $reference Reference of the role tag category + * @return RoleTagCategoryModel Updated role tag category + */ + public function update(int $id, string $name, string $description, string $reference): RoleTagCategoryModel + { + $roleTagCategory = $this->getById($id)->fill([ + 'name' => $name, 'description' => $description, 'reference' => $reference + ]); + $roleTagCategory->save(); + return $roleTagCategory; + } } diff --git a/src/Repositories/Tags/UserTag.php b/src/Repositories/Tags/UserTag.php index 7cc6c34..a3c66ef 100644 --- a/src/Repositories/Tags/UserTag.php +++ b/src/Repositories/Tags/UserTag.php @@ -94,4 +94,23 @@ public function allThroughTagCategory(\BristolSU\ControlDB\Contracts\Models\Tags { return \BristolSU\ControlDB\Models\Tags\UserTag::where('tag_category_id', $userTagCategory->id())->get(); } + + /** + * Update a user tag + * + * @param int $id + * @param string $name Name of the tag + * @param string $description Description of the tag + * @param string $reference Reference for the tag + * @param int $tagCategoryId Category ID of the tag + * @return \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + */ + public function update(int $id, string $name, string $description, string $reference, int $tagCategoryId): \BristolSU\ControlDB\Contracts\Models\Tags\UserTag + { + $userTag = $this->getById($id)->fill([ + 'name' => $name, 'description' => $description, 'reference' => $reference, 'tag_category_id' => $tagCategoryId + ]); + $userTag->save(); + return $userTag; + } } diff --git a/src/Repositories/Tags/UserTagCategory.php b/src/Repositories/Tags/UserTagCategory.php index 754af34..1700dbe 100644 --- a/src/Repositories/Tags/UserTagCategory.php +++ b/src/Repositories/Tags/UserTagCategory.php @@ -72,4 +72,21 @@ public function delete(int $id): void $this->getById($id)->delete(); } + /** + * Update a user tag category + * + * @param int $id + * @param string $name Name of the user tag category + * @param string $description Description of the user tag category + * @param string $reference Reference of the user tag category + * @return UserTagCategoryModel Updated user tag category + */ + public function update(int $id, string $name, string $description, string $reference): UserTagCategoryModel + { + $userTagCategory = $this->getById($id)->fill([ + 'name' => $name, 'description' => $description, 'reference' => $reference + ]); + $userTagCategory->save(); + return $userTagCategory; + } } diff --git a/src/Repositories/User.php b/src/Repositories/User.php index d5c2926..4800b04 100644 --- a/src/Repositories/User.php +++ b/src/Repositories/User.php @@ -90,4 +90,17 @@ public function count(): int } + /** + * Update the user model + * + * @param int $id + * @param int $dataProviderId New data provider ID + * @return UserModel + */ + public function update(int $id, int $dataProviderId): UserModel + { + $user = $this->getById($id)->fill(['data_provider_id' => $dataProviderId]); + $user->save(); + return $user; + } } diff --git a/src/Traits/DataGroupTrait.php b/src/Traits/DataGroupTrait.php index bb52e46..25ff906 100644 --- a/src/Traits/DataGroupTrait.php +++ b/src/Traits/DataGroupTrait.php @@ -5,6 +5,7 @@ use BristolSU\ControlDB\Contracts\Models\Group; +use BristolSU\ControlDB\Contracts\Repositories\DataGroup; use Illuminate\Database\Eloquent\ModelNotFoundException; /** @@ -26,4 +27,24 @@ public function group(): ?Group return null; } } + + /** + * Set the name of the group + * + * @param string|null $name + */ + public function setName(?string $name): void + { + app(DataGroup::class)->update($this->id(), $name, $this->email()); + } + + /** + * Set the email of the group + * + * @param string|null $email + */ + public function setEmail(?string $email): void + { + app(DataGroup::class)->update($this->id(), $this->name(), $email); + } } \ No newline at end of file diff --git a/src/Traits/DataPositionTrait.php b/src/Traits/DataPositionTrait.php index 8dc4913..8570071 100644 --- a/src/Traits/DataPositionTrait.php +++ b/src/Traits/DataPositionTrait.php @@ -5,6 +5,7 @@ use BristolSU\ControlDB\Contracts\Models\Position; +use BristolSU\ControlDB\Contracts\Repositories\DataPosition; use Illuminate\Database\Eloquent\ModelNotFoundException; /** @@ -26,4 +27,25 @@ public function position(): ?Position return null; } } + + /** + * Set the position name + * + * @param string|null $name + */ + public function setName(?string $name): void + { + app(DataPosition::class)->update($this->id(), $name, $this->description()); + } + + /** + * Set the description + * + * @param string|null $description + */ + public function setDescription(?string $description): void + { + app(DataPosition::class)->update($this->id(), $this->name(), $description); + + } } \ No newline at end of file diff --git a/src/Traits/DataRoleTrait.php b/src/Traits/DataRoleTrait.php index 829cd89..8bfdbb0 100644 --- a/src/Traits/DataRoleTrait.php +++ b/src/Traits/DataRoleTrait.php @@ -5,6 +5,7 @@ use BristolSU\ControlDB\Contracts\Models\Role; +use BristolSU\ControlDB\Contracts\Repositories\DataRole; use Illuminate\Database\Eloquent\ModelNotFoundException; /** @@ -26,4 +27,26 @@ public function role(): ?Role return null; } } + + /** + * Set the email of the role + * + * @param string|null $email + */ + public function setEmail(?string $email): void + { + app(DataRole::class)->update($this->id(), $this->roleName(), $email); + } + + + /** + * Set a name for the role + * + * @param string|null $roleName + */ + public function setRoleName(?string $roleName): void + { + app(DataRole::class)->update($this->id(), $roleName, $this->email()); + + } } \ No newline at end of file diff --git a/src/Traits/DataUserTrait.php b/src/Traits/DataUserTrait.php index bd763cc..7464057 100644 --- a/src/Traits/DataUserTrait.php +++ b/src/Traits/DataUserTrait.php @@ -5,6 +5,7 @@ use BristolSU\ControlDB\Contracts\Models\User; +use DateTime; use Illuminate\Database\Eloquent\ModelNotFoundException; /** @@ -26,4 +27,64 @@ public function user(): ?User return null; } } + + /** + * Set the users first name + * + * @param string|null $firstName + */ + public function setFirstName(?string $firstName): void + { + app(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class)->update( + $this->id(), $firstName, $this->lastName(), $this->email(), $this->dob(), $this->preferredName() + ); + } + + /** + * Set the users last name + * + * @param string|null $lastName + */ + public function setLastName(?string $lastName): void + { + app(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class)->update( + $this->id(), $this->firstName(), $lastName, $this->email(), $this->dob(), $this->preferredName() + ); + } + + /** + * Set the users email + * + * @param string|null $email + */ + public function setEmail(?string $email): void + { + app(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class)->update( + $this->id(), $this->firstName(), $this->lastName(), $email, $this->dob(), $this->preferredName() + ); + } + + /** + * Set the date of birth attribute + * + * @param DateTime|null $dob + */ + public function setDob(?DateTime $dob): void + { + app(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class)->update( + $this->id(), $this->firstName(), $this->lastName(), $this->email(), $dob, $this->preferredName() + ); + } + + /** + * Set the preferred name for the user + * + * @param string|null $name + */ + public function setPreferredName(?string $name): void + { + app(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class)->update( + $this->id(), $this->firstName(), $this->lastName(), $this->email(), $this->dob(), $name + ); + } } \ No newline at end of file diff --git a/src/Traits/GroupTrait.php b/src/Traits/GroupTrait.php index 0171360..2fbd24b 100644 --- a/src/Traits/GroupTrait.php +++ b/src/Traits/GroupTrait.php @@ -3,6 +3,7 @@ namespace BristolSU\ControlDB\Traits; use BristolSU\ControlDB\Contracts\Models\DataGroup; +use BristolSU\ControlDB\Contracts\Repositories\Group; use BristolSU\ControlDB\Contracts\Repositories\Pivots\Tags\GroupGroupTag; use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserGroup; use BristolSU\ControlDB\Contracts\Repositories\Role; @@ -24,6 +25,16 @@ public function data(): DataGroup return app(\BristolSU\ControlDB\Contracts\Repositories\DataGroup::class)->getById($this->dataProviderId()); } + /** + * Set the ID of the data provider + * + * @param int $dataProviderId + */ + public function setDataProviderId(int $dataProviderId): void + { + app(Group::class)->update($this->id(), $dataProviderId); + } + /** * Members of the group * diff --git a/src/Traits/PositionTrait.php b/src/Traits/PositionTrait.php index ce08ac9..c625699 100644 --- a/src/Traits/PositionTrait.php +++ b/src/Traits/PositionTrait.php @@ -7,6 +7,7 @@ use BristolSU\ControlDB\Contracts\Models\DataPosition as DataPositionModel; use BristolSU\ControlDB\Contracts\Repositories\DataPosition as DataPositionRepository; use BristolSU\ControlDB\Contracts\Repositories\Pivots\Tags\PositionPositionTag; +use BristolSU\ControlDB\Contracts\Repositories\Position; use Illuminate\Support\Collection; /** @@ -25,6 +26,16 @@ public function data(): DataPositionModel return app(DataPositionRepository::class)->getById($this->dataProviderId()); } + /** + * Set the ID of the data provider + * + * @param int $dataProviderId + */ + public function setDataProviderId(int $dataProviderId): void + { + app(Position::class)->update($this->id(), $dataProviderId); + } + /** * Roles with this position * diff --git a/src/Traits/RoleTrait.php b/src/Traits/RoleTrait.php index 5d25b67..6255b56 100644 --- a/src/Traits/RoleTrait.php +++ b/src/Traits/RoleTrait.php @@ -9,6 +9,7 @@ use BristolSU\ControlDB\Contracts\Repositories\DataRole as DataRoleRepository; use BristolSU\ControlDB\Contracts\Repositories\Pivots\Tags\RoleRoleTag; use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserRole; +use BristolSU\ControlDB\Contracts\Repositories\Role; use BristolSU\ControlDB\Models\Group; use BristolSU\ControlDB\Models\Position; use Illuminate\Support\Collection; @@ -29,6 +30,36 @@ public function data(): DataRoleModel return app(DataRoleRepository::class)->getById($this->dataProviderId()); } + /** + * Set the ID of the data provider + * + * @param int $dataProviderId + */ + public function setDataProviderId(int $dataProviderId): void + { + app(Role::class)->update($this->id(), $this->positionId(), $this->groupId(), $dataProviderId); + } + + /** + * Set a group ID + * + * @param int $groupId + */ + public function setGroupId(int $groupId): void + { + app(Role::class)->update($this->id(), $this->positionId(), $groupId, $this->dataProviderId()); + } + + /** + * Set a position ID + * + * @param int $positionId + */ + public function setPositionId(int $positionId): void + { + app(Role::class)->update($this->id(), $positionId, $this->groupId(), $this->dataProviderId()); + } + /** * Position belonging to the role * diff --git a/src/Traits/Tags/GroupTagCategoryTrait.php b/src/Traits/Tags/GroupTagCategoryTrait.php index 3d6aae6..69f28b4 100644 --- a/src/Traits/Tags/GroupTagCategoryTrait.php +++ b/src/Traits/Tags/GroupTagCategoryTrait.php @@ -3,6 +3,7 @@ namespace BristolSU\ControlDB\Traits\Tags; use BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTag; +use BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTagCategory; use Illuminate\Support\Collection; /** @@ -20,5 +21,35 @@ public function tags(): Collection { return app(GroupTag::class)->allThroughTagCategory($this); } + + /** + * Set the name of the tag category + * + * @param string $name + */ + public function setName(string $name): void + { + app(GroupTagCategory::class)->update($this->id(), $name, $this->description(), $this->reference()); + } + + /** + * Set the description of the tag category + * + * @param string $description + */ + public function setDescription(string $description): void + { + app(GroupTagCategory::class)->update($this->id(), $this->name(), $description, $this->reference()); + } + + /** + * Set the reference of the tag category + * + * @param string $reference + */ + public function setReference(string $reference): void + { + app(GroupTagCategory::class)->update($this->id(), $this->name(), $this->description(), $reference); + } } \ No newline at end of file diff --git a/src/Traits/Tags/GroupTagTrait.php b/src/Traits/Tags/GroupTagTrait.php index 0d476c2..f650cd7 100644 --- a/src/Traits/Tags/GroupTagTrait.php +++ b/src/Traits/Tags/GroupTagTrait.php @@ -4,6 +4,7 @@ use BristolSU\ControlDB\Contracts\Models\Group; use BristolSU\ControlDB\Contracts\Repositories\Pivots\Tags\GroupGroupTag; +use BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTag; use BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTagCategory; use Illuminate\Support\Collection; @@ -63,5 +64,45 @@ public function removeGroup(Group $group): void { app(GroupGroupTag::class)->removeTagFromGroup($this, $group); } + + /** + * Set the name of the tag + * + * @param string $name + */ + public function setName(string $name): void + { + app(GroupTag::class)->update($this->id(), $name, $this->description(), $this->reference(), $this->categoryId()); + } + + /** + * Set the description of the Tag + * + * @param string $description + */ + public function setDescription(string $description): void + { + app(GroupTag::class)->update($this->id(), $this->name(), $description, $this->reference(), $this->categoryId()); + } + + /** + * Set the reference of the tag + * + * @param string $reference + */ + public function setReference(string $reference): void + { + app(GroupTag::class)->update($this->id(), $this->name(), $this->description(), $reference, $this->categoryId()); + } + + /** + * Set the tag category ID + * + * @param int $categoryId + */ + public function setTagCategoryId($categoryId): void + { + app(GroupTag::class)->update($this->id(), $this->name(), $this->description(), $this->reference(), $categoryId); + } } \ No newline at end of file diff --git a/src/Traits/Tags/PositionTagCategoryTrait.php b/src/Traits/Tags/PositionTagCategoryTrait.php index d667150..f994034 100644 --- a/src/Traits/Tags/PositionTagCategoryTrait.php +++ b/src/Traits/Tags/PositionTagCategoryTrait.php @@ -3,6 +3,7 @@ namespace BristolSU\ControlDB\Traits\Tags; use BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTag; +use BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTagCategory; use Illuminate\Support\Collection; /** @@ -20,5 +21,35 @@ public function tags(): Collection { return app(PositionTag::class)->allThroughTagCategory($this); } + + /** + * Set the name of the tag category + * + * @param string $name + */ + public function setName(string $name): void + { + app(PositionTagCategory::class)->update($this->id(), $name, $this->description(), $this->reference()); + } + + /** + * Set the description of the tag category + * + * @param string $description + */ + public function setDescription(string $description): void + { + app(PositionTagCategory::class)->update($this->id(), $this->name(), $description, $this->reference()); + } + + /** + * Set the reference of the tag category + * + * @param string $reference + */ + public function setReference(string $reference): void + { + app(PositionTagCategory::class)->update($this->id(), $this->name(), $this->description(), $reference); + } } \ No newline at end of file diff --git a/src/Traits/Tags/PositionTagTrait.php b/src/Traits/Tags/PositionTagTrait.php index 706eaa4..784d39a 100644 --- a/src/Traits/Tags/PositionTagTrait.php +++ b/src/Traits/Tags/PositionTagTrait.php @@ -4,6 +4,7 @@ use BristolSU\ControlDB\Contracts\Models\Position; use BristolSU\ControlDB\Contracts\Repositories\Pivots\Tags\PositionPositionTag; +use BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTag; use BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTagCategory; use Illuminate\Support\Collection; @@ -64,4 +65,43 @@ public function removePosition(Position $position): void app(PositionPositionTag::class)->removeTagFromPosition($this, $position); } + /** + * Set the name of the tag + * + * @param string $name + */ + public function setName(string $name): void + { + app(PositionTag::class)->update($this->id(), $name, $this->description(), $this->reference(), $this->categoryId()); + } + + /** + * Set the description of the Tag + * + * @param string $description + */ + public function setDescription(string $description): void + { + app(PositionTag::class)->update($this->id(), $this->name(), $description, $this->reference(), $this->categoryId()); + } + + /** + * Set the reference of the tag + * + * @param string $reference + */ + public function setReference(string $reference): void + { + app(PositionTag::class)->update($this->id(), $this->name(), $this->description(), $reference, $this->categoryId()); + } + + /** + * Set the tag category ID + * + * @param int $categoryId + */ + public function setTagCategoryId($categoryId): void + { + app(PositionTag::class)->update($this->id(), $this->name(), $this->description(), $this->reference(), $categoryId); + } } \ No newline at end of file diff --git a/src/Traits/Tags/RoleTagCategoryTrait.php b/src/Traits/Tags/RoleTagCategoryTrait.php index 9916020..568cf11 100644 --- a/src/Traits/Tags/RoleTagCategoryTrait.php +++ b/src/Traits/Tags/RoleTagCategoryTrait.php @@ -3,6 +3,7 @@ namespace BristolSU\ControlDB\Traits\Tags; use BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTag; +use BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTagCategory; use Illuminate\Support\Collection; /** @@ -20,5 +21,35 @@ public function tags(): Collection { return app(RoleTag::class)->allThroughTagCategory($this); } + + /** + * Set the name of the tag category + * + * @param string $name + */ + public function setName(string $name): void + { + app(RoleTagCategory::class)->update($this->id(), $name, $this->description(), $this->reference()); + } + + /** + * Set the description of the tag category + * + * @param string $description + */ + public function setDescription(string $description): void + { + app(RoleTagCategory::class)->update($this->id(), $this->name(), $description, $this->reference()); + } + + /** + * Set the reference of the tag category + * + * @param string $reference + */ + public function setReference(string $reference): void + { + app(RoleTagCategory::class)->update($this->id(), $this->name(), $this->description(), $reference); + } } \ No newline at end of file diff --git a/src/Traits/Tags/RoleTagTrait.php b/src/Traits/Tags/RoleTagTrait.php index 028c9df..f190fe1 100644 --- a/src/Traits/Tags/RoleTagTrait.php +++ b/src/Traits/Tags/RoleTagTrait.php @@ -4,6 +4,7 @@ use BristolSU\ControlDB\Contracts\Models\Role; use BristolSU\ControlDB\Contracts\Repositories\Pivots\Tags\RoleRoleTag; +use BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTag; use BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTagCategory; use Illuminate\Support\Collection; @@ -64,4 +65,43 @@ public function removeRole(Role $role): void app(RoleRoleTag::class)->removeTagFromRole($this, $role); } + /** + * Set the name of the tag + * + * @param string $name + */ + public function setName(string $name): void + { + app(RoleTag::class)->update($this->id(), $name, $this->description(), $this->reference(), $this->categoryId()); + } + + /** + * Set the description of the Tag + * + * @param string $description + */ + public function setDescription(string $description): void + { + app(RoleTag::class)->update($this->id(), $this->name(), $description, $this->reference(), $this->categoryId()); + } + + /** + * Set the reference of the tag + * + * @param string $reference + */ + public function setReference(string $reference): void + { + app(RoleTag::class)->update($this->id(), $this->name(), $this->description(), $reference, $this->categoryId()); + } + + /** + * Set the tag category ID + * + * @param int $categoryId + */ + public function setTagCategoryId($categoryId): void + { + app(RoleTag::class)->update($this->id(), $this->name(), $this->description(), $this->reference(), $categoryId); + } } \ No newline at end of file diff --git a/src/Traits/Tags/UserTagCategoryTrait.php b/src/Traits/Tags/UserTagCategoryTrait.php index 9d8a2de..b7dd0ce 100644 --- a/src/Traits/Tags/UserTagCategoryTrait.php +++ b/src/Traits/Tags/UserTagCategoryTrait.php @@ -3,6 +3,7 @@ namespace BristolSU\ControlDB\Traits\Tags; use BristolSU\ControlDB\Contracts\Repositories\Tags\UserTag; +use BristolSU\ControlDB\Contracts\Repositories\Tags\UserTagCategory; use Illuminate\Support\Collection; /** @@ -20,5 +21,35 @@ public function tags(): Collection { return app(UserTag::class)->allThroughTagCategory($this); } + + /** + * Set the name of the tag category + * + * @param string $name + */ + public function setName(string $name): void + { + app(UserTagCategory::class)->update($this->id(), $name, $this->description(), $this->reference()); + } + + /** + * Set the description of the tag category + * + * @param string $description + */ + public function setDescription(string $description): void + { + app(UserTagCategory::class)->update($this->id(), $this->name(), $description, $this->reference()); + } + + /** + * Set the reference of the tag category + * + * @param string $reference + */ + public function setReference(string $reference): void + { + app(UserTagCategory::class)->update($this->id(), $this->name(), $this->description(), $reference); + } } \ No newline at end of file diff --git a/src/Traits/Tags/UserTagTrait.php b/src/Traits/Tags/UserTagTrait.php index 6740680..ecb7016 100644 --- a/src/Traits/Tags/UserTagTrait.php +++ b/src/Traits/Tags/UserTagTrait.php @@ -4,6 +4,7 @@ use BristolSU\ControlDB\Contracts\Models\User; use BristolSU\ControlDB\Contracts\Repositories\Pivots\Tags\UserUserTag; +use BristolSU\ControlDB\Contracts\Repositories\Tags\UserTag; use BristolSU\ControlDB\Contracts\Repositories\Tags\UserTagCategory; use Illuminate\Support\Collection; @@ -64,4 +65,44 @@ public function removeUser(User $user): void app(UserUserTag::class)->removeTagFromUser($this, $user); } + /** + * Set the name of the tag + * + * @param string $name + */ + public function setName(string $name): void + { + app(UserTag::class)->update($this->id(), $name, $this->description(), $this->reference(), $this->categoryId()); + } + + /** + * Set the description of the Tag + * + * @param string $description + */ + public function setDescription(string $description): void + { + app(UserTag::class)->update($this->id(), $this->name(), $description, $this->reference(), $this->categoryId()); + } + + /** + * Set the reference of the tag + * + * @param string $reference + */ + public function setReference(string $reference): void + { + app(UserTag::class)->update($this->id(), $this->name(), $this->description(), $reference, $this->categoryId()); + } + + /** + * Set the tag category ID + * + * @param int $categoryId + */ + public function setTagCategoryId($categoryId): void + { + app(UserTag::class)->update($this->id(), $this->name(), $this->description(), $this->reference(), $categoryId); + } + } \ No newline at end of file diff --git a/src/Traits/UserTrait.php b/src/Traits/UserTrait.php index 1f0ba43..9fa0bb4 100644 --- a/src/Traits/UserTrait.php +++ b/src/Traits/UserTrait.php @@ -9,6 +9,7 @@ use BristolSU\ControlDB\Contracts\Repositories\Pivots\Tags\UserUserTag; use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserGroup; use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserRole; +use BristolSU\ControlDB\Contracts\Repositories\User; use BristolSU\ControlDB\Models\Group; use BristolSU\ControlDB\Models\Tags\UserTag; use Illuminate\Support\Collection; @@ -28,6 +29,16 @@ public function data(): DataUser { return app(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class)->getById($this->dataProviderId()); } + /** + * Set the ID of the data provider + * + * @param int $dataProviderId + */ + public function setDataProviderId(int $dataProviderId): void + { + app(User::class)->update($this->id(), $dataProviderId); + } + /** * Tags the user is tagged with * diff --git a/tests/Unit/Models/DataRoleTest.php b/tests/Unit/Models/DataRoleTest.php index dfe53b8..581e591 100644 --- a/tests/Unit/Models/DataRoleTest.php +++ b/tests/Unit/Models/DataRoleTest.php @@ -76,7 +76,7 @@ public function a_role_name_can_be_set_on_the_model() 'role_name' => 'Role1' ]); - $dataRole->setroleName('Role2'); + $dataRole->setRoleName('Role2'); $this->assertEquals('Role2', $dataRole->roleName()); } diff --git a/tests/Unit/Models/GroupTest.php b/tests/Unit/Models/GroupTest.php index dcef81c..a2aec79 100644 --- a/tests/Unit/Models/GroupTest.php +++ b/tests/Unit/Models/GroupTest.php @@ -31,7 +31,7 @@ public function a_data_provider_id_can_be_retrieved_from_the_model(){ /** @test */ public function a_data_provider_id_can_set_on_from_the_model(){ $group = factory(Group::class)->create([ - 'data_provider_id' => 5 + 'data_provider_id' => 2 ]); $group->setDataProviderId(5); diff --git a/tests/Unit/Models/PositionTest.php b/tests/Unit/Models/PositionTest.php index 7bed3a2..312093b 100644 --- a/tests/Unit/Models/PositionTest.php +++ b/tests/Unit/Models/PositionTest.php @@ -31,7 +31,7 @@ public function a_data_provider_id_can_be_retrieved_from_the_model(){ /** @test */ public function a_data_provider_id_can_set_on_from_the_model(){ $position = factory(Position::class)->create([ - 'data_provider_id' => 5 + 'data_provider_id' => 1 ]); $position->setDataProviderId(5); diff --git a/tests/Unit/Models/RoleTest.php b/tests/Unit/Models/RoleTest.php index 9cfb57b..679b53f 100644 --- a/tests/Unit/Models/RoleTest.php +++ b/tests/Unit/Models/RoleTest.php @@ -66,10 +66,10 @@ public function a_position_id_can_be_set_on_the_model() /** @test */ public function a_data_provider_id_can_be_retrieved_from_the_model(){ $role = factory(Role::class)->create([ - 'data_provider_id' => 5 + 'data_provider_id' => 2 ]); - $this->assertEquals(5, $role->dataProviderId()); + $this->assertEquals(2, $role->dataProviderId()); } /** @test */ diff --git a/tests/Unit/Models/Tags/GroupTagTest.php b/tests/Unit/Models/Tags/GroupTagTest.php index e48c383..74a4953 100644 --- a/tests/Unit/Models/Tags/GroupTagTest.php +++ b/tests/Unit/Models/Tags/GroupTagTest.php @@ -65,9 +65,11 @@ public function it_sets_a_reference_attribute(){ /** @test */ public function it_sets_a_category_id_attribute(){ - $groupTag = factory(GroupTag::class)->create(['tag_category_id' => 1]); - $groupTag->setTagCategoryId(2); - $this->assertEquals(2, $groupTag->categoryId()); + $tagCategory1 = factory(GroupTagCategory::class)->create(); + $tagCategory2 = factory(GroupTagCategory::class)->create(); + $groupTag = factory(GroupTag::class)->create(['tag_category_id' => $tagCategory1->id]); + $groupTag->setTagCategoryId($tagCategory2->id); + $this->assertEquals($tagCategory2->id, $groupTag->categoryId()); } /** @test */ diff --git a/tests/Unit/Models/Tags/PositionTagTest.php b/tests/Unit/Models/Tags/PositionTagTest.php index 3242298..597e49a 100644 --- a/tests/Unit/Models/Tags/PositionTagTest.php +++ b/tests/Unit/Models/Tags/PositionTagTest.php @@ -67,9 +67,11 @@ public function it_sets_a_reference_attribute(){ /** @test */ public function it_sets_a_category_id_attribute(){ - $positionTag = factory(PositionTag::class)->create(['tag_category_id' => 1]); - $positionTag->setTagCategoryId(2); - $this->assertEquals(2, $positionTag->categoryId()); + $tagCategory1 = factory(PositionTagCategory::class)->create(); + $tagCategory2 = factory(PositionTagCategory::class)->create(); + $positionTag = factory(PositionTag::class)->create(['tag_category_id' => $tagCategory1->id]); + $positionTag->setTagCategoryId($tagCategory2->id); + $this->assertEquals($tagCategory2->id, $positionTag->categoryId()); } /** @test */ diff --git a/tests/Unit/Models/Tags/RoleTagTest.php b/tests/Unit/Models/Tags/RoleTagTest.php index ebb6b42..ae5ded7 100644 --- a/tests/Unit/Models/Tags/RoleTagTest.php +++ b/tests/Unit/Models/Tags/RoleTagTest.php @@ -67,9 +67,11 @@ public function it_sets_a_reference_attribute(){ /** @test */ public function it_sets_a_category_id_attribute(){ - $roleTag = factory(RoleTag::class)->create(['tag_category_id' => 1]); - $roleTag->setTagCategoryId(2); - $this->assertEquals(2, $roleTag->categoryId()); + $tagCategory1 = factory(RoleTagCategory::class)->create(); + $tagCategory2 = factory(RoleTagCategory::class)->create(); + $roleTag = factory(RoleTag::class)->create(['tag_category_id' => $tagCategory1->id]); + $roleTag->setTagCategoryId($tagCategory2->id); + $this->assertEquals($tagCategory2->id, $roleTag->categoryId()); } /** @test */ diff --git a/tests/Unit/Models/Tags/UserTagTest.php b/tests/Unit/Models/Tags/UserTagTest.php index aed4379..1ef67d0 100644 --- a/tests/Unit/Models/Tags/UserTagTest.php +++ b/tests/Unit/Models/Tags/UserTagTest.php @@ -67,9 +67,11 @@ public function it_sets_a_reference_attribute(){ /** @test */ public function it_sets_a_category_id_attribute(){ - $userTag = factory(UserTag::class)->create(['tag_category_id' => 1]); - $userTag->setTagCategoryId(2); - $this->assertEquals(2, $userTag->categoryId()); + $tagCategory1 = factory(UserTagCategory::class)->create(); + $tagCategory2 = factory(UserTagCategory::class)->create(); + $userTag = factory(UserTag::class)->create(['tag_category_id' => $tagCategory1->id]); + $userTag->setTagCategoryId($tagCategory2->id); + $this->assertEquals($tagCategory2->id, $userTag->categoryId()); } /** @test */ diff --git a/tests/Unit/Models/UserTest.php b/tests/Unit/Models/UserTest.php index 39ebd01..7145756 100644 --- a/tests/Unit/Models/UserTest.php +++ b/tests/Unit/Models/UserTest.php @@ -30,9 +30,9 @@ public function a_data_provider_id_can_set_on_from_the_model(){ 'data_provider_id' => 5 ]); - $user->setDataProviderId(5); + $user->setDataProviderId(6); - $this->assertEquals(5, $user->dataProviderId()); + $this->assertEquals(6, $user->dataProviderId()); } /** @test */ diff --git a/tests/Unit/Repositories/DataGroupTest.php b/tests/Unit/Repositories/DataGroupTest.php index 226c200..4cffafd 100644 --- a/tests/Unit/Repositories/DataGroupTest.php +++ b/tests/Unit/Repositories/DataGroupTest.php @@ -112,4 +112,49 @@ public function getAllWhere_returns_all_model_matching_the_attributes(){ $this->assertTrue($dataGroups[0]->is($dbDataGroup[0])); $this->assertTrue($dataGroups[1]->is($dbDataGroup[1])); } + + /** @test */ + public function update_updates_a_group() + { + $dataGroup = factory(DataGroup::class)->create([ + 'name' => 'Toby', + 'email' => 'support@example.com', + ]); + $this->assertDatabaseHas('control_data_group', [ + 'id' => $dataGroup->id(), + 'name' => 'Toby', + 'email' => 'support@example.com', + ]); + $repository = new \BristolSU\ControlDB\Repositories\DataGroup(); + $repository->update($dataGroup->id(), 'Toby2', 'support@example2.com'); + $this->assertDatabaseMissing('control_data_group', [ + 'id' => $dataGroup->id(), + 'name' => 'Toby', + 'email' => 'support@example.com', + ]); + $this->assertDatabaseHas('control_data_group', [ + 'id' => $dataGroup->id(), + 'name' => 'Toby2', + 'email' => 'support@example2.com', + ]); + + } + + /** @test */ + public function update_returns_the_updated_group() + { + $dataGroup = factory(DataGroup::class)->create([ + 'name' => 'Toby', + 'email' => 'support@example.com', + ]); + $this->assertEquals('Toby', $dataGroup->name()); + $this->assertEquals('support@example.com', $dataGroup->email()); + + $repository = new \BristolSU\ControlDB\Repositories\DataGroup(); + $updatedGroup = $repository->update($dataGroup->id(), 'Toby2', 'support@example2.com'); + + $this->assertEquals('Toby2', $updatedGroup->name()); + $this->assertEquals('support@example2.com', $updatedGroup->email()); + + } } diff --git a/tests/Unit/Repositories/DataPositionTest.php b/tests/Unit/Repositories/DataPositionTest.php index df2ff33..c1c259e 100644 --- a/tests/Unit/Repositories/DataPositionTest.php +++ b/tests/Unit/Repositories/DataPositionTest.php @@ -112,4 +112,49 @@ public function getAllWhere_returns_all_model_matching_the_attributes(){ $this->assertTrue($dataPositions[0]->is($dbDataPosition[0])); $this->assertTrue($dataPositions[1]->is($dbDataPosition[1])); } + + /** @test */ + public function update_updates_a_position() + { + $dataPosition = factory(DataPosition::class)->create([ + 'name' => 'Toby', + 'description' => 'description_example.com', + ]); + $this->assertDatabaseHas('control_data_position', [ + 'id' => $dataPosition->id(), + 'name' => 'Toby', + 'description' => 'description_example.com', + ]); + $repository = new \BristolSU\ControlDB\Repositories\DataPosition(); + $repository->update($dataPosition->id(), 'Toby2', 'description_example2.com'); + $this->assertDatabaseMissing('control_data_position', [ + 'id' => $dataPosition->id(), + 'name' => 'Toby', + 'description' => 'description_example.com', + ]); + $this->assertDatabaseHas('control_data_position', [ + 'id' => $dataPosition->id(), + 'name' => 'Toby2', + 'description' => 'description_example2.com', + ]); + + } + + /** @test */ + public function update_returns_the_updated_position() + { + $dataPosition = factory(DataPosition::class)->create([ + 'name' => 'Toby', + 'description' => 'description_example.com', + ]); + $this->assertEquals('Toby', $dataPosition->name()); + $this->assertEquals('description_example.com', $dataPosition->description()); + + $repository = new \BristolSU\ControlDB\Repositories\DataPosition(); + $updatedPosition = $repository->update($dataPosition->id(), 'Toby2', 'description_example2.com'); + + $this->assertEquals('Toby2', $updatedPosition->name()); + $this->assertEquals('description_example2.com', $updatedPosition->description()); + + } } diff --git a/tests/Unit/Repositories/DataRoleTest.php b/tests/Unit/Repositories/DataRoleTest.php index d161c50..26ab2c8 100644 --- a/tests/Unit/Repositories/DataRoleTest.php +++ b/tests/Unit/Repositories/DataRoleTest.php @@ -113,4 +113,49 @@ public function getAllWhere_returns_all_model_matching_the_attributes(){ $this->assertTrue($dataRoles[1]->is($dbDataRole[1])); } + /** @test */ + public function update_updates_a_role() + { + $dataRole = factory(DataRole::class)->create([ + 'role_name' => 'Toby', + 'email' => 'support@example.com', + ]); + $this->assertDatabaseHas('control_data_role', [ + 'id' => $dataRole->id(), + 'role_name' => 'Toby', + 'email' => 'support@example.com', + ]); + $repository = new \BristolSU\ControlDB\Repositories\DataRole(); + $repository->update($dataRole->id(), 'Toby2', 'support@example2.com'); + $this->assertDatabaseMissing('control_data_role', [ + 'id' => $dataRole->id(), + 'role_name' => 'Toby', + 'email' => 'support@example.com', + ]); + $this->assertDatabaseHas('control_data_role', [ + 'id' => $dataRole->id(), + 'role_name' => 'Toby2', + 'email' => 'support@example2.com', + ]); + + } + + /** @test */ + public function update_returns_the_updated_role() + { + $dataRole = factory(DataRole::class)->create([ + 'role_name' => 'Toby', + 'email' => 'support@example.com', + ]); + $this->assertEquals('Toby', $dataRole->roleName()); + $this->assertEquals('support@example.com', $dataRole->email()); + + $repository = new \BristolSU\ControlDB\Repositories\DataRole(); + $updatedRole = $repository->update($dataRole->id(), 'Toby2', 'support@example2.com'); + + $this->assertEquals('Toby2', $updatedRole->roleName()); + $this->assertEquals('support@example2.com', $updatedRole->email()); + + } + } diff --git a/tests/Unit/Repositories/DataUserTest.php b/tests/Unit/Repositories/DataUserTest.php index 0a3fb0f..24bb0e6 100644 --- a/tests/Unit/Repositories/DataUserTest.php +++ b/tests/Unit/Repositories/DataUserTest.php @@ -12,17 +12,19 @@ class DataUserTest extends TestCase { /** @test */ - public function getById_returns_a_data_user_by_id(){ + public function getById_returns_a_data_user_by_id() + { $dataUser = factory(DataUser::class)->create(['id' => 1]); - + $repository = new \BristolSU\ControlDB\Repositories\DataUser(); $dbDataUser = $repository->getById(1); - + $this->assertTrue($dataUser->is($dbDataUser)); } - + /** @test */ - public function getById_throws_a_ModelNotFoundException_if_the_data_user_is_not_found(){ + public function getById_throws_a_ModelNotFoundException_if_the_data_user_is_not_found() + { $this->expectException(ModelNotFoundException::class); $repository = new \BristolSU\ControlDB\Repositories\DataUser(); @@ -30,7 +32,8 @@ public function getById_throws_a_ModelNotFoundException_if_the_data_user_is_not_ } /** @test */ - public function getAllWhere_returns_all_model_matching_the_attributes(){ + public function getAllWhere_returns_all_model_matching_the_attributes() + { DataUser::addProperty('additionalAttr'); $attributes = ['email' => 'email@email.com', 'additional_attributes' => json_encode(['additionalAttr' => 15])]; @@ -44,23 +47,25 @@ public function getAllWhere_returns_all_model_matching_the_attributes(){ $this->assertTrue($dataUsers[0]->is($dbDataUser[0])); $this->assertTrue($dataUsers[1]->is($dbDataUser[1])); } - + /** @test */ - public function getWhere_returns_the_first_model_matching_the_attributes(){ + public function getWhere_returns_the_first_model_matching_the_attributes() + { $attributes = ['email' => 'email@email.com']; $dataUser = factory(DataUser::class)->create($attributes); - + $repository = new \BristolSU\ControlDB\Repositories\DataUser(); $dbDataUser = $repository->getWhere($attributes); - + $this->assertTrue($dataUser->is($dbDataUser)); } /** @test */ - public function getWhere_throws_a_ModelNotFoundException_if_a_data_user_is_not_found(){ + public function getWhere_throws_a_ModelNotFoundException_if_a_data_user_is_not_found() + { $this->expectException(ModelNotFoundException::class); - + $attributes = ['email' => 'email@email.com']; $dataUser = factory(DataUser::class)->create(); @@ -68,12 +73,13 @@ public function getWhere_throws_a_ModelNotFoundException_if_a_data_user_is_not_f $repository = new \BristolSU\ControlDB\Repositories\DataUser(); $dbDataUser = $repository->getWhere($attributes); } - + /** @test */ - public function create_creates_a_new_data_user(){ + public function create_creates_a_new_data_user() + { $repository = new \BristolSU\ControlDB\Repositories\DataUser(); $dataUser = $repository->create('FirstName', 'Lastname', 'email@email.com', Carbon::make('14-02-1990'), 'TobyT'); - + $this->assertDatabaseHas('control_data_user', [ 'first_name' => 'FirstName', 'last_name' => 'Lastname', @@ -82,22 +88,24 @@ public function create_creates_a_new_data_user(){ 'preferred_name' => 'TobyT' ]); } - + /** @test */ - public function create_can_be_called_with_no_arguments(){ + public function create_can_be_called_with_no_arguments() + { $repository = new \BristolSU\ControlDB\Repositories\DataUser(); $dataUser = $repository->create(); $this->assertEquals(1, DB::table('control_data_user')->count()); } - + /** @test */ - public function create_returns_the_created_model(){ + public function create_returns_the_created_model() + { $repository = new \BristolSU\ControlDB\Repositories\DataUser(); $dataUser = $repository->create('FirstName', 'Lastname', 'email@email.com', Carbon::make('14-02-1990'), 'TobyT'); - + $this->assertInstanceOf(DataUser::class, $dataUser); - + $this->assertEquals('FirstName', $dataUser->firstName()); $this->assertEquals('Lastname', $dataUser->lastName()); $this->assertEquals('email@email.com', $dataUser->email()); @@ -106,7 +114,8 @@ public function create_returns_the_created_model(){ } /** @test */ - public function getWhere_also_searches_additional_attributes(){ + public function getWhere_also_searches_additional_attributes() + { DataUser::addProperty('student_id'); $dataUser1 = factory(DataUser::class)->create(['email' => 'email@email.com']); $dataUser1->saveAdditionalAttribute('student_id', 'xy123'); @@ -119,4 +128,72 @@ public function getWhere_also_searches_additional_attributes(){ $this->assertTrue($dataUser2->is($dbDataUser2)); } + /** @test */ + public function update_updates_a_user() + { + $dataUser = factory(DataUser::class)->create([ + 'first_name' => 'Toby', + 'last_name' => 'Twigger', + 'email' => 'support@example.com', + 'dob' => Carbon::create(1850, 12, 20), + 'preferred_name' => 'Toby T' + ]); + $this->assertDatabaseHas('control_data_user', [ + 'id' => $dataUser->id(), + 'first_name' => 'Toby', + 'last_name' => 'Twigger', + 'email' => 'support@example.com', + 'dob' => '1850-12-20 00:00:00', + 'preferred_name' => 'Toby T' + ]); + $repository = new \BristolSU\ControlDB\Repositories\DataUser(); + $repository->update($dataUser->id(), 'Toby2', 'Twigger2', 'support@example2.com', + Carbon::create(1950, 8, 15), 'Toby T2'); + $this->assertDatabaseMissing('control_data_user', [ + 'id' => $dataUser->id(), + 'first_name' => 'Toby', + 'last_name' => 'Twigger', + 'email' => 'support@example.com', + 'dob' => '1850-12-20 00:00:00', + 'preferred_name' => 'Toby T' + ]); + $this->assertDatabaseHas('control_data_user', [ + 'id' => $dataUser->id(), + 'first_name' => 'Toby2', + 'last_name' => 'Twigger2', + 'email' => 'support@example2.com', + 'dob' => '1950-08-15 00:00:00', + 'preferred_name' => 'Toby T2' + ]); + + } + + /** @test */ + public function update_returns_the_updated_user() + { + $dataUser = factory(DataUser::class)->create([ + 'first_name' => 'Toby', + 'last_name' => 'Twigger', + 'email' => 'support@example.com', + 'dob' => Carbon::create(1850, 12, 20), + 'preferred_name' => 'Toby T' + ]); + $this->assertEquals('Toby', $dataUser->firstName()); + $this->assertEquals('Twigger', $dataUser->lastName()); + $this->assertEquals('support@example.com', $dataUser->email()); + $this->assertTrue(Carbon::create(1850, 12, 20)->equalTo($dataUser->dob())); + $this->assertEquals('Toby T', $dataUser->preferredName()); + + $repository = new \BristolSU\ControlDB\Repositories\DataUser(); + $updatedUser = $repository->update($dataUser->id(), 'Toby2', 'Twigger2', 'support@example2.com', + Carbon::create(1950, 8, 15), 'Toby T2'); + + $this->assertEquals('Toby2', $updatedUser->firstName()); + $this->assertEquals('Twigger2', $updatedUser->lastName()); + $this->assertEquals('support@example2.com', $updatedUser->email()); + $this->assertTrue(Carbon::create(1950, 8, 15)->equalTo($updatedUser->dob())); + $this->assertEquals('Toby T2', $updatedUser->preferredName()); + + } + } diff --git a/tests/Unit/Repositories/GroupTest.php b/tests/Unit/Repositories/GroupTest.php index 88f9fd5..ec7c827 100644 --- a/tests/Unit/Repositories/GroupTest.php +++ b/tests/Unit/Repositories/GroupTest.php @@ -122,5 +122,40 @@ public function paginate_returns_the_number_of_groups_specified_for_the_given_pa $this->assertTrue($groups[18]->is($paginatedGroups->shift())); $this->assertTrue($groups[19]->is($paginatedGroups->shift())); } + + /** @test */ + public function update_updates_a_group(){ + $dataGroup1 = factory(DataGroup::class)->create(); + $dataGroup2 = factory(DataGroup::class)->create(); + $group = factory(Group::class)->create(['data_provider_id' => $dataGroup1->id()]); + + $this->assertDatabaseHas('control_groups', [ + 'id' => $group->id(), 'data_provider_id' => $dataGroup1->id() + ]); + + $repository = new \BristolSU\ControlDB\Repositories\Group(); + $repository->update($group->id(), $dataGroup2->id()); + + $this->assertDatabaseMissing('control_groups', [ + 'id' => $group->id(), 'data_provider_id' => $dataGroup1->id() + ]); + $this->assertDatabaseHas('control_groups', [ + 'id' => $group->id(), 'data_provider_id' => $dataGroup2->id() + ]); + } + + /** @test */ + public function update_returns_the_updated_group(){ + $dataGroup1 = factory(DataGroup::class)->create(); + $dataGroup2 = factory(DataGroup::class)->create(); + $group = factory(Group::class)->create(['data_provider_id' => $dataGroup1->id()]); + + $this->assertEquals($dataGroup1->id(), $group->dataProviderId()); + + $repository = new \BristolSU\ControlDB\Repositories\Group(); + $updatedGroup = $repository->update($group->id(), $dataGroup2->id()); + + $this->assertEquals($dataGroup2->id(), $updatedGroup->dataProviderId()); + } } diff --git a/tests/Unit/Repositories/PositionTest.php b/tests/Unit/Repositories/PositionTest.php index 72cce5d..3caeebf 100644 --- a/tests/Unit/Repositories/PositionTest.php +++ b/tests/Unit/Repositories/PositionTest.php @@ -123,4 +123,39 @@ public function paginate_returns_the_number_of_positions_specified_for_the_given $this->assertTrue($positions[19]->is($paginatedPositions->shift())); } + /** @test */ + public function update_updates_a_position(){ + $dataPosition1 = factory(DataPosition::class)->create(); + $dataPosition2 = factory(DataPosition::class)->create(); + $position = factory(Position::class)->create(['data_provider_id' => $dataPosition1->id()]); + + $this->assertDatabaseHas('control_positions', [ + 'id' => $position->id(), 'data_provider_id' => $dataPosition1->id() + ]); + + $repository = new \BristolSU\ControlDB\Repositories\Position(); + $repository->update($position->id(), $dataPosition2->id()); + + $this->assertDatabaseMissing('control_positions', [ + 'id' => $position->id(), 'data_provider_id' => $dataPosition1->id() + ]); + $this->assertDatabaseHas('control_positions', [ + 'id' => $position->id(), 'data_provider_id' => $dataPosition2->id() + ]); + } + + /** @test */ + public function update_returns_the_updated_position(){ + $dataPosition1 = factory(DataPosition::class)->create(); + $dataPosition2 = factory(DataPosition::class)->create(); + $position = factory(Position::class)->create(['data_provider_id' => $dataPosition1->id()]); + + $this->assertEquals($dataPosition1->id(), $position->dataProviderId()); + + $repository = new \BristolSU\ControlDB\Repositories\Position(); + $updatedPosition = $repository->update($position->id(), $dataPosition2->id()); + + $this->assertEquals($dataPosition2->id(), $updatedPosition->dataProviderId()); + } + } diff --git a/tests/Unit/Repositories/RoleTest.php b/tests/Unit/Repositories/RoleTest.php index 6fe9816..169fe12 100644 --- a/tests/Unit/Repositories/RoleTest.php +++ b/tests/Unit/Repositories/RoleTest.php @@ -159,4 +159,51 @@ public function paginate_returns_the_number_of_roles_specified_for_the_given_pag $this->assertTrue($roles[19]->is($paginatedRoles->shift())); } + /** @test */ + public function update_updates_a_role(){ + $dataRole1 = factory(DataRole::class)->create(); + $dataRole2 = factory(DataRole::class)->create(); + $position1 = factory(Position::class)->create(); + $position2 = factory(Position::class)->create(); + $group1 = factory(Group::class)->create(); + $group2 = factory(Group::class)->create(); + $role = factory(Role::class)->create(['data_provider_id' => $dataRole1->id(), 'position_id' => $position1->id(), 'group_id' => $group1->id()]); + + $this->assertDatabaseHas('control_roles', [ + 'id' => $role->id(), 'data_provider_id' => $dataRole1->id(), 'position_id' => $position1->id(), 'group_id' => $group1->id() + ]); + + $repository = new \BristolSU\ControlDB\Repositories\Role(); + $repository->update($role->id(), $position2->id(), $group2->id(), $dataRole2->id()); + + $this->assertDatabaseMissing('control_roles', [ + 'id' => $role->id(), 'data_provider_id' => $dataRole1->id(), 'position_id' => $position1->id(), 'group_id' => $group1->id() + ]); + $this->assertDatabaseHas('control_roles', [ + 'id' => $role->id(), 'data_provider_id' => $dataRole2->id(), 'position_id' => $position2->id(), 'group_id' => $group2->id() + ]); + } + + /** @test */ + public function update_returns_the_updated_role(){ + $dataRole1 = factory(DataRole::class)->create(); + $dataRole2 = factory(DataRole::class)->create(); + $position1 = factory(Position::class)->create(); + $position2 = factory(Position::class)->create(); + $group1 = factory(Group::class)->create(); + $group2 = factory(Group::class)->create(); + $role = factory(Role::class)->create(['data_provider_id' => $dataRole1->id(), 'position_id' => $position1->id(), 'group_id' => $group1->id()]); + + $this->assertEquals($dataRole1->id(), $role->dataProviderId()); + $this->assertEquals($position1->id(), $role->positionId()); + $this->assertEquals($group1->id(), $role->groupId()); + + $repository = new \BristolSU\ControlDB\Repositories\Role(); + $updatedRole = $repository->update($role->id(), $position2->id(), $group2->id(), $dataRole2->id()); + + $this->assertEquals($dataRole2->id(), $updatedRole->dataProviderId()); + $this->assertEquals($position2->id(), $updatedRole->positionId()); + $this->assertEquals($group2->id(), $updatedRole->groupId()); + } + } diff --git a/tests/Unit/Repositories/UserTest.php b/tests/Unit/Repositories/UserTest.php index 485f5aa..bc9e3dd 100644 --- a/tests/Unit/Repositories/UserTest.php +++ b/tests/Unit/Repositories/UserTest.php @@ -123,5 +123,39 @@ public function paginate_returns_the_number_of_users_specified_for_the_given_pag $this->assertTrue($users[18]->is($paginatedUsers->shift())); $this->assertTrue($users[19]->is($paginatedUsers->shift())); } + + /** @test */ + public function update_updates_a_user(){ + $dataUser1 = factory(DataUser::class)->create(); + $dataUser2 = factory(DataUser::class)->create(); + $user = factory(User::class)->create(['data_provider_id' => $dataUser1->id()]); + + $this->assertDatabaseHas('control_users', [ + 'id' => $user->id(), 'data_provider_id' => $dataUser1->id() + ]); + + $repository = new \BristolSU\ControlDB\Repositories\User(); + $repository->update($user->id(), $dataUser2->id()); + + $this->assertDatabaseMissing('control_users', [ + 'id' => $user->id(), 'data_provider_id' => $dataUser1->id() + ]); + $this->assertDatabaseHas('control_users', [ + 'id' => $user->id(), 'data_provider_id' => $dataUser2->id() + ]); + } + + /** @test */ + public function update_returns_the_updated_user(){ + $dataUser1 = factory(DataUser::class)->create(); + $dataUser2 = factory(DataUser::class)->create(); + $user = factory(User::class)->create(['data_provider_id' => $dataUser1->id()]); + + $this->assertEquals($dataUser1->id(), $user->dataProviderId()); + + $repository = new \BristolSU\ControlDB\Repositories\User(); + $updatedUser = $repository->update($user->id(), $dataUser2->id()); + $this->assertEquals($dataUser2->id(), $updatedUser->dataProviderId()); + } } diff --git a/tests/Unit/Traits/UserTraitTest.php b/tests/Unit/Traits/UserTraitTest.php index 3123ffc..626065c 100644 --- a/tests/Unit/Traits/UserTraitTest.php +++ b/tests/Unit/Traits/UserTraitTest.php @@ -2,11 +2,9 @@ namespace BristolSU\Tests\ControlDB\Unit\Traits; -use BristolSU\ControlDB\Models\DataGroup; use BristolSU\ControlDB\Models\DataUser; use BristolSU\ControlDB\Models\Group; use BristolSU\ControlDB\Models\Role; -use BristolSU\ControlDB\Models\Tags\GroupTag; use BristolSU\ControlDB\Models\Tags\UserTag; use BristolSU\ControlDB\Models\User; use BristolSU\Tests\ControlDB\TestCase; From b1225f7aac044e339dd75e9c7b318a91e40ce787 Mon Sep 17 00:00:00 2001 From: Toby Twigger Date: Fri, 24 Apr 2020 18:31:37 +0100 Subject: [PATCH 2/7] Update binding --- composer.lock | 1000 ++++++++++++++++-------------- src/ControlDBServiceProvider.php | 12 +- 2 files changed, 536 insertions(+), 476 deletions(-) diff --git a/composer.lock b/composer.lock index cafa639..f478c2b 100644 --- a/composer.lock +++ b/composer.lock @@ -248,16 +248,16 @@ }, { "name": "egulias/email-validator", - "version": "2.1.15", + "version": "2.1.17", "source": { "type": "git", "url": "https://github.com/egulias/EmailValidator.git", - "reference": "e834eea5306d85d67de5a05db5882911d5b29357" + "reference": "ade6887fd9bd74177769645ab5c474824f8a418a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/e834eea5306d85d67de5a05db5882911d5b29357", - "reference": "e834eea5306d85d67de5a05db5882911d5b29357", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/ade6887fd9bd74177769645ab5c474824f8a418a", + "reference": "ade6887fd9bd74177769645ab5c474824f8a418a", "shasum": "" }, "require": { @@ -302,7 +302,7 @@ "validation", "validator" ], - "time": "2020-01-20T21:40:59+00:00" + "time": "2020-02-13T22:36:52+00:00" }, { "name": "fzaninotto/faker", @@ -404,16 +404,16 @@ }, { "name": "laravel/framework", - "version": "v6.13.1", + "version": "v6.18.10", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "f0059760814b76fb5f98bb80628607c7560ebe58" + "reference": "9177744ccdd8d5db970fdff2383fe89c2e94aabe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/f0059760814b76fb5f98bb80628607c7560ebe58", - "reference": "f0059760814b76fb5f98bb80628607c7560ebe58", + "url": "https://api.github.com/repos/laravel/framework/zipball/9177744ccdd8d5db970fdff2383fe89c2e94aabe", + "reference": "9177744ccdd8d5db970fdff2383fe89c2e94aabe", "shasum": "" }, "require": { @@ -423,8 +423,7 @@ "ext-json": "*", "ext-mbstring": "*", "ext-openssl": "*", - "league/commonmark": "^1.1", - "league/commonmark-ext-table": "^2.1", + "league/commonmark": "^1.3", "league/flysystem": "^1.0.8", "monolog/monolog": "^1.12|^2.0", "nesbot/carbon": "^2.0", @@ -482,7 +481,7 @@ "aws/aws-sdk-php": "^3.0", "doctrine/dbal": "^2.6", "filp/whoops": "^2.4", - "guzzlehttp/guzzle": "^6.3", + "guzzlehttp/guzzle": "^6.3|^7.0", "league/flysystem-cached-adapter": "^1.0", "mockery/mockery": "^1.3.1", "moontoast/math": "^1.1", @@ -499,11 +498,11 @@ "ext-memcached": "Required to use the memcache cache driver.", "ext-pcntl": "Required to use all features of the queue worker.", "ext-posix": "Required to use all features of the queue worker.", - "ext-redis": "Required to use the Redis cache and queue drivers.", + "ext-redis": "Required to use the Redis cache and queue drivers (^4.0|^5.0).", "filp/whoops": "Required for friendly error pages in development (^2.4).", - "fzaninotto/faker": "Required to use the eloquent factory builder (^1.4).", - "guzzlehttp/guzzle": "Required to use the Mailgun mail driver and the ping methods on schedules (^6.0).", - "laravel/tinker": "Required to use the tinker console command (^1.0).", + "fzaninotto/faker": "Required to use the eloquent factory builder (^1.9.1).", + "guzzlehttp/guzzle": "Required to use the Mailgun mail driver and the ping methods on schedules (^6.0|^7.0).", + "laravel/tinker": "Required to use the tinker console command (^2.0).", "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).", "league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).", "league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0).", @@ -547,51 +546,49 @@ "framework", "laravel" ], - "time": "2020-01-28T21:44:01+00:00" + "time": "2020-04-21T18:53:10+00:00" }, { "name": "league/commonmark", - "version": "1.2.2", + "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/thephpleague/commonmark.git", - "reference": "34cf4ddb3892c715ae785c880e6691d839cff88d" + "reference": "9e780d972185e4f737a03bade0fd34a9e67bbf31" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/34cf4ddb3892c715ae785c880e6691d839cff88d", - "reference": "34cf4ddb3892c715ae785c880e6691d839cff88d", + "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/9e780d972185e4f737a03bade0fd34a9e67bbf31", + "reference": "9e780d972185e4f737a03bade0fd34a9e67bbf31", "shasum": "" }, "require": { "ext-mbstring": "*", "php": "^7.1" }, - "replace": { - "colinodell/commonmark-php": "*" + "conflict": { + "scrutinizer/ocular": "1.7.*" }, "require-dev": { "cebe/markdown": "~1.0", "commonmark/commonmark.js": "0.29.1", "erusev/parsedown": "~1.0", "ext-json": "*", + "github/gfm": "0.29.0", "michelf/php-markdown": "~1.4", "mikehaertl/php-shellcommand": "^1.4", - "phpstan/phpstan-shim": "^0.11.5", + "phpstan/phpstan": "^0.12", "phpunit/phpunit": "^7.5", "scrutinizer/ocular": "^1.5", "symfony/finder": "^4.2" }, - "suggest": { - "league/commonmark-extras": "Library of useful extensions including smart punctuation" - }, "bin": [ "bin/commonmark" ], "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "1.4-dev" } }, "autoload": { @@ -611,92 +608,32 @@ "role": "Lead Developer" } ], - "description": "PHP Markdown parser based on the CommonMark spec", + "description": "Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and Github-Flavored Markdown (GFM)", "homepage": "https://commonmark.thephpleague.com", "keywords": [ "commonmark", + "flavored", + "gfm", + "github", + "github-flavored", "markdown", + "md", "parser" ], - "time": "2020-01-16T01:18:13+00:00" - }, - { - "name": "league/commonmark-ext-table", - "version": "v2.1.0", - "source": { - "type": "git", - "url": "https://github.com/thephpleague/commonmark-ext-table.git", - "reference": "3228888ea69636e855efcf6636ff8e6316933fe7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/thephpleague/commonmark-ext-table/zipball/3228888ea69636e855efcf6636ff8e6316933fe7", - "reference": "3228888ea69636e855efcf6636ff8e6316933fe7", - "shasum": "" - }, - "require": { - "league/commonmark": "~0.19.3|^1.0", - "php": "^7.1" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.14", - "phpstan/phpstan": "~0.11", - "phpunit/phpunit": "^7.0|^8.0", - "symfony/var-dumper": "^4.0", - "vimeo/psalm": "^3.0" - }, - "type": "commonmark-extension", - "extra": { - "branch-alias": { - "dev-master": "2.2-dev" - } - }, - "autoload": { - "psr-4": { - "League\\CommonMark\\Ext\\Table\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Martin Hasoň", - "email": "martin.hason@gmail.com" - }, - { - "name": "Webuni s.r.o.", - "homepage": "https://www.webuni.cz" - }, - { - "name": "Colin O'Dell", - "email": "colinodell@gmail.com", - "homepage": "https://www.colinodell.com" - } - ], - "description": "Table extension for league/commonmark", - "homepage": "https://github.com/thephpleague/commonmark-ext-table", - "keywords": [ - "commonmark", - "extension", - "markdown", - "table" - ], - "time": "2019-09-26T13:28:33+00:00" + "time": "2020-04-24T13:39:56+00:00" }, { "name": "league/flysystem", - "version": "1.0.63", + "version": "1.0.67", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "8132daec326565036bc8e8d1876f77ec183a7bd6" + "reference": "5b1f36c75c4bdde981294c2a0ebdb437ee6f275e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/8132daec326565036bc8e8d1876f77ec183a7bd6", - "reference": "8132daec326565036bc8e8d1876f77ec183a7bd6", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/5b1f36c75c4bdde981294c2a0ebdb437ee6f275e", + "reference": "5b1f36c75c4bdde981294c2a0ebdb437ee6f275e", "shasum": "" }, "require": { @@ -708,7 +645,7 @@ }, "require-dev": { "phpspec/phpspec": "^3.4", - "phpunit/phpunit": "^5.7.10" + "phpunit/phpunit": "^5.7.26" }, "suggest": { "ext-fileinfo": "Required for MimeType", @@ -767,7 +704,7 @@ "sftp", "storage" ], - "time": "2020-01-04T16:30:31+00:00" + "time": "2020-04-16T13:21:26+00:00" }, { "name": "mockery/mockery", @@ -965,16 +902,16 @@ }, { "name": "nesbot/carbon", - "version": "2.29.1", + "version": "2.32.2", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "e509be5bf2d703390e69e14496d9a1168452b0a2" + "reference": "f10e22cf546704fab1db4ad4b9dedbc5c797a0dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/e509be5bf2d703390e69e14496d9a1168452b0a2", - "reference": "e509be5bf2d703390e69e14496d9a1168452b0a2", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/f10e22cf546704fab1db4ad4b9dedbc5c797a0dc", + "reference": "f10e22cf546704fab1db4ad4b9dedbc5c797a0dc", "shasum": "" }, "require": { @@ -983,6 +920,7 @@ "symfony/translation": "^3.4 || ^4.0 || ^5.0" }, "require-dev": { + "doctrine/orm": "^2.7", "friendsofphp/php-cs-fixer": "^2.14 || ^3.0", "kylekatarnls/multi-tester": "^1.1", "phpmd/phpmd": "^2.8", @@ -1031,7 +969,7 @@ "datetime", "time" ], - "time": "2020-01-21T09:36:43+00:00" + "time": "2020-03-31T13:43:19+00:00" }, { "name": "opis/closure", @@ -1096,22 +1034,22 @@ }, { "name": "orchestra/testbench", - "version": "v4.6.0", + "version": "v4.7.0", "source": { "type": "git", "url": "https://github.com/orchestral/testbench.git", - "reference": "0b537bf4d34a8da92759b79fcbe371e10b0135f0" + "reference": "133e2756f15e8e605c22973d255290798f933e70" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/orchestral/testbench/zipball/0b537bf4d34a8da92759b79fcbe371e10b0135f0", - "reference": "0b537bf4d34a8da92759b79fcbe371e10b0135f0", + "url": "https://api.github.com/repos/orchestral/testbench/zipball/133e2756f15e8e605c22973d255290798f933e70", + "reference": "133e2756f15e8e605c22973d255290798f933e70", "shasum": "" }, "require": { - "laravel/framework": "^6.9", + "laravel/framework": "^6.18", "mockery/mockery": "~1.2.3 || ^1.3.1", - "orchestra/testbench-core": "^4.6", + "orchestra/testbench-core": "^4.7", "php": ">=7.2", "phpunit/phpunit": "^8.3 || ^9.0" }, @@ -1142,20 +1080,20 @@ "orchestral", "testing" ], - "time": "2020-01-29T23:03:49+00:00" + "time": "2020-03-06T23:23:46+00:00" }, { "name": "orchestra/testbench-core", - "version": "v4.6.0", + "version": "v4.7.1", "source": { "type": "git", "url": "https://github.com/orchestral/testbench-core.git", - "reference": "6e6f1c330d37563d2ecca125d6b672e752ab88b5" + "reference": "c8e9ce9578fe13c075751d81f23dc2c3bb37a134" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/orchestral/testbench-core/zipball/6e6f1c330d37563d2ecca125d6b672e752ab88b5", - "reference": "6e6f1c330d37563d2ecca125d6b672e752ab88b5", + "url": "https://api.github.com/repos/orchestral/testbench-core/zipball/c8e9ce9578fe13c075751d81f23dc2c3bb37a134", + "reference": "c8e9ce9578fe13c075751d81f23dc2c3bb37a134", "shasum": "" }, "require": { @@ -1163,13 +1101,13 @@ "php": ">=7.2" }, "require-dev": { - "laravel/framework": "^6.9", - "laravel/laravel": "dev-master", - "mockery/mockery": "^1.2.3", + "laravel/framework": "^6.18.0", + "laravel/laravel": "6.x-dev", + "mockery/mockery": "~1.2.3 || ^1.3.1", "phpunit/phpunit": "^8.3 || ^9.0" }, "suggest": { - "laravel/framework": "Required for testing (^6.9).", + "laravel/framework": "Required for testing (^6.18).", "mockery/mockery": "Allow using Mockery for testing (^1.2.3).", "orchestra/testbench-browser-kit": "Allow using legacy Laravel BrowserKit for testing (^4.0).", "orchestra/testbench-dusk": "Allow using Laravel Dusk for testing (^4.0).", @@ -1207,7 +1145,7 @@ "orchestral", "testing" ], - "time": "2020-01-29T22:59:50+00:00" + "time": "2020-04-11T10:37:21+00:00" }, { "name": "paragonie/random_compat", @@ -1410,41 +1348,38 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.4", + "version": "5.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "da3fd972d6bafd628114f7e7e036f45944b62e9c" + "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/da3fd972d6bafd628114f7e7e036f45944b62e9c", - "reference": "da3fd972d6bafd628114f7e7e036f45944b62e9c", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", + "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", "shasum": "" }, "require": { - "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", - "phpdocumentor/type-resolver": "~0.4 || ^1.0.0", - "webmozart/assert": "^1.0" + "ext-filter": "^7.1", + "php": "^7.2", + "phpdocumentor/reflection-common": "^2.0", + "phpdocumentor/type-resolver": "^1.0", + "webmozart/assert": "^1" }, "require-dev": { - "doctrine/instantiator": "^1.0.5", - "mockery/mockery": "^1.0", - "phpdocumentor/type-resolver": "0.4.*", - "phpunit/phpunit": "^6.4" + "doctrine/instantiator": "^1", + "mockery/mockery": "^1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.x-dev" + "dev-master": "5.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -1455,33 +1390,36 @@ { "name": "Mike van Riel", "email": "me@mikevanriel.com" + }, + { + "name": "Jaap van Otterdijk", + "email": "account@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2019-12-28T18:55:12+00:00" + "time": "2020-02-22T12:28:44+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.0.1", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9" + "reference": "7462d5f123dfc080dfdf26897032a6513644fc95" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", - "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/7462d5f123dfc080dfdf26897032a6513644fc95", + "reference": "7462d5f123dfc080dfdf26897032a6513644fc95", "shasum": "" }, "require": { - "php": "^7.1", + "php": "^7.2", "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "ext-tokenizer": "^7.1", - "mockery/mockery": "~1", - "phpunit/phpunit": "^7.0" + "ext-tokenizer": "^7.2", + "mockery/mockery": "~1" }, "type": "library", "extra": { @@ -1505,24 +1443,24 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2019-08-22T18:11:29+00:00" + "time": "2020-02-18T18:59:58+00:00" }, { "name": "phpoption/phpoption", - "version": "1.7.2", + "version": "1.7.3", "source": { "type": "git", "url": "https://github.com/schmittjoh/php-option.git", - "reference": "77f7c4d2e65413aff5b5a8cc8b3caf7a28d81959" + "reference": "4acfd6a4b33a509d8c88f50e5222f734b6aeebae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/77f7c4d2e65413aff5b5a8cc8b3caf7a28d81959", - "reference": "77f7c4d2e65413aff5b5a8cc8b3caf7a28d81959", + "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/4acfd6a4b33a509d8c88f50e5222f734b6aeebae", + "reference": "4acfd6a4b33a509d8c88f50e5222f734b6aeebae", "shasum": "" }, "require": { - "php": "^5.5.9 || ^7.0" + "php": "^5.5.9 || ^7.0 || ^8.0" }, "require-dev": { "bamarni/composer-bin-plugin": "^1.3", @@ -1560,20 +1498,20 @@ "php", "type" ], - "time": "2019-12-15T19:35:24+00:00" + "time": "2020-03-21T18:07:53+00:00" }, { "name": "phpspec/prophecy", - "version": "v1.10.2", + "version": "v1.10.3", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "b4400efc9d206e83138e2bb97ed7f5b14b831cd9" + "reference": "451c3cd1418cf640de218914901e51b064abb093" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/b4400efc9d206e83138e2bb97ed7f5b14b831cd9", - "reference": "b4400efc9d206e83138e2bb97ed7f5b14b831cd9", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/451c3cd1418cf640de218914901e51b064abb093", + "reference": "451c3cd1418cf640de218914901e51b064abb093", "shasum": "" }, "require": { @@ -1623,25 +1561,28 @@ "spy", "stub" ], - "time": "2020-01-20T15:57:02+00:00" + "time": "2020-03-05T15:02:03+00:00" }, { "name": "phpstan/phpstan", - "version": "0.12.8", + "version": "0.12.19", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "62a552602b7586d82826231f2fd4cbfe39fe0b1d" + "reference": "054f6d76b12ba9a6c13a5a8d5fcdf51219615f4d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/62a552602b7586d82826231f2fd4cbfe39fe0b1d", - "reference": "62a552602b7586d82826231f2fd4cbfe39fe0b1d", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/054f6d76b12ba9a6c13a5a8d5fcdf51219615f4d", + "reference": "054f6d76b12ba9a6c13a5a8d5fcdf51219615f4d", "shasum": "" }, "require": { "php": "^7.1" }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, "bin": [ "phpstan", "phpstan.phar" @@ -1662,44 +1603,45 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", - "time": "2020-01-26T23:36:48+00:00" + "time": "2020-04-19T20:35:10+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "7.0.10", + "version": "8.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f1884187926fbb755a9aaf0b3836ad3165b478bf" + "reference": "31e94ccc084025d6abee0585df533eb3a792b96a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f1884187926fbb755a9aaf0b3836ad3165b478bf", - "reference": "f1884187926fbb755a9aaf0b3836ad3165b478bf", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/31e94ccc084025d6abee0585df533eb3a792b96a", + "reference": "31e94ccc084025d6abee0585df533eb3a792b96a", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", - "php": "^7.2", - "phpunit/php-file-iterator": "^2.0.2", - "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.1.1", - "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^4.2.2", - "sebastian/version": "^2.0.1", + "php": "^7.3", + "phpunit/php-file-iterator": "^3.0", + "phpunit/php-text-template": "^2.0", + "phpunit/php-token-stream": "^4.0", + "sebastian/code-unit-reverse-lookup": "^2.0", + "sebastian/environment": "^5.0", + "sebastian/version": "^3.0", "theseer/tokenizer": "^1.1.3" }, "require-dev": { - "phpunit/phpunit": "^8.2.2" + "phpunit/phpunit": "^9.0" }, "suggest": { - "ext-xdebug": "^2.7.2" + "ext-pcov": "*", + "ext-xdebug": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "7.0-dev" + "dev-master": "8.0-dev" } }, "autoload": { @@ -1725,32 +1667,32 @@ "testing", "xunit" ], - "time": "2019-11-20T13:55:58+00:00" + "time": "2020-02-19T13:41:19+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "2.0.2", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "050bedf145a257b1ff02746c31894800e5122946" + "reference": "4ac5b3e13df14829daa60a2eb4fdd2f2b7d33cf4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/050bedf145a257b1ff02746c31894800e5122946", - "reference": "050bedf145a257b1ff02746c31894800e5122946", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/4ac5b3e13df14829daa60a2eb4fdd2f2b7d33cf4", + "reference": "4ac5b3e13df14829daa60a2eb4fdd2f2b7d33cf4", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.3" }, "require-dev": { - "phpunit/phpunit": "^7.1" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1775,26 +1717,84 @@ "filesystem", "iterator" ], - "time": "2018-09-13T20:33:42+00:00" + "time": "2020-04-18T05:02:12+00:00" + }, + { + "name": "phpunit/php-invoker", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "7579d5a1ba7f3ac11c80004d205877911315ae7a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/7579d5a1ba7f3ac11c80004d205877911315ae7a", + "reference": "7579d5a1ba7f3ac11c80004d205877911315ae7a", + "shasum": "" + }, + "require": { + "php": "^7.3" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^9.0" + }, + "suggest": { + "ext-pcntl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", + "keywords": [ + "process" + ], + "time": "2020-02-07T06:06:11+00:00" }, { "name": "phpunit/php-text-template", - "version": "1.2.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + "reference": "526dc996cc0ebdfa428cd2dfccd79b7b53fee346" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/526dc996cc0ebdfa428cd2dfccd79b7b53fee346", + "reference": "526dc996cc0ebdfa428cd2dfccd79b7b53fee346", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.3" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, "autoload": { "classmap": [ "src/" @@ -1816,32 +1816,32 @@ "keywords": [ "template" ], - "time": "2015-06-21T13:50:34+00:00" + "time": "2020-02-01T07:43:44+00:00" }, { "name": "phpunit/php-timer", - "version": "2.1.2", + "version": "3.1.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "1038454804406b0b5f5f520358e78c1c2f71501e" + "reference": "dc9368fae6ef2ffa57eba80a7410bcef81df6258" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/1038454804406b0b5f5f520358e78c1c2f71501e", - "reference": "1038454804406b0b5f5f520358e78c1c2f71501e", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/dc9368fae6ef2ffa57eba80a7410bcef81df6258", + "reference": "dc9368fae6ef2ffa57eba80a7410bcef81df6258", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.3" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -1865,33 +1865,33 @@ "keywords": [ "timer" ], - "time": "2019-06-07T04:22:29+00:00" + "time": "2020-04-20T06:00:37+00:00" }, { "name": "phpunit/php-token-stream", - "version": "3.1.1", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff" + "reference": "b2560a0c33f7710e4d7f8780964193e8e8f8effe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/995192df77f63a59e47f025390d2d1fdf8f425ff", - "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/b2560a0c33f7710e4d7f8780964193e8e8f8effe", + "reference": "b2560a0c33f7710e4d7f8780964193e8e8f8effe", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": "^7.1" + "php": "^7.3" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1914,20 +1914,20 @@ "keywords": [ "tokenizer" ], - "time": "2019-09-17T06:23:10+00:00" + "time": "2020-02-07T06:19:00+00:00" }, { "name": "phpunit/phpunit", - "version": "8.5.2", + "version": "9.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "018b6ac3c8ab20916db85fa91bf6465acb64d1e0" + "reference": "a74780472172957a65cb5999a597e8c0878cf39c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/018b6ac3c8ab20916db85fa91bf6465acb64d1e0", - "reference": "018b6ac3c8ab20916db85fa91bf6465acb64d1e0", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a74780472172957a65cb5999a597e8c0878cf39c", + "reference": "a74780472172957a65cb5999a597e8c0878cf39c", "shasum": "" }, "require": { @@ -1941,29 +1941,31 @@ "myclabs/deep-copy": "^1.9.1", "phar-io/manifest": "^1.0.3", "phar-io/version": "^2.0.1", - "php": "^7.2", + "php": "^7.3", "phpspec/prophecy": "^1.8.1", - "phpunit/php-code-coverage": "^7.0.7", - "phpunit/php-file-iterator": "^2.0.2", - "phpunit/php-text-template": "^1.2.1", - "phpunit/php-timer": "^2.1.2", - "sebastian/comparator": "^3.0.2", - "sebastian/diff": "^3.0.2", - "sebastian/environment": "^4.2.2", - "sebastian/exporter": "^3.1.1", - "sebastian/global-state": "^3.0.0", - "sebastian/object-enumerator": "^3.0.3", - "sebastian/resource-operations": "^2.0.1", - "sebastian/type": "^1.1.3", - "sebastian/version": "^2.0.1" + "phpunit/php-code-coverage": "^8.0.1", + "phpunit/php-file-iterator": "^3.0", + "phpunit/php-invoker": "^3.0", + "phpunit/php-text-template": "^2.0", + "phpunit/php-timer": "^3.1.4", + "sebastian/code-unit": "^1.0", + "sebastian/comparator": "^4.0", + "sebastian/diff": "^4.0", + "sebastian/environment": "^5.0.1", + "sebastian/exporter": "^4.0", + "sebastian/global-state": "^4.0", + "sebastian/object-enumerator": "^4.0", + "sebastian/resource-operations": "^3.0", + "sebastian/type": "^2.0", + "sebastian/version": "^3.0" }, "require-dev": { - "ext-pdo": "*" + "ext-pdo": "*", + "phpspec/prophecy-phpunit": "^2.0" }, "suggest": { "ext-soap": "*", - "ext-xdebug": "*", - "phpunit/php-invoker": "^2.0.0" + "ext-xdebug": "*" }, "bin": [ "phpunit" @@ -1971,12 +1973,15 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "8.5-dev" + "dev-master": "9.1-dev" } }, "autoload": { "classmap": [ "src/" + ], + "files": [ + "src/Framework/Assert/Functions.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -1997,7 +2002,7 @@ "testing", "xunit" ], - "time": "2020-01-08T08:49:49+00:00" + "time": "2020-04-23T04:42:05+00:00" }, { "name": "psr/container", @@ -2050,16 +2055,16 @@ }, { "name": "psr/log", - "version": "1.1.2", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801" + "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/446d54b4cb6bf489fc9d75f55843658e6f25d801", - "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801", + "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc", + "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc", "shasum": "" }, "require": { @@ -2093,7 +2098,7 @@ "psr", "psr-3" ], - "time": "2019-11-01T11:05:21+00:00" + "time": "2020-03-23T09:12:05+00:00" }, { "name": "psr/simple-cache", @@ -2145,16 +2150,16 @@ }, { "name": "ramsey/uuid", - "version": "3.9.2", + "version": "3.9.3", "source": { "type": "git", "url": "https://github.com/ramsey/uuid.git", - "reference": "7779489a47d443f845271badbdcedfe4df8e06fb" + "reference": "7e1633a6964b48589b142d60542f9ed31bd37a92" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/uuid/zipball/7779489a47d443f845271badbdcedfe4df8e06fb", - "reference": "7779489a47d443f845271badbdcedfe4df8e06fb", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/7e1633a6964b48589b142d60542f9ed31bd37a92", + "reference": "7e1633a6964b48589b142d60542f9ed31bd37a92", "shasum": "" }, "require": { @@ -2228,32 +2233,78 @@ "identifier", "uuid" ], - "time": "2019-12-17T08:18:51+00:00" + "time": "2020-02-21T04:36:14+00:00" + }, + { + "name": "sebastian/code-unit", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "8d8f09bd47c75159921e6e84fdef146343962866" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/8d8f09bd47c75159921e6e84fdef146343962866", + "reference": "8d8f09bd47c75159921e6e84fdef146343962866", + "shasum": "" + }, + "require": { + "php": "^7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "time": "2020-03-30T11:59:20+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + "reference": "5b5dbe0044085ac41df47e79d34911a15b96d82e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/5b5dbe0044085ac41df47e79d34911a15b96d82e", + "reference": "5b5dbe0044085ac41df47e79d34911a15b96d82e", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": "^7.3" }, "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.0" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -2273,34 +2324,34 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2017-03-04T06:30:41+00:00" + "time": "2020-02-07T06:20:13+00:00" }, { "name": "sebastian/comparator", - "version": "3.0.2", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" + "reference": "85b3435da967696ed618ff745f32be3ff4a2b8e8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", - "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/85b3435da967696ed618ff745f32be3ff4a2b8e8", + "reference": "85b3435da967696ed618ff745f32be3ff4a2b8e8", "shasum": "" }, "require": { - "php": "^7.1", - "sebastian/diff": "^3.0", - "sebastian/exporter": "^3.1" + "php": "^7.3", + "sebastian/diff": "^4.0", + "sebastian/exporter": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^7.1" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -2313,6 +2364,10 @@ "BSD-3-Clause" ], "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, { "name": "Jeff Welch", "email": "whatthejeff@gmail.com" @@ -2324,10 +2379,6 @@ { "name": "Bernhard Schussek", "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" } ], "description": "Provides the functionality to compare PHP values for equality", @@ -2337,33 +2388,33 @@ "compare", "equality" ], - "time": "2018-07-12T15:12:46+00:00" + "time": "2020-02-07T06:08:51+00:00" }, { "name": "sebastian/diff", - "version": "3.0.2", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29" + "reference": "c0c26c9188b538bfa985ae10c9f05d278f12060d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/720fcc7e9b5cf384ea68d9d930d480907a0c1a29", - "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/c0c26c9188b538bfa985ae10c9f05d278f12060d", + "reference": "c0c26c9188b538bfa985ae10c9f05d278f12060d", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.3" }, "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.0", - "symfony/process": "^2 || ^3.3 || ^4" + "phpunit/phpunit": "^9.0", + "symfony/process": "^4 || ^5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -2376,13 +2427,13 @@ "BSD-3-Clause" ], "authors": [ - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - }, { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" } ], "description": "Diff implementation", @@ -2393,27 +2444,27 @@ "unidiff", "unified diff" ], - "time": "2019-02-04T06:01:07+00:00" + "time": "2020-02-07T06:09:38+00:00" }, { "name": "sebastian/environment", - "version": "4.2.3", + "version": "5.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368" + "reference": "c753f04d68cd489b6973cf9b4e505e191af3b05c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/464c90d7bdf5ad4e8a6aea15c091fec0603d4368", - "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/c753f04d68cd489b6973cf9b4e505e191af3b05c", + "reference": "c753f04d68cd489b6973cf9b4e505e191af3b05c", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.3" }, "require-dev": { - "phpunit/phpunit": "^7.5" + "phpunit/phpunit": "^9.0" }, "suggest": { "ext-posix": "*" @@ -2421,7 +2472,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -2446,34 +2497,34 @@ "environment", "hhvm" ], - "time": "2019-11-20T08:46:58+00:00" + "time": "2020-04-14T13:36:52+00:00" }, { "name": "sebastian/exporter", - "version": "3.1.2", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" + "reference": "80c26562e964016538f832f305b2286e1ec29566" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", - "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/80c26562e964016538f832f305b2286e1ec29566", + "reference": "80c26562e964016538f832f305b2286e1ec29566", "shasum": "" }, "require": { - "php": "^7.0", - "sebastian/recursion-context": "^3.0" + "php": "^7.3", + "sebastian/recursion-context": "^4.0" }, "require-dev": { "ext-mbstring": "*", - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1.x-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -2513,30 +2564,30 @@ "export", "exporter" ], - "time": "2019-09-14T09:02:43+00:00" + "time": "2020-02-07T06:10:52+00:00" }, { "name": "sebastian/global-state", - "version": "3.0.0", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4" + "reference": "bdb1e7c79e592b8c82cb1699be3c8743119b8a72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", - "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bdb1e7c79e592b8c82cb1699be3c8743119b8a72", + "reference": "bdb1e7c79e592b8c82cb1699be3c8743119b8a72", "shasum": "" }, "require": { - "php": "^7.2", - "sebastian/object-reflector": "^1.1.1", - "sebastian/recursion-context": "^3.0" + "php": "^7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" }, "require-dev": { "ext-dom": "*", - "phpunit/phpunit": "^8.0" + "phpunit/phpunit": "^9.0" }, "suggest": { "ext-uopz": "*" @@ -2544,7 +2595,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -2567,34 +2618,34 @@ "keywords": [ "global state" ], - "time": "2019-02-01T05:30:01+00:00" + "time": "2020-02-07T06:11:37+00:00" }, { "name": "sebastian/object-enumerator", - "version": "3.0.3", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" + "reference": "e67516b175550abad905dc952f43285957ef4363" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", - "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/e67516b175550abad905dc952f43285957ef4363", + "reference": "e67516b175550abad905dc952f43285957ef4363", "shasum": "" }, "require": { - "php": "^7.0", - "sebastian/object-reflector": "^1.1.1", - "sebastian/recursion-context": "^3.0" + "php": "^7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -2614,32 +2665,32 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-08-03T12:35:26+00:00" + "time": "2020-02-07T06:12:23+00:00" }, { "name": "sebastian/object-reflector", - "version": "1.1.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-reflector.git", - "reference": "773f97c67f28de00d397be301821b06708fca0be" + "reference": "f4fd0835cabb0d4a6546d9fe291e5740037aa1e7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", - "reference": "773f97c67f28de00d397be301821b06708fca0be", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/f4fd0835cabb0d4a6546d9fe291e5740037aa1e7", + "reference": "f4fd0835cabb0d4a6546d9fe291e5740037aa1e7", "shasum": "" }, "require": { - "php": "^7.0" + "php": "^7.3" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -2659,32 +2710,32 @@ ], "description": "Allows reflection of object attributes, including inherited and non-public ones", "homepage": "https://github.com/sebastianbergmann/object-reflector/", - "time": "2017-03-29T09:07:27+00:00" + "time": "2020-02-07T06:19:40+00:00" }, { "name": "sebastian/recursion-context", - "version": "3.0.0", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" + "reference": "cdd86616411fc3062368b720b0425de10bd3d579" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", - "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/cdd86616411fc3062368b720b0425de10bd3d579", + "reference": "cdd86616411fc3062368b720b0425de10bd3d579", "shasum": "" }, "require": { - "php": "^7.0" + "php": "^7.3" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -2697,14 +2748,14 @@ "BSD-3-Clause" ], "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, { "name": "Adam Harvey", "email": "aharvey@php.net" @@ -2712,29 +2763,32 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2017-03-03T06:23:57+00:00" + "time": "2020-02-07T06:18:20+00:00" }, { "name": "sebastian/resource-operations", - "version": "2.0.1", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9" + "reference": "8c98bf0dfa1f9256d0468b9803a1e1df31b6fa98" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/4d7a795d35b889bf80a0cc04e08d77cedfa917a9", - "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/8c98bf0dfa1f9256d0468b9803a1e1df31b6fa98", + "reference": "8c98bf0dfa1f9256d0468b9803a1e1df31b6fa98", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -2754,32 +2808,32 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2018-10-04T04:07:39+00:00" + "time": "2020-02-07T06:13:02+00:00" }, { "name": "sebastian/type", - "version": "1.1.3", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3" + "reference": "9e8f42f740afdea51f5f4e8cec2035580e797ee1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/3aaaa15fa71d27650d62a948be022fe3b48541a3", - "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/9e8f42f740afdea51f5f4e8cec2035580e797ee1", + "reference": "9e8f42f740afdea51f5f4e8cec2035580e797ee1", "shasum": "" }, "require": { - "php": "^7.2" + "php": "^7.3" }, "require-dev": { - "phpunit/phpunit": "^8.2" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -2800,29 +2854,29 @@ ], "description": "Collection of value objects that represent the types of the PHP type system", "homepage": "https://github.com/sebastianbergmann/type", - "time": "2019-07-02T08:10:15+00:00" + "time": "2020-02-07T06:13:43+00:00" }, { "name": "sebastian/version", - "version": "2.0.1", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + "reference": "0411bde656dce64202b39c2f4473993a9081d39e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/0411bde656dce64202b39c2f4473993a9081d39e", + "reference": "0411bde656dce64202b39c2f4473993a9081d39e", "shasum": "" }, "require": { - "php": ">=5.6" + "php": "^7.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -2843,7 +2897,7 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-10-03T07:35:21+00:00" + "time": "2020-01-21T06:36:37+00:00" }, { "name": "swiftmailer/swiftmailer", @@ -2909,16 +2963,16 @@ }, { "name": "symfony/console", - "version": "v4.4.3", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "e9ee09d087e2c88eaf6e5fc0f5c574f64d100e4f" + "reference": "10bb3ee3c97308869d53b3e3d03f6ac23ff985f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/e9ee09d087e2c88eaf6e5fc0f5c574f64d100e4f", - "reference": "e9ee09d087e2c88eaf6e5fc0f5c574f64d100e4f", + "url": "https://api.github.com/repos/symfony/console/zipball/10bb3ee3c97308869d53b3e3d03f6ac23ff985f7", + "reference": "10bb3ee3c97308869d53b3e3d03f6ac23ff985f7", "shasum": "" }, "require": { @@ -2981,20 +3035,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2020-01-10T21:54:01+00:00" + "time": "2020-03-30T11:41:10+00:00" }, { "name": "symfony/css-selector", - "version": "v5.0.3", + "version": "v5.0.7", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "ff60c90cb7950b592ebc84ad1289d0345bf24f9f" + "reference": "5f8d5271303dad260692ba73dfa21777d38e124e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/ff60c90cb7950b592ebc84ad1289d0345bf24f9f", - "reference": "ff60c90cb7950b592ebc84ad1289d0345bf24f9f", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/5f8d5271303dad260692ba73dfa21777d38e124e", + "reference": "5f8d5271303dad260692ba73dfa21777d38e124e", "shasum": "" }, "require": { @@ -3034,20 +3088,20 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2020-01-04T14:08:26+00:00" + "time": "2020-03-27T16:56:45+00:00" }, { "name": "symfony/debug", - "version": "v4.4.3", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "89c3fd5c299b940333bc6fe9f1b8db1b0912c759" + "reference": "346636d2cae417992ecfd761979b2ab98b339a45" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/89c3fd5c299b940333bc6fe9f1b8db1b0912c759", - "reference": "89c3fd5c299b940333bc6fe9f1b8db1b0912c759", + "url": "https://api.github.com/repos/symfony/debug/zipball/346636d2cae417992ecfd761979b2ab98b339a45", + "reference": "346636d2cae417992ecfd761979b2ab98b339a45", "shasum": "" }, "require": { @@ -3090,26 +3144,26 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2020-01-08T17:29:02+00:00" + "time": "2020-03-27T16:54:36+00:00" }, { "name": "symfony/error-handler", - "version": "v4.4.3", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/error-handler.git", - "reference": "a59789092e40ad08465dc2cdc55651be503d0d5a" + "reference": "7e9828fc98aa1cf27b422fe478a84f5b0abb7358" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/error-handler/zipball/a59789092e40ad08465dc2cdc55651be503d0d5a", - "reference": "a59789092e40ad08465dc2cdc55651be503d0d5a", + "url": "https://api.github.com/repos/symfony/error-handler/zipball/7e9828fc98aa1cf27b422fe478a84f5b0abb7358", + "reference": "7e9828fc98aa1cf27b422fe478a84f5b0abb7358", "shasum": "" }, "require": { "php": "^7.1.3", "psr/log": "~1.0", - "symfony/debug": "^4.4", + "symfony/debug": "^4.4.5", "symfony/var-dumper": "^4.4|^5.0" }, "require-dev": { @@ -3146,20 +3200,20 @@ ], "description": "Symfony ErrorHandler Component", "homepage": "https://symfony.com", - "time": "2020-01-08T17:29:02+00:00" + "time": "2020-03-30T14:07:33+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v4.4.3", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "9e3de195e5bc301704dd6915df55892f6dfc208b" + "reference": "abc8e3618bfdb55e44c8c6a00abd333f831bbfed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9e3de195e5bc301704dd6915df55892f6dfc208b", - "reference": "9e3de195e5bc301704dd6915df55892f6dfc208b", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/abc8e3618bfdb55e44c8c6a00abd333f831bbfed", + "reference": "abc8e3618bfdb55e44c8c6a00abd333f831bbfed", "shasum": "" }, "require": { @@ -3216,7 +3270,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2020-01-10T21:54:01+00:00" + "time": "2020-03-27T16:54:36+00:00" }, { "name": "symfony/event-dispatcher-contracts", @@ -3278,16 +3332,16 @@ }, { "name": "symfony/finder", - "version": "v4.4.3", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "3a50be43515590faf812fbd7708200aabc327ec3" + "reference": "5729f943f9854c5781984ed4907bbb817735776b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/3a50be43515590faf812fbd7708200aabc327ec3", - "reference": "3a50be43515590faf812fbd7708200aabc327ec3", + "url": "https://api.github.com/repos/symfony/finder/zipball/5729f943f9854c5781984ed4907bbb817735776b", + "reference": "5729f943f9854c5781984ed4907bbb817735776b", "shasum": "" }, "require": { @@ -3323,20 +3377,20 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2020-01-04T13:00:46+00:00" + "time": "2020-03-27T16:54:36+00:00" }, { "name": "symfony/http-foundation", - "version": "v4.4.3", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "c33998709f3fe9b8e27e0277535b07fbf6fde37a" + "reference": "62f92509c9abfd1f73e17b8cf1b72c0bdac6611b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/c33998709f3fe9b8e27e0277535b07fbf6fde37a", - "reference": "c33998709f3fe9b8e27e0277535b07fbf6fde37a", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/62f92509c9abfd1f73e17b8cf1b72c0bdac6611b", + "reference": "62f92509c9abfd1f73e17b8cf1b72c0bdac6611b", "shasum": "" }, "require": { @@ -3378,20 +3432,20 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2020-01-04T13:00:46+00:00" + "time": "2020-03-30T14:07:33+00:00" }, { "name": "symfony/http-kernel", - "version": "v4.4.3", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "16f2aa3c54b08483fba5375938f60b1ff83b6bd2" + "reference": "f356a489e51856b99908005eb7f2c51a1dfc95dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/16f2aa3c54b08483fba5375938f60b1ff83b6bd2", - "reference": "16f2aa3c54b08483fba5375938f60b1ff83b6bd2", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/f356a489e51856b99908005eb7f2c51a1dfc95dc", + "reference": "f356a489e51856b99908005eb7f2c51a1dfc95dc", "shasum": "" }, "require": { @@ -3468,20 +3522,20 @@ ], "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", - "time": "2020-01-21T13:23:17+00:00" + "time": "2020-03-30T14:59:15+00:00" }, { "name": "symfony/mime", - "version": "v5.0.3", + "version": "v5.0.7", "source": { "type": "git", "url": "https://github.com/symfony/mime.git", - "reference": "2a3c7fee1f1a0961fa9cf360d5da553d05095e59" + "reference": "481b7d6da88922fb1e0d86a943987722b08f3955" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/mime/zipball/2a3c7fee1f1a0961fa9cf360d5da553d05095e59", - "reference": "2a3c7fee1f1a0961fa9cf360d5da553d05095e59", + "url": "https://api.github.com/repos/symfony/mime/zipball/481b7d6da88922fb1e0d86a943987722b08f3955", + "reference": "481b7d6da88922fb1e0d86a943987722b08f3955", "shasum": "" }, "require": { @@ -3530,20 +3584,20 @@ "mime", "mime-type" ], - "time": "2020-01-04T14:08:26+00:00" + "time": "2020-03-27T16:56:45+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.13.1", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3" + "reference": "4719fa9c18b0464d399f1a63bf624b42b6fa8d14" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", - "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/4719fa9c18b0464d399f1a63bf624b42b6fa8d14", + "reference": "4719fa9c18b0464d399f1a63bf624b42b6fa8d14", "shasum": "" }, "require": { @@ -3555,7 +3609,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.13-dev" + "dev-master": "1.15-dev" } }, "autoload": { @@ -3588,20 +3642,20 @@ "polyfill", "portable" ], - "time": "2019-11-27T13:56:44+00:00" + "time": "2020-02-27T09:26:54+00:00" }, { "name": "symfony/polyfill-iconv", - "version": "v1.13.1", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-iconv.git", - "reference": "a019efccc03f1a335af6b4f20c30f5ea8060be36" + "reference": "ad6d62792bfbcfc385dd34b424d4fcf9712a32c8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/a019efccc03f1a335af6b4f20c30f5ea8060be36", - "reference": "a019efccc03f1a335af6b4f20c30f5ea8060be36", + "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/ad6d62792bfbcfc385dd34b424d4fcf9712a32c8", + "reference": "ad6d62792bfbcfc385dd34b424d4fcf9712a32c8", "shasum": "" }, "require": { @@ -3613,7 +3667,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.13-dev" + "dev-master": "1.15-dev" } }, "autoload": { @@ -3647,26 +3701,26 @@ "portable", "shim" ], - "time": "2019-11-27T13:56:44+00:00" + "time": "2020-03-09T19:04:49+00:00" }, { "name": "symfony/polyfill-intl-idn", - "version": "v1.13.1", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "6f9c239e61e1b0c9229a28ff89a812dc449c3d46" + "reference": "47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/6f9c239e61e1b0c9229a28ff89a812dc449c3d46", - "reference": "6f9c239e61e1b0c9229a28ff89a812dc449c3d46", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf", + "reference": "47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf", "shasum": "" }, "require": { "php": ">=5.3.3", "symfony/polyfill-mbstring": "^1.3", - "symfony/polyfill-php72": "^1.9" + "symfony/polyfill-php72": "^1.10" }, "suggest": { "ext-intl": "For best performance" @@ -3674,7 +3728,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.13-dev" + "dev-master": "1.15-dev" } }, "autoload": { @@ -3709,20 +3763,20 @@ "portable", "shim" ], - "time": "2019-11-27T13:56:44+00:00" + "time": "2020-03-09T19:04:49+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.13.1", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "7b4aab9743c30be783b73de055d24a39cf4b954f" + "reference": "81ffd3a9c6d707be22e3012b827de1c9775fc5ac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7b4aab9743c30be783b73de055d24a39cf4b954f", - "reference": "7b4aab9743c30be783b73de055d24a39cf4b954f", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/81ffd3a9c6d707be22e3012b827de1c9775fc5ac", + "reference": "81ffd3a9c6d707be22e3012b827de1c9775fc5ac", "shasum": "" }, "require": { @@ -3734,7 +3788,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.13-dev" + "dev-master": "1.15-dev" } }, "autoload": { @@ -3768,20 +3822,20 @@ "portable", "shim" ], - "time": "2019-11-27T14:18:11+00:00" + "time": "2020-03-09T19:04:49+00:00" }, { "name": "symfony/polyfill-php72", - "version": "v1.13.1", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php72.git", - "reference": "66fea50f6cb37a35eea048d75a7d99a45b586038" + "reference": "37b0976c78b94856543260ce09b460a7bc852747" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/66fea50f6cb37a35eea048d75a7d99a45b586038", - "reference": "66fea50f6cb37a35eea048d75a7d99a45b586038", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/37b0976c78b94856543260ce09b460a7bc852747", + "reference": "37b0976c78b94856543260ce09b460a7bc852747", "shasum": "" }, "require": { @@ -3790,7 +3844,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.13-dev" + "dev-master": "1.15-dev" } }, "autoload": { @@ -3823,20 +3877,20 @@ "portable", "shim" ], - "time": "2019-11-27T13:56:44+00:00" + "time": "2020-02-27T09:26:54+00:00" }, { "name": "symfony/polyfill-php73", - "version": "v1.13.1", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "4b0e2222c55a25b4541305a053013d5647d3a25f" + "reference": "0f27e9f464ea3da33cbe7ca3bdf4eb66def9d0f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/4b0e2222c55a25b4541305a053013d5647d3a25f", - "reference": "4b0e2222c55a25b4541305a053013d5647d3a25f", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/0f27e9f464ea3da33cbe7ca3bdf4eb66def9d0f7", + "reference": "0f27e9f464ea3da33cbe7ca3bdf4eb66def9d0f7", "shasum": "" }, "require": { @@ -3845,7 +3899,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.13-dev" + "dev-master": "1.15-dev" } }, "autoload": { @@ -3881,20 +3935,20 @@ "portable", "shim" ], - "time": "2019-11-27T16:25:15+00:00" + "time": "2020-02-27T09:26:54+00:00" }, { "name": "symfony/process", - "version": "v4.4.3", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "f5697ab4cb14a5deed7473819e63141bf5352c36" + "reference": "3e40e87a20eaf83a1db825e1fa5097ae89042db3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/f5697ab4cb14a5deed7473819e63141bf5352c36", - "reference": "f5697ab4cb14a5deed7473819e63141bf5352c36", + "url": "https://api.github.com/repos/symfony/process/zipball/3e40e87a20eaf83a1db825e1fa5097ae89042db3", + "reference": "3e40e87a20eaf83a1db825e1fa5097ae89042db3", "shasum": "" }, "require": { @@ -3930,20 +3984,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2020-01-09T09:50:08+00:00" + "time": "2020-03-27T16:54:36+00:00" }, { "name": "symfony/routing", - "version": "v4.4.3", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/routing.git", - "reference": "7bf4e38573728e317b926ca4482ad30470d0e86a" + "reference": "0f562fa613e288d7dbae6c63abbc9b33ed75a8f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/routing/zipball/7bf4e38573728e317b926ca4482ad30470d0e86a", - "reference": "7bf4e38573728e317b926ca4482ad30470d0e86a", + "url": "https://api.github.com/repos/symfony/routing/zipball/0f562fa613e288d7dbae6c63abbc9b33ed75a8f8", + "reference": "0f562fa613e288d7dbae6c63abbc9b33ed75a8f8", "shasum": "" }, "require": { @@ -4006,7 +4060,7 @@ "uri", "url" ], - "time": "2020-01-08T17:29:02+00:00" + "time": "2020-03-30T11:41:10+00:00" }, { "name": "symfony/service-contracts", @@ -4068,16 +4122,16 @@ }, { "name": "symfony/translation", - "version": "v4.4.3", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "f5d2ac46930238b30a9c2f1b17c905f3697d808c" + "reference": "4e54d336f2eca5facad449d0b0118bb449375b76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/f5d2ac46930238b30a9c2f1b17c905f3697d808c", - "reference": "f5d2ac46930238b30a9c2f1b17c905f3697d808c", + "url": "https://api.github.com/repos/symfony/translation/zipball/4e54d336f2eca5facad449d0b0118bb449375b76", + "reference": "4e54d336f2eca5facad449d0b0118bb449375b76", "shasum": "" }, "require": { @@ -4140,7 +4194,7 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2020-01-15T13:29:06+00:00" + "time": "2020-03-27T16:54:36+00:00" }, { "name": "symfony/translation-contracts", @@ -4201,16 +4255,16 @@ }, { "name": "symfony/var-dumper", - "version": "v4.4.3", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "7cfa470bc3b1887a7b2a47c0a702a84ad614fa92" + "reference": "5a0c2d93006131a36cf6f767d10e2ca8333b0d4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/7cfa470bc3b1887a7b2a47c0a702a84ad614fa92", - "reference": "7cfa470bc3b1887a7b2a47c0a702a84ad614fa92", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/5a0c2d93006131a36cf6f767d10e2ca8333b0d4a", + "reference": "5a0c2d93006131a36cf6f767d10e2ca8333b0d4a", "shasum": "" }, "require": { @@ -4273,7 +4327,7 @@ "debug", "dump" ], - "time": "2020-01-04T13:00:46+00:00" + "time": "2020-03-27T16:54:36+00:00" }, { "name": "theseer/tokenizer", @@ -4366,16 +4420,16 @@ }, { "name": "vlucas/phpdotenv", - "version": "v3.6.0", + "version": "v3.6.3", "source": { "type": "git", "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "1bdf24f065975594f6a117f0f1f6cabf1333b156" + "reference": "1b3103013797f04521c6cae5560f604649484066" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/1bdf24f065975594f6a117f0f1f6cabf1333b156", - "reference": "1bdf24f065975594f6a117f0f1f6cabf1333b156", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/1b3103013797f04521c6cae5560f604649484066", + "reference": "1b3103013797f04521c6cae5560f604649484066", "shasum": "" }, "require": { @@ -4384,8 +4438,14 @@ "symfony/polyfill-ctype": "^1.9" }, "require-dev": { + "ext-filter": "*", + "ext-pcre": "*", "phpunit/phpunit": "^4.8.35 || ^5.0 || ^6.0 || ^7.0" }, + "suggest": { + "ext-filter": "Required to use the boolean validator.", + "ext-pcre": "Required to use most of the library." + }, "type": "library", "extra": { "branch-alias": { @@ -4419,20 +4479,20 @@ "env", "environment" ], - "time": "2019-09-10T21:37:39+00:00" + "time": "2020-04-12T15:18:03+00:00" }, { "name": "webmozart/assert", - "version": "1.6.0", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "573381c0a64f155a0d9a23f4b0c797194805b925" + "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/573381c0a64f155a0d9a23f4b0c797194805b925", - "reference": "573381c0a64f155a0d9a23f4b0c797194805b925", + "url": "https://api.github.com/repos/webmozart/assert/zipball/ab2cb0b3b559010b75981b1bdce728da3ee90ad6", + "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6", "shasum": "" }, "require": { @@ -4440,7 +4500,7 @@ "symfony/polyfill-ctype": "^1.8" }, "conflict": { - "vimeo/psalm": "<3.6.0" + "vimeo/psalm": "<3.9.1" }, "require-dev": { "phpunit/phpunit": "^4.8.36 || ^7.5.13" @@ -4467,7 +4527,7 @@ "check", "validate" ], - "time": "2019-11-24T13:36:37+00:00" + "time": "2020-04-18T12:12:48+00:00" } ], "aliases": [], diff --git a/src/ControlDBServiceProvider.php b/src/ControlDBServiceProvider.php index 09b5712..fd931d8 100644 --- a/src/ControlDBServiceProvider.php +++ b/src/ControlDBServiceProvider.php @@ -330,13 +330,13 @@ private function setupObservers() Observe::attach(UserTagCategoryRepositoryContract::class, UserTagCategoryObserverClearCache::class); Observe::attach(PositionTagCategoryRepositoryContract::class, PositionTagCategoryObserverClearCache::class); - Observe::attach(UserGroup::class, UserGroupObserverClearCache::class); - Observe::attach(UserRole::class, UserRoleObserverClearCache::class); + Observe::attach(UserGroupContract::class, UserGroupObserverClearCache::class); + Observe::attach(UserRoleContract::class, UserRoleObserverClearCache::class); - Observe::attach(GroupGroupTag::class, GroupGroupTagObserverClearCache::class); - Observe::attach(UserUserTag::class, UserUserTagObserverClearCache::class); - Observe::attach(RoleRoleTag::class, RoleRoleTagObserverClearCache::class); - Observe::attach(PositionPositionTag::class, PositionPositionTagObserverClearCache::class); + Observe::attach(GroupGroupTagContract::class, GroupGroupTagObserverClearCache::class); + Observe::attach(UserUserTagContract::class, UserUserTagObserverClearCache::class); + Observe::attach(RoleRoleTagContract::class, RoleRoleTagObserverClearCache::class); + Observe::attach(PositionPositionTagContract::class, PositionPositionTagObserverClearCache::class); Observe::attach(GroupTagRepositoryContract::class, GroupTagObserverCascadeDelete::class); Observe::attach(UserTagRepositoryContract::class, UserTagObserverCascadeDelete::class); From a80ebd0cfec117447dcb87125eb3bb8db1c4e0a5 Mon Sep 17 00:00:00 2001 From: Toby Twigger Date: Fri, 24 Apr 2020 19:09:48 +0100 Subject: [PATCH 3/7] Update bug --- src/Observers/RoleObserverClearCache.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Observers/RoleObserverClearCache.php b/src/Observers/RoleObserverClearCache.php index f53ce8f..c784d16 100644 --- a/src/Observers/RoleObserverClearCache.php +++ b/src/Observers/RoleObserverClearCache.php @@ -23,6 +23,8 @@ public function create(RoleModel $roleModel) { $this->cache->forget(RoleCache::class . '@count'); $this->cache->forget(RoleCache::class . '@getByDataProviderId:' . $roleModel->dataProviderId()); + $this->cache->forget(RoleCache::class . '@allThroughGroup:' . $roleModel->groupId()); + $this->cache->forget(RoleCache::class . '@allThroughPosition:' . $roleModel->positionId()); } public function delete(RoleModel $role) From 292fffa68aeb1e14835673a5e92db082b64627ac Mon Sep 17 00:00:00 2001 From: Toby Twigger Date: Mon, 27 Apr 2020 13:39:00 +0100 Subject: [PATCH 4/7] Tests for new work --- composer.json | 3 +- composer.lock | 50 ++++- .../Framework/ObserverStore.php | 5 +- tests/Integration/Cache/DataGroupTest.php | 97 +++++++++ tests/Integration/Cache/DataPositionTest.php | 97 +++++++++ tests/Integration/Cache/DataRoleTest.php | 97 +++++++++ tests/Integration/Cache/DataUserTest.php | 97 +++++++++ tests/Integration/Cache/GroupTest.php | 150 +++++++++++++ .../Cache/Pivots/Tags/GroupGroupTagTest.php | 104 +++++++++ .../Pivots/Tags/PositionPositionTagTest.php | 104 +++++++++ .../Cache/Pivots/Tags/RoleRoleTagTest.php | 104 +++++++++ .../Cache/Pivots/Tags/UserUserTagTest.php | 104 +++++++++ .../Cache/Pivots/UserGroupTest.php | 107 ++++++++++ .../Integration/Cache/Pivots/UserRoleTest.php | 107 ++++++++++ tests/Integration/Cache/PositionTest.php | 150 +++++++++++++ tests/Integration/Cache/RoleTest.php | 198 ++++++++++++++++++ .../Cache/Tags/GroupTagCategoryTest.php | 117 +++++++++++ tests/Integration/Cache/Tags/GroupTagTest.php | 144 +++++++++++++ .../Cache/Tags/PositionTagCategoryTest.php | 117 +++++++++++ .../Cache/Tags/PositionTagTest.php | 144 +++++++++++++ .../Cache/Tags/RoleTagCategoryTest.php | 117 +++++++++++ tests/Integration/Cache/Tags/RoleTagTest.php | 144 +++++++++++++ .../Cache/Tags/UserTagCategoryTest.php | 117 +++++++++++ tests/Integration/Cache/Tags/UserTagTest.php | 144 +++++++++++++ tests/Integration/Cache/UserTest.php | 135 ++++++++++++ tests/TestCase.php | 4 +- .../Framework/NotifierTest.php | 74 +++++++ .../NotifyObservers/Framework/ObserveTest.php | 22 ++ .../Framework/ObserverStoreTest.php | 88 ++++++++ .../Tags/GroupTagCategoryTest.php | 54 +++++ tests/Unit/Repositories/Tags/GroupTagTest.php | 80 ++++++- .../Tags/PositionTagCategoryTest.php | 55 +++++ .../Repositories/Tags/PositionTagTest.php | 62 ++++++ .../Repositories/Tags/RoleTagCategoryTest.php | 54 +++++ tests/Unit/Repositories/Tags/RoleTagTest.php | 62 ++++++ .../Repositories/Tags/UserTagCategoryTest.php | 54 +++++ tests/Unit/Repositories/Tags/UserTagTest.php | 62 ++++++ tests/Unit/Traits/DataGroupTraitTest.php | 22 ++ tests/Unit/Traits/DataPositionTraitTest.php | 22 ++ tests/Unit/Traits/DataRoleTraitTest.php | 22 ++ tests/Unit/Traits/DataUserTraitTest.php | 92 ++++++++ tests/Unit/Traits/GroupTraitTest.php | 14 ++ tests/Unit/Traits/PositionTraitTest.php | 14 ++ tests/Unit/Traits/RoleTraitTest.php | 43 +++- .../Traits/Tags/GroupTagCategoryTraitTest.php | 41 ++++ tests/Unit/Traits/Tags/GroupTagTraitTest.php | 53 +++++ .../Tags/PositionTagCategoryTraitTest.php | 40 +++- .../Unit/Traits/Tags/PositionTagTraitTest.php | 54 +++++ .../Traits/Tags/RoleTagCategoryTraitTest.php | 39 ++++ tests/Unit/Traits/Tags/RoleTagTraitTest.php | 58 ++++- .../Traits/Tags/UserTagCategoryTraitTest.php | 39 ++++ tests/Unit/Traits/Tags/UserTagTraitTest.php | 54 +++++ tests/Unit/Traits/UserTraitTest.php | 14 ++ 53 files changed, 4025 insertions(+), 20 deletions(-) create mode 100644 tests/Integration/Cache/DataGroupTest.php create mode 100644 tests/Integration/Cache/DataPositionTest.php create mode 100644 tests/Integration/Cache/DataRoleTest.php create mode 100644 tests/Integration/Cache/DataUserTest.php create mode 100644 tests/Integration/Cache/GroupTest.php create mode 100644 tests/Integration/Cache/Pivots/Tags/GroupGroupTagTest.php create mode 100644 tests/Integration/Cache/Pivots/Tags/PositionPositionTagTest.php create mode 100644 tests/Integration/Cache/Pivots/Tags/RoleRoleTagTest.php create mode 100644 tests/Integration/Cache/Pivots/Tags/UserUserTagTest.php create mode 100644 tests/Integration/Cache/Pivots/UserGroupTest.php create mode 100644 tests/Integration/Cache/Pivots/UserRoleTest.php create mode 100644 tests/Integration/Cache/PositionTest.php create mode 100644 tests/Integration/Cache/RoleTest.php create mode 100644 tests/Integration/Cache/Tags/GroupTagCategoryTest.php create mode 100644 tests/Integration/Cache/Tags/GroupTagTest.php create mode 100644 tests/Integration/Cache/Tags/PositionTagCategoryTest.php create mode 100644 tests/Integration/Cache/Tags/PositionTagTest.php create mode 100644 tests/Integration/Cache/Tags/RoleTagCategoryTest.php create mode 100644 tests/Integration/Cache/Tags/RoleTagTest.php create mode 100644 tests/Integration/Cache/Tags/UserTagCategoryTest.php create mode 100644 tests/Integration/Cache/Tags/UserTagTest.php create mode 100644 tests/Integration/Cache/UserTest.php create mode 100644 tests/Unit/Observers/NotifyObservers/Framework/NotifierTest.php create mode 100644 tests/Unit/Observers/NotifyObservers/Framework/ObserveTest.php create mode 100644 tests/Unit/Observers/NotifyObservers/Framework/ObserverStoreTest.php diff --git a/composer.json b/composer.json index f9a9d01..f7aa548 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ }, "require-dev": { "orchestra/testbench": "^4.0", - "phpstan/phpstan": "^0.12.8" + "phpstan/phpstan": "^0.12.8", + "phpspec/prophecy-phpunit": "2.0.0" }, "extra": { "laravel": { diff --git a/composer.lock b/composer.lock index f478c2b..ccdd737 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "054ee4e037d5e3290f4072e7d9315028", + "content-hash": "35f37fb072d464e00ca595a7101da7ea", "packages": [], "packages-dev": [ { @@ -1563,6 +1563,54 @@ ], "time": "2020-03-05T15:02:03+00:00" }, + { + "name": "phpspec/prophecy-phpunit", + "version": "v2.0.0", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy-phpunit.git", + "reference": "049638b7a0a50149ec16fe9c6959f8e37c15454e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy-phpunit/zipball/049638b7a0a50149ec16fe9c6959f8e37c15454e", + "reference": "049638b7a0a50149ec16fe9c6959f8e37c15454e", + "shasum": "" + }, + "require": { + "php": "^7.3", + "phpspec/prophecy": "^1.3", + "phpunit/phpunit": "^9.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "Prophecy\\PhpUnit\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christophe Coevoet", + "email": "stof@notk.org" + } + ], + "description": "PhpUnit test case integrating the Prophecy mocking library", + "homepage": "http://phpspec.net", + "keywords": [ + "phpunit", + "prophecy" + ], + "time": "2020-04-07T09:34:43+00:00" + }, { "name": "phpstan/phpstan", "version": "0.12.19", diff --git a/src/Observers/NotifyObservers/Framework/ObserverStore.php b/src/Observers/NotifyObservers/Framework/ObserverStore.php index b1df42e..caac1ab 100644 --- a/src/Observers/NotifyObservers/Framework/ObserverStore.php +++ b/src/Observers/NotifyObservers/Framework/ObserverStore.php @@ -18,8 +18,9 @@ public function attach($notifier, $observer): void public function detach($notifier, $observer): void { if (array_key_exists($notifier, $this->observers)) { - if (array_key_exists($observer, $this->observers[$notifier])) { - unset($this->observers[$notifier][$observer]); + if (($key = array_search($observer, $this->observers[$notifier])) !== false) { + unset($this->observers[$notifier][$key]); + $this->observers[$notifier] = array_values($this->observers[$notifier]); } } } diff --git a/tests/Integration/Cache/DataGroupTest.php b/tests/Integration/Cache/DataGroupTest.php new file mode 100644 index 0000000..73937e2 --- /dev/null +++ b/tests/Integration/Cache/DataGroupTest.php @@ -0,0 +1,97 @@ +create(); + + $groupRepository = $this->prophesize(DataGroupRepository::class); + $groupRepository->getById($dataGroup->id())->shouldBeCalled()->willReturn($dataGroup); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\DataGroup::class . '@getById:' . $dataGroup->id(); + + $groupCache = new \BristolSU\ControlDB\Cache\DataGroup($groupRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($dataGroup->is($groupCache->getById($dataGroup->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($dataGroup->is($cache->get($key))); + } + + /** @test */ + public function getWhere_does_not_save_in_the_cache() + { + $group = factory(DataGroup::class)->create(); + + $groupRepository = $this->prophesize(DataGroupRepository::class); + $groupRepository->getWhere(['email' => 'test@test.com'])->shouldBeCalled()->willReturn($group); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupCache = new \BristolSU\ControlDB\Cache\DataGroup($groupRepository->reveal(), $cache->reveal()); + + $this->assertTrue($group->is($groupCache->getWhere(['email' => 'test@test.com']))); + } + + /** @test */ + public function getAllWhere_does_not_save_in_the_cache() + { + $groups = factory(DataGroup::class, 5)->create(); + + $groupRepository = $this->prophesize(DataGroupRepository::class); + $groupRepository->getAllWhere(['email' => 'test@test.com'])->shouldBeCalled()->willReturn($groups); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupCache = new \BristolSU\ControlDB\Cache\DataGroup($groupRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $groupCache->getAllWhere(['email' => 'test@test.com'])); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $group = factory(DataGroup::class)->create(); + + $groupRepository = $this->prophesize(DataGroupRepository::class); + $groupRepository->update($group->id(), 'N', 'E')->shouldBeCalled()->willReturn($group); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupCache = new \BristolSU\ControlDB\Cache\DataGroup($groupRepository->reveal(), $cache->reveal()); + + $this->assertTrue($group->is($groupCache->update($group->id(), 'N', 'E'))); + } + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $group = factory(DataGroup::class)->create(); + + $groupRepository = $this->prophesize(DataGroupRepository::class); + $groupRepository->create('N', 'E')->shouldBeCalled()->willReturn($group); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupCache = new \BristolSU\ControlDB\Cache\DataGroup($groupRepository->reveal(), $cache->reveal()); + + $this->assertTrue($group->is($groupCache->create('N', 'E'))); + } + + +} \ No newline at end of file diff --git a/tests/Integration/Cache/DataPositionTest.php b/tests/Integration/Cache/DataPositionTest.php new file mode 100644 index 0000000..7514219 --- /dev/null +++ b/tests/Integration/Cache/DataPositionTest.php @@ -0,0 +1,97 @@ +create(); + + $positionRepository = $this->prophesize(DataPositionRepository::class); + $positionRepository->getById($dataPosition->id())->shouldBeCalled()->willReturn($dataPosition); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\DataPosition::class . '@getById:' . $dataPosition->id(); + + $positionCache = new \BristolSU\ControlDB\Cache\DataPosition($positionRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($dataPosition->is($positionCache->getById($dataPosition->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($dataPosition->is($cache->get($key))); + } + + /** @test */ + public function getWhere_does_not_save_in_the_cache() + { + $position = factory(DataPosition::class)->create(); + + $positionRepository = $this->prophesize(DataPositionRepository::class); + $positionRepository->getWhere(['email' => 'test@test.com'])->shouldBeCalled()->willReturn($position); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionCache = new \BristolSU\ControlDB\Cache\DataPosition($positionRepository->reveal(), $cache->reveal()); + + $this->assertTrue($position->is($positionCache->getWhere(['email' => 'test@test.com']))); + } + + /** @test */ + public function getAllWhere_does_not_save_in_the_cache() + { + $positions = factory(DataPosition::class, 5)->create(); + + $positionRepository = $this->prophesize(DataPositionRepository::class); + $positionRepository->getAllWhere(['email' => 'test@test.com'])->shouldBeCalled()->willReturn($positions); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionCache = new \BristolSU\ControlDB\Cache\DataPosition($positionRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $positionCache->getAllWhere(['email' => 'test@test.com'])); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $position = factory(DataPosition::class)->create(); + + $positionRepository = $this->prophesize(DataPositionRepository::class); + $positionRepository->update($position->id(), 'N', 'E')->shouldBeCalled()->willReturn($position); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionCache = new \BristolSU\ControlDB\Cache\DataPosition($positionRepository->reveal(), $cache->reveal()); + + $this->assertTrue($position->is($positionCache->update($position->id(), 'N', 'E'))); + } + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $position = factory(DataPosition::class)->create(); + + $positionRepository = $this->prophesize(DataPositionRepository::class); + $positionRepository->create('N', 'E')->shouldBeCalled()->willReturn($position); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionCache = new \BristolSU\ControlDB\Cache\DataPosition($positionRepository->reveal(), $cache->reveal()); + + $this->assertTrue($position->is($positionCache->create('N', 'E'))); + } + + +} \ No newline at end of file diff --git a/tests/Integration/Cache/DataRoleTest.php b/tests/Integration/Cache/DataRoleTest.php new file mode 100644 index 0000000..972a0e4 --- /dev/null +++ b/tests/Integration/Cache/DataRoleTest.php @@ -0,0 +1,97 @@ +create(); + + $roleRepository = $this->prophesize(DataRoleRepository::class); + $roleRepository->getById($dataRole->id())->shouldBeCalled()->willReturn($dataRole); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\DataRole::class . '@getById:' . $dataRole->id(); + + $roleCache = new \BristolSU\ControlDB\Cache\DataRole($roleRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($dataRole->is($roleCache->getById($dataRole->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($dataRole->is($cache->get($key))); + } + + /** @test */ + public function getWhere_does_not_save_in_the_cache() + { + $role = factory(DataRole::class)->create(); + + $roleRepository = $this->prophesize(DataRoleRepository::class); + $roleRepository->getWhere(['email' => 'test@test.com'])->shouldBeCalled()->willReturn($role); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleCache = new \BristolSU\ControlDB\Cache\DataRole($roleRepository->reveal(), $cache->reveal()); + + $this->assertTrue($role->is($roleCache->getWhere(['email' => 'test@test.com']))); + } + + /** @test */ + public function getAllWhere_does_not_save_in_the_cache() + { + $roles = factory(DataRole::class, 5)->create(); + + $roleRepository = $this->prophesize(DataRoleRepository::class); + $roleRepository->getAllWhere(['email' => 'test@test.com'])->shouldBeCalled()->willReturn($roles); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleCache = new \BristolSU\ControlDB\Cache\DataRole($roleRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $roleCache->getAllWhere(['email' => 'test@test.com'])); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $role = factory(DataRole::class)->create(); + + $roleRepository = $this->prophesize(DataRoleRepository::class); + $roleRepository->update($role->id(), 'N', 'E')->shouldBeCalled()->willReturn($role); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleCache = new \BristolSU\ControlDB\Cache\DataRole($roleRepository->reveal(), $cache->reveal()); + + $this->assertTrue($role->is($roleCache->update($role->id(), 'N', 'E'))); + } + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $role = factory(DataRole::class)->create(); + + $roleRepository = $this->prophesize(DataRoleRepository::class); + $roleRepository->create('N', 'E')->shouldBeCalled()->willReturn($role); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleCache = new \BristolSU\ControlDB\Cache\DataRole($roleRepository->reveal(), $cache->reveal()); + + $this->assertTrue($role->is($roleCache->create('N', 'E'))); + } + + +} \ No newline at end of file diff --git a/tests/Integration/Cache/DataUserTest.php b/tests/Integration/Cache/DataUserTest.php new file mode 100644 index 0000000..4e25a0e --- /dev/null +++ b/tests/Integration/Cache/DataUserTest.php @@ -0,0 +1,97 @@ +create(); + + $userRepository = $this->prophesize(DataUserRepository::class); + $userRepository->getById($dataUser->id())->shouldBeCalled()->willReturn($dataUser); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\DataUser::class . '@getById:' . $dataUser->id(); + + $userCache = new \BristolSU\ControlDB\Cache\DataUser($userRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($dataUser->is($userCache->getById($dataUser->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($dataUser->is($cache->get($key))); + } + + /** @test */ + public function getWhere_does_not_save_in_the_cache() + { + $user = factory(DataUser::class)->create(); + + $userRepository = $this->prophesize(DataUserRepository::class); + $userRepository->getWhere(['email' => 'test@test.com'])->shouldBeCalled()->willReturn($user); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userCache = new \BristolSU\ControlDB\Cache\DataUser($userRepository->reveal(), $cache->reveal()); + + $this->assertTrue($user->is($userCache->getWhere(['email' => 'test@test.com']))); + } + + /** @test */ + public function getAllWhere_does_not_save_in_the_cache() + { + $users = factory(DataUser::class, 5)->create(); + + $userRepository = $this->prophesize(DataUserRepository::class); + $userRepository->getAllWhere(['email' => 'test@test.com'])->shouldBeCalled()->willReturn($users); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userCache = new \BristolSU\ControlDB\Cache\DataUser($userRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $userCache->getAllWhere(['email' => 'test@test.com'])); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $user = factory(DataUser::class)->create(); + + $userRepository = $this->prophesize(DataUserRepository::class); + $userRepository->update($user->id(), 'F', 'L', 'E', null, 'PN')->shouldBeCalled()->willReturn($user); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userCache = new \BristolSU\ControlDB\Cache\DataUser($userRepository->reveal(), $cache->reveal()); + + $this->assertTrue($user->is($userCache->update($user->id(), 'F', 'L', 'E', null, 'PN'))); + } + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $user = factory(DataUser::class)->create(); + + $userRepository = $this->prophesize(DataUserRepository::class); + $userRepository->create('F', 'L', 'E', null, 'PN')->shouldBeCalled()->willReturn($user); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userCache = new \BristolSU\ControlDB\Cache\DataUser($userRepository->reveal(), $cache->reveal()); + + $this->assertTrue($user->is($userCache->create('F', 'L', 'E', null, 'PN'))); + } + + +} \ No newline at end of file diff --git a/tests/Integration/Cache/GroupTest.php b/tests/Integration/Cache/GroupTest.php new file mode 100644 index 0000000..e502c3f --- /dev/null +++ b/tests/Integration/Cache/GroupTest.php @@ -0,0 +1,150 @@ +create(); + + $groupRepository = $this->prophesize(GroupRepository::class); + $groupRepository->getById($group->id())->shouldBeCalled()->willReturn($group); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Group::class . '@getById:' . $group->id(); + + $groupCache = new \BristolSU\ControlDB\Cache\Group($groupRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($group->is($groupCache->getById($group->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($group->is($cache->get($key))); + } + + /** @test */ + public function getByDataProviderId_saves_the_group_in_the_cache(){ + $dataProvider = factory(DataGroup::class)->create(); + $group = factory(Group::class)->create(['data_provider_id' => $dataProvider->id()]); + + $groupRepository = $this->prophesize(GroupRepository::class); + $groupRepository->getByDataProviderId($group->id())->shouldBeCalled()->willReturn($group); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Group::class . '@getByDataProviderId:' . $dataProvider->id(); + + $groupCache = new \BristolSU\ControlDB\Cache\Group($groupRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($group->is($groupCache->getByDataProviderId($dataProvider->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($group->is($cache->get($key))); + } + + /** @test */ + public function all_does_not_save_in_the_cache() + { + $groups = factory(Group::class, 5)->create(); + + $groupRepository = $this->prophesize(GroupRepository::class); + $groupRepository->all()->shouldBeCalled()->willReturn($groups); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupCache = new \BristolSU\ControlDB\Cache\Group($groupRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $groupCache->all()); + } + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $dataProvider = factory(DataGroup::class)->create(); + $group = factory(Group::class)->create(['data_provider_id' => $dataProvider->id()]); + + $groupRepository = $this->prophesize(GroupRepository::class); + $groupRepository->create($dataProvider->id())->shouldBeCalled()->willReturn($group); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupCache = new \BristolSU\ControlDB\Cache\Group($groupRepository->reveal(), $cache->reveal()); + + $this->assertTrue($group->is($groupCache->create($dataProvider->id()))); + } + + /** @test */ + public function delete_does_not_save_in_the_cache() + { + $group = factory(Group::class)->create(); + + $groupRepository = $this->prophesize(GroupRepository::class); + $groupRepository->delete($group->id())->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupCache = new \BristolSU\ControlDB\Cache\Group($groupRepository->reveal(), $cache->reveal()); + + $this->assertNull($groupCache->delete($group->id())); + } + + /** @test */ + public function paginate_does_not_save_in_the_cache() + { + $groups = factory(Group::class, 5)->create(); + + $groupRepository = $this->prophesize(GroupRepository::class); + $groupRepository->paginate(1, 2)->shouldBeCalled()->willReturn($groups); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupCache = new \BristolSU\ControlDB\Cache\Group($groupRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $groupCache->paginate(1, 2)); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $dataProvider = factory(DataGroup::class)->create(); + $group = factory(Group::class)->create(['data_provider_id' => $dataProvider->id()]); + + $groupRepository = $this->prophesize(GroupRepository::class); + $groupRepository->update($group->id(), $dataProvider->id())->shouldBeCalled()->willReturn($group); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupCache = new \BristolSU\ControlDB\Cache\Group($groupRepository->reveal(), $cache->reveal()); + + $this->assertTrue($group->is($groupCache->update($group->id(), $dataProvider->id()))); + } + + /** @test */ + public function count_saves_the_count_in_the_cache(){ + $groupRepository = $this->prophesize(GroupRepository::class); + $groupRepository->count()->shouldBeCalled()->willReturn(19); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Group::class . '@count'; + + $groupCache = new \BristolSU\ControlDB\Cache\Group($groupRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertEquals(19, $groupCache->count()); + $this->assertTrue($cache->has($key)); + $this->assertEquals(19, $cache->get($key)); + } + +} \ No newline at end of file diff --git a/tests/Integration/Cache/Pivots/Tags/GroupGroupTagTest.php b/tests/Integration/Cache/Pivots/Tags/GroupGroupTagTest.php new file mode 100644 index 0000000..34af43a --- /dev/null +++ b/tests/Integration/Cache/Pivots/Tags/GroupGroupTagTest.php @@ -0,0 +1,104 @@ +create(); + $group = factory(Group::class)->create(); + + $groupGroupTagRepository = $this->prophesize(GroupGroupTag::class); + $groupGroupTagRepository->addTagToGroup(Argument::that(function ($arg) use ($groupTag) { + return $arg instanceof GroupTag && $arg->is($groupTag); + }), Argument::that(function ($arg) use ($group) { + return $arg instanceof Group && $arg->is($group); + }))->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupGroupTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\GroupGroupTag($groupGroupTagRepository->reveal(), $cache->reveal()); + + $groupGroupTagCache->addTagToGroup($groupTag, $group); + } + + /** @test */ + public function removeTagFromGroup_does_not_save_in_cache() + { + $groupTag = factory(GroupTag::class)->create(); + $group = factory(Group::class)->create(); + + $groupGroupTagRepository = $this->prophesize(GroupGroupTag::class); + $groupGroupTagRepository->removeTagFromGroup(Argument::that(function ($arg) use ($groupTag) { + return $arg instanceof GroupTag && $arg->is($groupTag); + }), Argument::that(function ($arg) use ($group) { + return $arg instanceof Group && $arg->is($group); + }))->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupGroupTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\GroupGroupTag($groupGroupTagRepository->reveal(), $cache->reveal()); + + $groupGroupTagCache->removeTagFromGroup($groupTag, $group); + } + + /** @test */ + public function getTagsThroughGroup_saves_the_tags_in_the_cache() + { + $groupTags = factory(GroupTag::class, 5)->create(); + $group = factory(Group::class)->create(); + + $groupGroupTagRepository = $this->prophesize(GroupGroupTag::class); + $groupGroupTagRepository->getTagsThroughGroup(Argument::that(function ($arg) use ($group) { + return $arg instanceof Group && $arg->is($group); + }))->shouldBeCalled()->willReturn($groupTags); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Pivots\Tags\GroupGroupTag::class . '@getTagsThroughGroup:' . $group->id(); + + $groupGroupTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\GroupGroupTag($groupGroupTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $groupGroupTagCache->getTagsThroughGroup($group)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(GroupTag::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + } + + /** @test */ + public function getGroupsThroughTag_saves_the_groups_in_the_cache() + { + $groups = factory(Group::class, 5)->create(); + $groupTag = factory(GroupTag::class)->create(); + + $groupGroupTagRepository = $this->prophesize(GroupGroupTag::class); + $groupGroupTagRepository->getGroupsThroughTag(Argument::that(function ($arg) use ($groupTag) { + return $arg instanceof GroupTag && $arg->is($groupTag); + }))->shouldBeCalled()->willReturn($groups); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Pivots\Tags\GroupGroupTag::class . '@getGroupsThroughTag:' . $groupTag->id(); + + $groupTagTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\GroupGroupTag($groupGroupTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $groupTagTagCache->getGroupsThroughTag($groupTag)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(Group::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + } +} \ No newline at end of file diff --git a/tests/Integration/Cache/Pivots/Tags/PositionPositionTagTest.php b/tests/Integration/Cache/Pivots/Tags/PositionPositionTagTest.php new file mode 100644 index 0000000..a5f0f5f --- /dev/null +++ b/tests/Integration/Cache/Pivots/Tags/PositionPositionTagTest.php @@ -0,0 +1,104 @@ +create(); + $position = factory(Position::class)->create(); + + $positionPositionTagRepository = $this->prophesize(PositionPositionTag::class); + $positionPositionTagRepository->addTagToPosition(Argument::that(function ($arg) use ($positionTag) { + return $arg instanceof PositionTag && $arg->is($positionTag); + }), Argument::that(function ($arg) use ($position) { + return $arg instanceof Position && $arg->is($position); + }))->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionPositionTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\PositionPositionTag($positionPositionTagRepository->reveal(), $cache->reveal()); + + $positionPositionTagCache->addTagToPosition($positionTag, $position); + } + + /** @test */ + public function removeTagFromPosition_does_not_save_in_cache() + { + $positionTag = factory(PositionTag::class)->create(); + $position = factory(Position::class)->create(); + + $positionPositionTagRepository = $this->prophesize(PositionPositionTag::class); + $positionPositionTagRepository->removeTagFromPosition(Argument::that(function ($arg) use ($positionTag) { + return $arg instanceof PositionTag && $arg->is($positionTag); + }), Argument::that(function ($arg) use ($position) { + return $arg instanceof Position && $arg->is($position); + }))->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionPositionTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\PositionPositionTag($positionPositionTagRepository->reveal(), $cache->reveal()); + + $positionPositionTagCache->removeTagFromPosition($positionTag, $position); + } + + /** @test */ + public function getTagsThroughPosition_saves_the_tags_in_the_cache() + { + $positionTags = factory(PositionTag::class, 5)->create(); + $position = factory(Position::class)->create(); + + $positionPositionTagRepository = $this->prophesize(PositionPositionTag::class); + $positionPositionTagRepository->getTagsThroughPosition(Argument::that(function ($arg) use ($position) { + return $arg instanceof Position && $arg->is($position); + }))->shouldBeCalled()->willReturn($positionTags); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Pivots\Tags\PositionPositionTag::class . '@getTagsThroughPosition:' . $position->id(); + + $positionPositionTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\PositionPositionTag($positionPositionTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $positionPositionTagCache->getTagsThroughPosition($position)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(PositionTag::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + } + + /** @test */ + public function getPositionsThroughTag_saves_the_positions_in_the_cache() + { + $positions = factory(Position::class, 5)->create(); + $positionTag = factory(PositionTag::class)->create(); + + $positionPositionTagRepository = $this->prophesize(PositionPositionTag::class); + $positionPositionTagRepository->getPositionsThroughTag(Argument::that(function ($arg) use ($positionTag) { + return $arg instanceof PositionTag && $arg->is($positionTag); + }))->shouldBeCalled()->willReturn($positions); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Pivots\Tags\PositionPositionTag::class . '@getPositionsThroughTag:' . $positionTag->id(); + + $positionTagTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\PositionPositionTag($positionPositionTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $positionTagTagCache->getPositionsThroughTag($positionTag)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(Position::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + } +} \ No newline at end of file diff --git a/tests/Integration/Cache/Pivots/Tags/RoleRoleTagTest.php b/tests/Integration/Cache/Pivots/Tags/RoleRoleTagTest.php new file mode 100644 index 0000000..4a71083 --- /dev/null +++ b/tests/Integration/Cache/Pivots/Tags/RoleRoleTagTest.php @@ -0,0 +1,104 @@ +create(); + $role = factory(Role::class)->create(); + + $roleRoleTagRepository = $this->prophesize(RoleRoleTag::class); + $roleRoleTagRepository->addTagToRole(Argument::that(function ($arg) use ($roleTag) { + return $arg instanceof RoleTag && $arg->is($roleTag); + }), Argument::that(function ($arg) use ($role) { + return $arg instanceof Role && $arg->is($role); + }))->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleRoleTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\RoleRoleTag($roleRoleTagRepository->reveal(), $cache->reveal()); + + $roleRoleTagCache->addTagToRole($roleTag, $role); + } + + /** @test */ + public function removeTagFromRole_does_not_save_in_cache() + { + $roleTag = factory(RoleTag::class)->create(); + $role = factory(Role::class)->create(); + + $roleRoleTagRepository = $this->prophesize(RoleRoleTag::class); + $roleRoleTagRepository->removeTagFromRole(Argument::that(function ($arg) use ($roleTag) { + return $arg instanceof RoleTag && $arg->is($roleTag); + }), Argument::that(function ($arg) use ($role) { + return $arg instanceof Role && $arg->is($role); + }))->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleRoleTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\RoleRoleTag($roleRoleTagRepository->reveal(), $cache->reveal()); + + $roleRoleTagCache->removeTagFromRole($roleTag, $role); + } + + /** @test */ + public function getTagsThroughRole_saves_the_tags_in_the_cache() + { + $roleTags = factory(RoleTag::class, 5)->create(); + $role = factory(Role::class)->create(); + + $roleRoleTagRepository = $this->prophesize(RoleRoleTag::class); + $roleRoleTagRepository->getTagsThroughRole(Argument::that(function ($arg) use ($role) { + return $arg instanceof Role && $arg->is($role); + }))->shouldBeCalled()->willReturn($roleTags); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Pivots\Tags\RoleRoleTag::class . '@getTagsThroughRole:' . $role->id(); + + $roleRoleTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\RoleRoleTag($roleRoleTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $roleRoleTagCache->getTagsThroughRole($role)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(RoleTag::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + } + + /** @test */ + public function getRolesThroughTag_saves_the_roles_in_the_cache() + { + $roles = factory(Role::class, 5)->create(); + $roleTag = factory(RoleTag::class)->create(); + + $roleRoleTagRepository = $this->prophesize(RoleRoleTag::class); + $roleRoleTagRepository->getRolesThroughTag(Argument::that(function ($arg) use ($roleTag) { + return $arg instanceof RoleTag && $arg->is($roleTag); + }))->shouldBeCalled()->willReturn($roles); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Pivots\Tags\RoleRoleTag::class . '@getRolesThroughTag:' . $roleTag->id(); + + $roleTagTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\RoleRoleTag($roleRoleTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $roleTagTagCache->getRolesThroughTag($roleTag)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(Role::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + } +} \ No newline at end of file diff --git a/tests/Integration/Cache/Pivots/Tags/UserUserTagTest.php b/tests/Integration/Cache/Pivots/Tags/UserUserTagTest.php new file mode 100644 index 0000000..8038258 --- /dev/null +++ b/tests/Integration/Cache/Pivots/Tags/UserUserTagTest.php @@ -0,0 +1,104 @@ +create(); + $user = factory(User::class)->create(); + + $userUserTagRepository = $this->prophesize(UserUserTag::class); + $userUserTagRepository->addTagToUser(Argument::that(function ($arg) use ($userTag) { + return $arg instanceof UserTag && $arg->is($userTag); + }), Argument::that(function ($arg) use ($user) { + return $arg instanceof User && $arg->is($user); + }))->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userUserTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\UserUserTag($userUserTagRepository->reveal(), $cache->reveal()); + + $userUserTagCache->addTagToUser($userTag, $user); + } + + /** @test */ + public function removeTagFromUser_does_not_save_in_cache() + { + $userTag = factory(UserTag::class)->create(); + $user = factory(User::class)->create(); + + $userUserTagRepository = $this->prophesize(UserUserTag::class); + $userUserTagRepository->removeTagFromUser(Argument::that(function ($arg) use ($userTag) { + return $arg instanceof UserTag && $arg->is($userTag); + }), Argument::that(function ($arg) use ($user) { + return $arg instanceof User && $arg->is($user); + }))->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userUserTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\UserUserTag($userUserTagRepository->reveal(), $cache->reveal()); + + $userUserTagCache->removeTagFromUser($userTag, $user); + } + + /** @test */ + public function getTagsThroughUser_saves_the_tags_in_the_cache() + { + $userTags = factory(UserTag::class, 5)->create(); + $user = factory(User::class)->create(); + + $userUserTagRepository = $this->prophesize(UserUserTag::class); + $userUserTagRepository->getTagsThroughUser(Argument::that(function ($arg) use ($user) { + return $arg instanceof User && $arg->is($user); + }))->shouldBeCalled()->willReturn($userTags); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Pivots\Tags\UserUserTag::class . '@getTagsThroughUser:' . $user->id(); + + $userUserTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\UserUserTag($userUserTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $userUserTagCache->getTagsThroughUser($user)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(UserTag::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + } + + /** @test */ + public function getUsersThroughTag_saves_the_users_in_the_cache() + { + $users = factory(User::class, 5)->create(); + $userTag = factory(UserTag::class)->create(); + + $userUserTagRepository = $this->prophesize(UserUserTag::class); + $userUserTagRepository->getUsersThroughTag(Argument::that(function ($arg) use ($userTag) { + return $arg instanceof UserTag && $arg->is($userTag); + }))->shouldBeCalled()->willReturn($users); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Pivots\Tags\UserUserTag::class . '@getUsersThroughTag:' . $userTag->id(); + + $userTagTagCache = new \BristolSU\ControlDB\Cache\Pivots\Tags\UserUserTag($userUserTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $userTagTagCache->getUsersThroughTag($userTag)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(User::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + } +} \ No newline at end of file diff --git a/tests/Integration/Cache/Pivots/UserGroupTest.php b/tests/Integration/Cache/Pivots/UserGroupTest.php new file mode 100644 index 0000000..ba4da04 --- /dev/null +++ b/tests/Integration/Cache/Pivots/UserGroupTest.php @@ -0,0 +1,107 @@ +create(); + $group = factory(Group::class)->create(); + + $userGroupRepository = $this->prophesize(UserGroup::class); + $userGroupRepository->addUserToGroup(Argument::that(function ($arg) use ($user) { + return $arg instanceof User && $arg->is($user); + }), Argument::that(function ($arg) use ($group) { + return $arg instanceof Group && $arg->is($group); + }))->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupTagCache = new \BristolSU\ControlDB\Cache\Pivots\UserGroup($userGroupRepository->reveal(), $cache->reveal()); + + $groupTagCache->addUserToGroup($user, $group); + } + + /** @test */ + public function removeUserFromGroup_does_not_save_in_cache() + { + $user = factory(User::class)->create(); + $group = factory(Group::class)->create(); + + $userGroupRepository = $this->prophesize(UserGroup::class); + $userGroupRepository->removeUserFromGroup(Argument::that(function ($arg) use ($user) { + return $arg instanceof User && $arg->is($user); + }), Argument::that(function ($arg) use ($group) { + return $arg instanceof Group && $arg->is($group); + }))->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupTagCache = new \BristolSU\ControlDB\Cache\Pivots\UserGroup($userGroupRepository->reveal(), $cache->reveal()); + + $groupTagCache->removeUserFromGroup($user, $group); + } + + /** @test */ + public function getUsersThroughGroup_saves_the_users_in_the_cache() + { + $users = factory(User::class, 5)->create(); + $group = factory(Group::class)->create(); + + $userGroupRepository = $this->prophesize(UserGroup::class); + $userGroupRepository->getUsersThroughGroup(Argument::that(function ($arg) use ($group) { + return $arg instanceof Group && $arg->is($group); + }))->shouldBeCalled()->willReturn($users); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Pivots\UserGroup::class . '@getUsersThroughGroup:' . $group->id(); + + $groupTagCache = new \BristolSU\ControlDB\Cache\Pivots\UserGroup($userGroupRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $groupTagCache->getUsersThroughGroup($group)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(User::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + } + + /** @test */ + public function getGroupsThroughUser_saves_the_groups_in_the_cache() + { + $groups = factory(Group::class, 5)->create(); + $user = factory(User::class)->create(); + + $userGroupRepository = $this->prophesize(UserGroup::class); + $userGroupRepository->getGroupsThroughUser(Argument::that(function ($arg) use ($user) { + return $arg instanceof User && $arg->is($user); + }))->shouldBeCalled()->willReturn($groups); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Pivots\UserGroup::class . '@getGroupsThroughUser:' . $user->id(); + + $userTagCache = new \BristolSU\ControlDB\Cache\Pivots\UserGroup($userGroupRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $userTagCache->getGroupsThroughUser($user)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(Group::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + } + + +} \ No newline at end of file diff --git a/tests/Integration/Cache/Pivots/UserRoleTest.php b/tests/Integration/Cache/Pivots/UserRoleTest.php new file mode 100644 index 0000000..dd67c86 --- /dev/null +++ b/tests/Integration/Cache/Pivots/UserRoleTest.php @@ -0,0 +1,107 @@ +create(); + $role = factory(Role::class)->create(); + + $userRoleRepository = $this->prophesize(UserRole::class); + $userRoleRepository->addUserToRole(Argument::that(function ($arg) use ($user) { + return $arg instanceof User && $arg->is($user); + }), Argument::that(function ($arg) use ($role) { + return $arg instanceof Role && $arg->is($role); + }))->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleTagCache = new \BristolSU\ControlDB\Cache\Pivots\UserRole($userRoleRepository->reveal(), $cache->reveal()); + + $roleTagCache->addUserToRole($user, $role); + } + + /** @test */ + public function removeUserFromRole_does_not_save_in_cache() + { + $user = factory(User::class)->create(); + $role = factory(Role::class)->create(); + + $userRoleRepository = $this->prophesize(UserRole::class); + $userRoleRepository->removeUserFromRole(Argument::that(function ($arg) use ($user) { + return $arg instanceof User && $arg->is($user); + }), Argument::that(function ($arg) use ($role) { + return $arg instanceof Role && $arg->is($role); + }))->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleTagCache = new \BristolSU\ControlDB\Cache\Pivots\UserRole($userRoleRepository->reveal(), $cache->reveal()); + + $roleTagCache->removeUserFromRole($user, $role); + } + + /** @test */ + public function getUsersThroughRole_saves_the_users_in_the_cache() + { + $users = factory(User::class, 5)->create(); + $role = factory(Role::class)->create(); + + $userRoleRepository = $this->prophesize(UserRole::class); + $userRoleRepository->getUsersThroughRole(Argument::that(function ($arg) use ($role) { + return $arg instanceof Role && $arg->is($role); + }))->shouldBeCalled()->willReturn($users); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Pivots\UserRole::class . '@getUsersThroughRole:' . $role->id(); + + $roleTagCache = new \BristolSU\ControlDB\Cache\Pivots\UserRole($userRoleRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $roleTagCache->getUsersThroughRole($role)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(User::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + } + + /** @test */ + public function getRolesThroughUser_saves_the_roles_in_the_cache() + { + $roles = factory(Role::class, 5)->create(); + $user = factory(User::class)->create(); + + $userRoleRepository = $this->prophesize(UserRole::class); + $userRoleRepository->getRolesThroughUser(Argument::that(function ($arg) use ($user) { + return $arg instanceof User && $arg->is($user); + }))->shouldBeCalled()->willReturn($roles); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Pivots\UserRole::class . '@getRolesThroughUser:' . $user->id(); + + $userTagCache = new \BristolSU\ControlDB\Cache\Pivots\UserRole($userRoleRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $userTagCache->getRolesThroughUser($user)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(Role::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + } + + +} \ No newline at end of file diff --git a/tests/Integration/Cache/PositionTest.php b/tests/Integration/Cache/PositionTest.php new file mode 100644 index 0000000..40308c8 --- /dev/null +++ b/tests/Integration/Cache/PositionTest.php @@ -0,0 +1,150 @@ +create(); + + $positionRepository = $this->prophesize(PositionRepository::class); + $positionRepository->getById($position->id())->shouldBeCalled()->willReturn($position); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Position::class . '@getById:' . $position->id(); + + $positionCache = new \BristolSU\ControlDB\Cache\Position($positionRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($position->is($positionCache->getById($position->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($position->is($cache->get($key))); + } + + /** @test */ + public function getByDataProviderId_saves_the_position_in_the_cache(){ + $dataProvider = factory(DataPosition::class)->create(); + $position = factory(Position::class)->create(['data_provider_id' => $dataProvider->id()]); + + $positionRepository = $this->prophesize(PositionRepository::class); + $positionRepository->getByDataProviderId($position->id())->shouldBeCalled()->willReturn($position); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Position::class . '@getByDataProviderId:' . $dataProvider->id(); + + $positionCache = new \BristolSU\ControlDB\Cache\Position($positionRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($position->is($positionCache->getByDataProviderId($dataProvider->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($position->is($cache->get($key))); + } + + /** @test */ + public function all_does_not_save_in_the_cache() + { + $positions = factory(Position::class, 5)->create(); + + $positionRepository = $this->prophesize(PositionRepository::class); + $positionRepository->all()->shouldBeCalled()->willReturn($positions); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionCache = new \BristolSU\ControlDB\Cache\Position($positionRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $positionCache->all()); + } + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $dataProvider = factory(DataPosition::class)->create(); + $position = factory(Position::class)->create(['data_provider_id' => $dataProvider->id()]); + + $positionRepository = $this->prophesize(PositionRepository::class); + $positionRepository->create($dataProvider->id())->shouldBeCalled()->willReturn($position); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionCache = new \BristolSU\ControlDB\Cache\Position($positionRepository->reveal(), $cache->reveal()); + + $this->assertTrue($position->is($positionCache->create($dataProvider->id()))); + } + + /** @test */ + public function delete_does_not_save_in_the_cache() + { + $position = factory(Position::class)->create(); + + $positionRepository = $this->prophesize(PositionRepository::class); + $positionRepository->delete($position->id())->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionCache = new \BristolSU\ControlDB\Cache\Position($positionRepository->reveal(), $cache->reveal()); + + $this->assertNull($positionCache->delete($position->id())); + } + + /** @test */ + public function paginate_does_not_save_in_the_cache() + { + $positions = factory(Position::class, 5)->create(); + + $positionRepository = $this->prophesize(PositionRepository::class); + $positionRepository->paginate(1, 2)->shouldBeCalled()->willReturn($positions); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionCache = new \BristolSU\ControlDB\Cache\Position($positionRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $positionCache->paginate(1, 2)); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $dataProvider = factory(DataPosition::class)->create(); + $position = factory(Position::class)->create(['data_provider_id' => $dataProvider->id()]); + + $positionRepository = $this->prophesize(PositionRepository::class); + $positionRepository->update($position->id(), $dataProvider->id())->shouldBeCalled()->willReturn($position); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionCache = new \BristolSU\ControlDB\Cache\Position($positionRepository->reveal(), $cache->reveal()); + + $this->assertTrue($position->is($positionCache->update($position->id(), $dataProvider->id()))); + } + + /** @test */ + public function count_saves_the_count_in_the_cache(){ + $positionRepository = $this->prophesize(PositionRepository::class); + $positionRepository->count()->shouldBeCalled()->willReturn(19); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Position::class . '@count'; + + $positionCache = new \BristolSU\ControlDB\Cache\Position($positionRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertEquals(19, $positionCache->count()); + $this->assertTrue($cache->has($key)); + $this->assertEquals(19, $cache->get($key)); + } + +} \ No newline at end of file diff --git a/tests/Integration/Cache/RoleTest.php b/tests/Integration/Cache/RoleTest.php new file mode 100644 index 0000000..fb4d3ca --- /dev/null +++ b/tests/Integration/Cache/RoleTest.php @@ -0,0 +1,198 @@ +create(); + + $roleRepository = $this->prophesize(RoleRepository::class); + $roleRepository->getById($role->id())->shouldBeCalled()->willReturn($role); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Role::class . '@getById:' . $role->id(); + + $roleCache = new \BristolSU\ControlDB\Cache\Role($roleRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($role->is($roleCache->getById($role->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($role->is($cache->get($key))); + } + + /** @test */ + public function getByDataProviderId_saves_the_role_in_the_cache(){ + $dataProvider = factory(DataRole::class)->create(); + $role = factory(Role::class)->create(['data_provider_id' => $dataProvider->id()]); + + $roleRepository = $this->prophesize(RoleRepository::class); + $roleRepository->getByDataProviderId($role->id())->shouldBeCalled()->willReturn($role); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Role::class . '@getByDataProviderId:' . $dataProvider->id(); + + $roleCache = new \BristolSU\ControlDB\Cache\Role($roleRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($role->is($roleCache->getByDataProviderId($dataProvider->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($role->is($cache->get($key))); + } + + /** @test */ + public function all_does_not_save_in_the_cache() + { + $roles = factory(Role::class, 5)->create(); + + $roleRepository = $this->prophesize(RoleRepository::class); + $roleRepository->all()->shouldBeCalled()->willReturn($roles); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleCache = new \BristolSU\ControlDB\Cache\Role($roleRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $roleCache->all()); + } + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $dataProvider = factory(DataRole::class)->create(); + $group = factory(Group::class)->create(); + $position = factory(Position::class)->create(); + $role = factory(Role::class)->create(['data_provider_id' => $dataProvider->id(), 'group_id' => $group->id(), 'position_id' => $position->id()]); + + $roleRepository = $this->prophesize(RoleRepository::class); + $roleRepository->create($position->id(), $group->id(), $dataProvider->id())->shouldBeCalled()->willReturn($role); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleCache = new \BristolSU\ControlDB\Cache\Role($roleRepository->reveal(), $cache->reveal()); + + $this->assertTrue($role->is($roleCache->create($position->id(), $group->id(), $dataProvider->id()))); + } + + /** @test */ + public function delete_does_not_save_in_the_cache() + { + $role = factory(Role::class)->create(); + + $roleRepository = $this->prophesize(RoleRepository::class); + $roleRepository->delete($role->id())->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleCache = new \BristolSU\ControlDB\Cache\Role($roleRepository->reveal(), $cache->reveal()); + + $this->assertNull($roleCache->delete($role->id())); + } + + /** @test */ + public function paginate_does_not_save_in_the_cache() + { + $roles = factory(Role::class, 5)->create(); + + $roleRepository = $this->prophesize(RoleRepository::class); + $roleRepository->paginate(1, 2)->shouldBeCalled()->willReturn($roles); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleCache = new \BristolSU\ControlDB\Cache\Role($roleRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $roleCache->paginate(1, 2)); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $group = factory(Group::class)->create(); + $position = factory(Position::class)->create(); + $dataProvider = factory(DataRole::class)->create(); + $role = factory(Role::class)->create(['data_provider_id' => $dataProvider->id()]); + + $roleRepository = $this->prophesize(RoleRepository::class); + $roleRepository->update($role->id(), $position->id(), $group->id(), $dataProvider->id())->shouldBeCalled()->willReturn($role); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleCache = new \BristolSU\ControlDB\Cache\Role($roleRepository->reveal(), $cache->reveal()); + + $this->assertTrue($role->is($roleCache->update($role->id(), $position->id(), $group->id(), $dataProvider->id()))); + } + + /** @test */ + public function count_saves_the_count_in_the_cache(){ + $roleRepository = $this->prophesize(RoleRepository::class); + $roleRepository->count()->shouldBeCalled()->willReturn(19); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Role::class . '@count'; + + $roleCache = new \BristolSU\ControlDB\Cache\Role($roleRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertEquals(19, $roleCache->count()); + $this->assertTrue($cache->has($key)); + $this->assertEquals(19, $cache->get($key)); + } + + /** @test */ + public function allThroughGroup_saves_all_roles_with_a_group_in_the_cache(){ + $group = factory(Group::class)->create(); + $roles = factory(Role::class, 5)->create(['group_id' => $group->id()]); + + $roleRepository = $this->prophesize(RoleRepository::class); + $roleRepository->allThroughGroup(Argument::that(function($arg) use ($group) { + return $arg instanceof Group && $arg->is($group); + }))->shouldBeCalled()->willReturn($roles); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Role::class . '@allThroughGroup:' . $group->id(); + + $roleCache = new \BristolSU\ControlDB\Cache\Role($roleRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $roleCache->allThroughGroup($group)); + $this->assertTrue($cache->has($key)); + $this->assertCount(5, $cache->get($key)); + } + + /** @test */ + public function allThroughPosition_saves_all_roles_with_a_position_in_the_cache(){ + $position = factory(Position::class)->create(); + $roles = factory(Role::class, 5)->create(['position_id' => $position->id()]); + + $roleRepository = $this->prophesize(RoleRepository::class); + $roleRepository->allThroughPosition(Argument::that(function($arg) use ($position) { + return $arg instanceof Position && $arg->is($position); + }))->shouldBeCalled()->willReturn($roles); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Role::class . '@allThroughPosition:' . $position->id(); + + $roleCache = new \BristolSU\ControlDB\Cache\Role($roleRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $roleCache->allThroughPosition($position)); + $this->assertTrue($cache->has($key)); + $this->assertCount(5, $cache->get($key)); + } + +} \ No newline at end of file diff --git a/tests/Integration/Cache/Tags/GroupTagCategoryTest.php b/tests/Integration/Cache/Tags/GroupTagCategoryTest.php new file mode 100644 index 0000000..054b83b --- /dev/null +++ b/tests/Integration/Cache/Tags/GroupTagCategoryTest.php @@ -0,0 +1,117 @@ +create(); + + $groupTagCategoryRepository = $this->prophesize(GroupTagCategoryRepository::class); + $groupTagCategoryRepository->all()->shouldBeCalled()->willReturn($groupTagCategories); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\GroupTagCategory($groupTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $groupTagCategoryCache->all()); + } + + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $groupTagCategory = factory(GroupTagCategory::class)->create(); + + $groupTagCategoryRepository = $this->prophesize(GroupTagCategoryRepository::class); + $groupTagCategoryRepository->create('name1', 'desc1', 'ref1')->shouldBeCalled()->willReturn($groupTagCategory); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\GroupTagCategory($groupTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertTrue($groupTagCategory->is($groupTagCategoryCache->create('name1', 'desc1', 'ref1'))); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $groupTagCategory = factory(GroupTagCategory::class)->create(); + + $groupTagCategoryRepository = $this->prophesize(GroupTagCategoryRepository::class); + $groupTagCategoryRepository->update($groupTagCategory->id(), 'name1', 'desc1', 'ref1')->shouldBeCalled()->willReturn($groupTagCategory); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\GroupTagCategory($groupTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertTrue($groupTagCategory->is($groupTagCategoryCache->update($groupTagCategory->id(), 'name1', 'desc1', 'ref1'))); + } + + /** @test */ + public function delete_does_not_save_in_the_cache() + { + $groupTagCategory = factory(GroupTagCategory::class)->create(); + + $groupTagCategoryRepository = $this->prophesize(GroupTagCategoryRepository::class); + $groupTagCategoryRepository->delete($groupTagCategory->id())->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\GroupTagCategory($groupTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertNull($groupTagCategoryCache->delete($groupTagCategory->id())); + } + + /** @test */ + public function getById_saves_tags_in_the_cache(){ + $groupTagCategory = factory(GroupTagCategory::class)->create(); + + $groupTagCategoryRepository = $this->prophesize(GroupTagCategoryRepository::class); + $groupTagCategoryRepository->getById($groupTagCategory->id())->shouldBeCalled()->willReturn($groupTagCategory); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\GroupTagCategory::class . '@getById:' . $groupTagCategory->id(); + + $groupTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\GroupTagCategory($groupTagCategoryRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($groupTagCategory->is($groupTagCategoryCache->getById($groupTagCategory->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($groupTagCategory->is($cache->get($key))); + } + + /** @test */ + public function getByReference_saves_tags_in_the_cache(){ + $groupTagCategory = factory(GroupTagCategory::class)->create(); + + $groupTagCategoryRepository = $this->prophesize(GroupTagCategoryRepository::class); + $groupTagCategoryRepository->getByReference('ref')->shouldBeCalled()->willReturn($groupTagCategory); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\GroupTagCategory::class . '@getByReference:ref'; + + $groupTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\GroupTagCategory($groupTagCategoryRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($groupTagCategory->is($groupTagCategoryCache->getByReference('ref'))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($groupTagCategory->is($cache->get($key))); + } + +} \ No newline at end of file diff --git a/tests/Integration/Cache/Tags/GroupTagTest.php b/tests/Integration/Cache/Tags/GroupTagTest.php new file mode 100644 index 0000000..80bd57f --- /dev/null +++ b/tests/Integration/Cache/Tags/GroupTagTest.php @@ -0,0 +1,144 @@ +create(); + + $groupTagRepository = $this->prophesize(GroupTagRepository::class); + $groupTagRepository->all()->shouldBeCalled()->willReturn($groupTags); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupTagCache = new \BristolSU\ControlDB\Cache\Tags\GroupTag($groupTagRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $groupTagCache->all()); + } + + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $groupTagCategory = factory(GroupTagCategory::class)->create(); + $groupTag = factory(GroupTag::class)->create(['tag_category_id' => $groupTagCategory->id()]); + + $groupTagRepository = $this->prophesize(GroupTagRepository::class); + $groupTagRepository->create('name1', 'desc1', 'ref1', $groupTagCategory->id())->shouldBeCalled()->willReturn($groupTag); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupTagCache = new \BristolSU\ControlDB\Cache\Tags\GroupTag($groupTagRepository->reveal(), $cache->reveal()); + + $this->assertTrue($groupTag->is($groupTagCache->create('name1', 'desc1', 'ref1', $groupTagCategory->id()))); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $groupTagCategory = factory(GroupTagCategory::class)->create(); + $groupTag = factory(GroupTag::class)->create(['tag_category_id' => $groupTagCategory->id()]); + + $groupTagRepository = $this->prophesize(GroupTagRepository::class); + $groupTagRepository->update($groupTag->id(), 'name1', 'desc1', 'ref1', $groupTagCategory->id())->shouldBeCalled()->willReturn($groupTag); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupTagCache = new \BristolSU\ControlDB\Cache\Tags\GroupTag($groupTagRepository->reveal(), $cache->reveal()); + + $this->assertTrue($groupTag->is($groupTagCache->update($groupTag->id(), 'name1', 'desc1', 'ref1', $groupTagCategory->id()))); + } + + /** @test */ + public function delete_does_not_save_in_the_cache() + { + $groupTagCategory = factory(GroupTagCategory::class)->create(); + $groupTag = factory(GroupTag::class)->create(['tag_category_id' => $groupTagCategory->id()]); + + $groupTagRepository = $this->prophesize(GroupTagRepository::class); + $groupTagRepository->delete($groupTag->id())->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $groupTagCache = new \BristolSU\ControlDB\Cache\Tags\GroupTag($groupTagRepository->reveal(), $cache->reveal()); + + $this->assertNull($groupTagCache->delete($groupTag->id())); + } + + /** @test */ + public function allThroughTagCategory_saves_tags_in_the_cache(){ + $tagCategory = factory(GroupTagCategory::class)->create(); + $groupTags = factory(GroupTag::class, 5)->create(['tag_category_id' => $tagCategory->id()]); + + $groupTagRepository = $this->prophesize(GroupTagRepository::class); + $groupTagRepository->allThroughTagCategory(Argument::that(function($arg) use ($tagCategory) { + return $arg instanceof GroupTagCategory && $arg->is($tagCategory); + }))->shouldBeCalled()->willReturn($groupTags); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\GroupTag::class . '@allThroughTagCategory:' . $tagCategory->id(); + + $groupTagCache = new \BristolSU\ControlDB\Cache\Tags\GroupTag($groupTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $groupTagCache->allThroughTagCategory($tagCategory)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(GroupTag::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + + } + + /** @test */ + public function getById_saves_tags_in_the_cache(){ + $groupTag = factory(GroupTag::class)->create(); + + $groupTagRepository = $this->prophesize(GroupTagRepository::class); + $groupTagRepository->getById($groupTag->id())->shouldBeCalled()->willReturn($groupTag); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\GroupTag::class . '@getById:' . $groupTag->id(); + + $groupTagCache = new \BristolSU\ControlDB\Cache\Tags\GroupTag($groupTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($groupTag->is($groupTagCache->getById($groupTag->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($groupTag->is($cache->get($key))); + } + + /** @test */ + public function getTagByFullReference_saves_tags_in_the_cache(){ + $groupTag = factory(GroupTag::class)->create(); + + $groupTagRepository = $this->prophesize(GroupTagRepository::class); + $groupTagRepository->getTagByFullReference('full.ref')->shouldBeCalled()->willReturn($groupTag); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\GroupTag::class . '@getTagByFullReference:full.ref'; + + $groupTagCache = new \BristolSU\ControlDB\Cache\Tags\GroupTag($groupTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($groupTag->is($groupTagCache->getTagByFullReference('full.ref'))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($groupTag->is($cache->get($key))); + } + +} \ No newline at end of file diff --git a/tests/Integration/Cache/Tags/PositionTagCategoryTest.php b/tests/Integration/Cache/Tags/PositionTagCategoryTest.php new file mode 100644 index 0000000..8c752b3 --- /dev/null +++ b/tests/Integration/Cache/Tags/PositionTagCategoryTest.php @@ -0,0 +1,117 @@ +create(); + + $positionTagCategoryRepository = $this->prophesize(PositionTagCategoryRepository::class); + $positionTagCategoryRepository->all()->shouldBeCalled()->willReturn($positionTagCategories); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\PositionTagCategory($positionTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $positionTagCategoryCache->all()); + } + + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $positionTagCategory = factory(PositionTagCategory::class)->create(); + + $positionTagCategoryRepository = $this->prophesize(PositionTagCategoryRepository::class); + $positionTagCategoryRepository->create('name1', 'desc1', 'ref1')->shouldBeCalled()->willReturn($positionTagCategory); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\PositionTagCategory($positionTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertTrue($positionTagCategory->is($positionTagCategoryCache->create('name1', 'desc1', 'ref1'))); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $positionTagCategory = factory(PositionTagCategory::class)->create(); + + $positionTagCategoryRepository = $this->prophesize(PositionTagCategoryRepository::class); + $positionTagCategoryRepository->update($positionTagCategory->id(), 'name1', 'desc1', 'ref1')->shouldBeCalled()->willReturn($positionTagCategory); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\PositionTagCategory($positionTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertTrue($positionTagCategory->is($positionTagCategoryCache->update($positionTagCategory->id(), 'name1', 'desc1', 'ref1'))); + } + + /** @test */ + public function delete_does_not_save_in_the_cache() + { + $positionTagCategory = factory(PositionTagCategory::class)->create(); + + $positionTagCategoryRepository = $this->prophesize(PositionTagCategoryRepository::class); + $positionTagCategoryRepository->delete($positionTagCategory->id())->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\PositionTagCategory($positionTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertNull($positionTagCategoryCache->delete($positionTagCategory->id())); + } + + /** @test */ + public function getById_saves_tags_in_the_cache(){ + $positionTagCategory = factory(PositionTagCategory::class)->create(); + + $positionTagCategoryRepository = $this->prophesize(PositionTagCategoryRepository::class); + $positionTagCategoryRepository->getById($positionTagCategory->id())->shouldBeCalled()->willReturn($positionTagCategory); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\PositionTagCategory::class . '@getById:' . $positionTagCategory->id(); + + $positionTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\PositionTagCategory($positionTagCategoryRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($positionTagCategory->is($positionTagCategoryCache->getById($positionTagCategory->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($positionTagCategory->is($cache->get($key))); + } + + /** @test */ + public function getByReference_saves_tags_in_the_cache(){ + $positionTagCategory = factory(PositionTagCategory::class)->create(); + + $positionTagCategoryRepository = $this->prophesize(PositionTagCategoryRepository::class); + $positionTagCategoryRepository->getByReference('ref')->shouldBeCalled()->willReturn($positionTagCategory); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\PositionTagCategory::class . '@getByReference:ref'; + + $positionTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\PositionTagCategory($positionTagCategoryRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($positionTagCategory->is($positionTagCategoryCache->getByReference('ref'))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($positionTagCategory->is($cache->get($key))); + } + +} \ No newline at end of file diff --git a/tests/Integration/Cache/Tags/PositionTagTest.php b/tests/Integration/Cache/Tags/PositionTagTest.php new file mode 100644 index 0000000..dd5079d --- /dev/null +++ b/tests/Integration/Cache/Tags/PositionTagTest.php @@ -0,0 +1,144 @@ +create(); + + $positionTagRepository = $this->prophesize(PositionTagRepository::class); + $positionTagRepository->all()->shouldBeCalled()->willReturn($positionTags); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionTagCache = new \BristolSU\ControlDB\Cache\Tags\PositionTag($positionTagRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $positionTagCache->all()); + } + + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $positionTagCategory = factory(PositionTagCategory::class)->create(); + $positionTag = factory(PositionTag::class)->create(['tag_category_id' => $positionTagCategory->id()]); + + $positionTagRepository = $this->prophesize(PositionTagRepository::class); + $positionTagRepository->create('name1', 'desc1', 'ref1', $positionTagCategory->id())->shouldBeCalled()->willReturn($positionTag); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionTagCache = new \BristolSU\ControlDB\Cache\Tags\PositionTag($positionTagRepository->reveal(), $cache->reveal()); + + $this->assertTrue($positionTag->is($positionTagCache->create('name1', 'desc1', 'ref1', $positionTagCategory->id()))); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $positionTagCategory = factory(PositionTagCategory::class)->create(); + $positionTag = factory(PositionTag::class)->create(['tag_category_id' => $positionTagCategory->id()]); + + $positionTagRepository = $this->prophesize(PositionTagRepository::class); + $positionTagRepository->update($positionTag->id(), 'name1', 'desc1', 'ref1', $positionTagCategory->id())->shouldBeCalled()->willReturn($positionTag); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionTagCache = new \BristolSU\ControlDB\Cache\Tags\PositionTag($positionTagRepository->reveal(), $cache->reveal()); + + $this->assertTrue($positionTag->is($positionTagCache->update($positionTag->id(), 'name1', 'desc1', 'ref1', $positionTagCategory->id()))); + } + + /** @test */ + public function delete_does_not_save_in_the_cache() + { + $positionTagCategory = factory(PositionTagCategory::class)->create(); + $positionTag = factory(PositionTag::class)->create(['tag_category_id' => $positionTagCategory->id()]); + + $positionTagRepository = $this->prophesize(PositionTagRepository::class); + $positionTagRepository->delete($positionTag->id())->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $positionTagCache = new \BristolSU\ControlDB\Cache\Tags\PositionTag($positionTagRepository->reveal(), $cache->reveal()); + + $this->assertNull($positionTagCache->delete($positionTag->id())); + } + + /** @test */ + public function allThroughTagCategory_saves_tags_in_the_cache(){ + $tagCategory = factory(PositionTagCategory::class)->create(); + $positionTags = factory(PositionTag::class, 5)->create(['tag_category_id' => $tagCategory->id()]); + + $positionTagRepository = $this->prophesize(PositionTagRepository::class); + $positionTagRepository->allThroughTagCategory(Argument::that(function($arg) use ($tagCategory) { + return $arg instanceof PositionTagCategory && $arg->is($tagCategory); + }))->shouldBeCalled()->willReturn($positionTags); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\PositionTag::class . '@allThroughTagCategory:' . $tagCategory->id(); + + $positionTagCache = new \BristolSU\ControlDB\Cache\Tags\PositionTag($positionTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $positionTagCache->allThroughTagCategory($tagCategory)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(PositionTag::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + + } + + /** @test */ + public function getById_saves_tags_in_the_cache(){ + $positionTag = factory(PositionTag::class)->create(); + + $positionTagRepository = $this->prophesize(PositionTagRepository::class); + $positionTagRepository->getById($positionTag->id())->shouldBeCalled()->willReturn($positionTag); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\PositionTag::class . '@getById:' . $positionTag->id(); + + $positionTagCache = new \BristolSU\ControlDB\Cache\Tags\PositionTag($positionTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($positionTag->is($positionTagCache->getById($positionTag->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($positionTag->is($cache->get($key))); + } + + /** @test */ + public function getTagByFullReference_saves_tags_in_the_cache(){ + $positionTag = factory(PositionTag::class)->create(); + + $positionTagRepository = $this->prophesize(PositionTagRepository::class); + $positionTagRepository->getTagByFullReference('full.ref')->shouldBeCalled()->willReturn($positionTag); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\PositionTag::class . '@getTagByFullReference:full.ref'; + + $positionTagCache = new \BristolSU\ControlDB\Cache\Tags\PositionTag($positionTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($positionTag->is($positionTagCache->getTagByFullReference('full.ref'))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($positionTag->is($cache->get($key))); + } + +} \ No newline at end of file diff --git a/tests/Integration/Cache/Tags/RoleTagCategoryTest.php b/tests/Integration/Cache/Tags/RoleTagCategoryTest.php new file mode 100644 index 0000000..2384c20 --- /dev/null +++ b/tests/Integration/Cache/Tags/RoleTagCategoryTest.php @@ -0,0 +1,117 @@ +create(); + + $roleTagCategoryRepository = $this->prophesize(RoleTagCategoryRepository::class); + $roleTagCategoryRepository->all()->shouldBeCalled()->willReturn($roleTagCategories); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\RoleTagCategory($roleTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $roleTagCategoryCache->all()); + } + + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $roleTagCategory = factory(RoleTagCategory::class)->create(); + + $roleTagCategoryRepository = $this->prophesize(RoleTagCategoryRepository::class); + $roleTagCategoryRepository->create('name1', 'desc1', 'ref1')->shouldBeCalled()->willReturn($roleTagCategory); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\RoleTagCategory($roleTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertTrue($roleTagCategory->is($roleTagCategoryCache->create('name1', 'desc1', 'ref1'))); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $roleTagCategory = factory(RoleTagCategory::class)->create(); + + $roleTagCategoryRepository = $this->prophesize(RoleTagCategoryRepository::class); + $roleTagCategoryRepository->update($roleTagCategory->id(), 'name1', 'desc1', 'ref1')->shouldBeCalled()->willReturn($roleTagCategory); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\RoleTagCategory($roleTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertTrue($roleTagCategory->is($roleTagCategoryCache->update($roleTagCategory->id(), 'name1', 'desc1', 'ref1'))); + } + + /** @test */ + public function delete_does_not_save_in_the_cache() + { + $roleTagCategory = factory(RoleTagCategory::class)->create(); + + $roleTagCategoryRepository = $this->prophesize(RoleTagCategoryRepository::class); + $roleTagCategoryRepository->delete($roleTagCategory->id())->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\RoleTagCategory($roleTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertNull($roleTagCategoryCache->delete($roleTagCategory->id())); + } + + /** @test */ + public function getById_saves_tags_in_the_cache(){ + $roleTagCategory = factory(RoleTagCategory::class)->create(); + + $roleTagCategoryRepository = $this->prophesize(RoleTagCategoryRepository::class); + $roleTagCategoryRepository->getById($roleTagCategory->id())->shouldBeCalled()->willReturn($roleTagCategory); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\RoleTagCategory::class . '@getById:' . $roleTagCategory->id(); + + $roleTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\RoleTagCategory($roleTagCategoryRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($roleTagCategory->is($roleTagCategoryCache->getById($roleTagCategory->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($roleTagCategory->is($cache->get($key))); + } + + /** @test */ + public function getByReference_saves_tags_in_the_cache(){ + $roleTagCategory = factory(RoleTagCategory::class)->create(); + + $roleTagCategoryRepository = $this->prophesize(RoleTagCategoryRepository::class); + $roleTagCategoryRepository->getByReference('ref')->shouldBeCalled()->willReturn($roleTagCategory); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\RoleTagCategory::class . '@getByReference:ref'; + + $roleTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\RoleTagCategory($roleTagCategoryRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($roleTagCategory->is($roleTagCategoryCache->getByReference('ref'))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($roleTagCategory->is($cache->get($key))); + } + +} \ No newline at end of file diff --git a/tests/Integration/Cache/Tags/RoleTagTest.php b/tests/Integration/Cache/Tags/RoleTagTest.php new file mode 100644 index 0000000..54412d6 --- /dev/null +++ b/tests/Integration/Cache/Tags/RoleTagTest.php @@ -0,0 +1,144 @@ +create(); + + $roleTagRepository = $this->prophesize(RoleTagRepository::class); + $roleTagRepository->all()->shouldBeCalled()->willReturn($roleTags); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleTagCache = new \BristolSU\ControlDB\Cache\Tags\RoleTag($roleTagRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $roleTagCache->all()); + } + + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $roleTagCategory = factory(RoleTagCategory::class)->create(); + $roleTag = factory(RoleTag::class)->create(['tag_category_id' => $roleTagCategory->id()]); + + $roleTagRepository = $this->prophesize(RoleTagRepository::class); + $roleTagRepository->create('name1', 'desc1', 'ref1', $roleTagCategory->id())->shouldBeCalled()->willReturn($roleTag); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleTagCache = new \BristolSU\ControlDB\Cache\Tags\RoleTag($roleTagRepository->reveal(), $cache->reveal()); + + $this->assertTrue($roleTag->is($roleTagCache->create('name1', 'desc1', 'ref1', $roleTagCategory->id()))); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $roleTagCategory = factory(RoleTagCategory::class)->create(); + $roleTag = factory(RoleTag::class)->create(['tag_category_id' => $roleTagCategory->id()]); + + $roleTagRepository = $this->prophesize(RoleTagRepository::class); + $roleTagRepository->update($roleTag->id(), 'name1', 'desc1', 'ref1', $roleTagCategory->id())->shouldBeCalled()->willReturn($roleTag); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleTagCache = new \BristolSU\ControlDB\Cache\Tags\RoleTag($roleTagRepository->reveal(), $cache->reveal()); + + $this->assertTrue($roleTag->is($roleTagCache->update($roleTag->id(), 'name1', 'desc1', 'ref1', $roleTagCategory->id()))); + } + + /** @test */ + public function delete_does_not_save_in_the_cache() + { + $roleTagCategory = factory(RoleTagCategory::class)->create(); + $roleTag = factory(RoleTag::class)->create(['tag_category_id' => $roleTagCategory->id()]); + + $roleTagRepository = $this->prophesize(RoleTagRepository::class); + $roleTagRepository->delete($roleTag->id())->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $roleTagCache = new \BristolSU\ControlDB\Cache\Tags\RoleTag($roleTagRepository->reveal(), $cache->reveal()); + + $this->assertNull($roleTagCache->delete($roleTag->id())); + } + + /** @test */ + public function allThroughTagCategory_saves_tags_in_the_cache(){ + $tagCategory = factory(RoleTagCategory::class)->create(); + $roleTags = factory(RoleTag::class, 5)->create(['tag_category_id' => $tagCategory->id()]); + + $roleTagRepository = $this->prophesize(RoleTagRepository::class); + $roleTagRepository->allThroughTagCategory(Argument::that(function($arg) use ($tagCategory) { + return $arg instanceof RoleTagCategory && $arg->is($tagCategory); + }))->shouldBeCalled()->willReturn($roleTags); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\RoleTag::class . '@allThroughTagCategory:' . $tagCategory->id(); + + $roleTagCache = new \BristolSU\ControlDB\Cache\Tags\RoleTag($roleTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $roleTagCache->allThroughTagCategory($tagCategory)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(RoleTag::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + + } + + /** @test */ + public function getById_saves_tags_in_the_cache(){ + $roleTag = factory(RoleTag::class)->create(); + + $roleTagRepository = $this->prophesize(RoleTagRepository::class); + $roleTagRepository->getById($roleTag->id())->shouldBeCalled()->willReturn($roleTag); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\RoleTag::class . '@getById:' . $roleTag->id(); + + $roleTagCache = new \BristolSU\ControlDB\Cache\Tags\RoleTag($roleTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($roleTag->is($roleTagCache->getById($roleTag->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($roleTag->is($cache->get($key))); + } + + /** @test */ + public function getTagByFullReference_saves_tags_in_the_cache(){ + $roleTag = factory(RoleTag::class)->create(); + + $roleTagRepository = $this->prophesize(RoleTagRepository::class); + $roleTagRepository->getTagByFullReference('full.ref')->shouldBeCalled()->willReturn($roleTag); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\RoleTag::class . '@getTagByFullReference:full.ref'; + + $roleTagCache = new \BristolSU\ControlDB\Cache\Tags\RoleTag($roleTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($roleTag->is($roleTagCache->getTagByFullReference('full.ref'))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($roleTag->is($cache->get($key))); + } + +} \ No newline at end of file diff --git a/tests/Integration/Cache/Tags/UserTagCategoryTest.php b/tests/Integration/Cache/Tags/UserTagCategoryTest.php new file mode 100644 index 0000000..21093b4 --- /dev/null +++ b/tests/Integration/Cache/Tags/UserTagCategoryTest.php @@ -0,0 +1,117 @@ +create(); + + $userTagCategoryRepository = $this->prophesize(UserTagCategoryRepository::class); + $userTagCategoryRepository->all()->shouldBeCalled()->willReturn($userTagCategories); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\UserTagCategory($userTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $userTagCategoryCache->all()); + } + + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $userTagCategory = factory(UserTagCategory::class)->create(); + + $userTagCategoryRepository = $this->prophesize(UserTagCategoryRepository::class); + $userTagCategoryRepository->create('name1', 'desc1', 'ref1')->shouldBeCalled()->willReturn($userTagCategory); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\UserTagCategory($userTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertTrue($userTagCategory->is($userTagCategoryCache->create('name1', 'desc1', 'ref1'))); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $userTagCategory = factory(UserTagCategory::class)->create(); + + $userTagCategoryRepository = $this->prophesize(UserTagCategoryRepository::class); + $userTagCategoryRepository->update($userTagCategory->id(), 'name1', 'desc1', 'ref1')->shouldBeCalled()->willReturn($userTagCategory); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\UserTagCategory($userTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertTrue($userTagCategory->is($userTagCategoryCache->update($userTagCategory->id(), 'name1', 'desc1', 'ref1'))); + } + + /** @test */ + public function delete_does_not_save_in_the_cache() + { + $userTagCategory = factory(UserTagCategory::class)->create(); + + $userTagCategoryRepository = $this->prophesize(UserTagCategoryRepository::class); + $userTagCategoryRepository->delete($userTagCategory->id())->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\UserTagCategory($userTagCategoryRepository->reveal(), $cache->reveal()); + + $this->assertNull($userTagCategoryCache->delete($userTagCategory->id())); + } + + /** @test */ + public function getById_saves_tags_in_the_cache(){ + $userTagCategory = factory(UserTagCategory::class)->create(); + + $userTagCategoryRepository = $this->prophesize(UserTagCategoryRepository::class); + $userTagCategoryRepository->getById($userTagCategory->id())->shouldBeCalled()->willReturn($userTagCategory); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\UserTagCategory::class . '@getById:' . $userTagCategory->id(); + + $userTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\UserTagCategory($userTagCategoryRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($userTagCategory->is($userTagCategoryCache->getById($userTagCategory->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($userTagCategory->is($cache->get($key))); + } + + /** @test */ + public function getByReference_saves_tags_in_the_cache(){ + $userTagCategory = factory(UserTagCategory::class)->create(); + + $userTagCategoryRepository = $this->prophesize(UserTagCategoryRepository::class); + $userTagCategoryRepository->getByReference('ref')->shouldBeCalled()->willReturn($userTagCategory); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\UserTagCategory::class . '@getByReference:ref'; + + $userTagCategoryCache = new \BristolSU\ControlDB\Cache\Tags\UserTagCategory($userTagCategoryRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($userTagCategory->is($userTagCategoryCache->getByReference('ref'))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($userTagCategory->is($cache->get($key))); + } + +} \ No newline at end of file diff --git a/tests/Integration/Cache/Tags/UserTagTest.php b/tests/Integration/Cache/Tags/UserTagTest.php new file mode 100644 index 0000000..f5f2fda --- /dev/null +++ b/tests/Integration/Cache/Tags/UserTagTest.php @@ -0,0 +1,144 @@ +create(); + + $userTagRepository = $this->prophesize(UserTagRepository::class); + $userTagRepository->all()->shouldBeCalled()->willReturn($userTags); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userTagCache = new \BristolSU\ControlDB\Cache\Tags\UserTag($userTagRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $userTagCache->all()); + } + + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $userTagCategory = factory(UserTagCategory::class)->create(); + $userTag = factory(UserTag::class)->create(['tag_category_id' => $userTagCategory->id()]); + + $userTagRepository = $this->prophesize(UserTagRepository::class); + $userTagRepository->create('name1', 'desc1', 'ref1', $userTagCategory->id())->shouldBeCalled()->willReturn($userTag); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userTagCache = new \BristolSU\ControlDB\Cache\Tags\UserTag($userTagRepository->reveal(), $cache->reveal()); + + $this->assertTrue($userTag->is($userTagCache->create('name1', 'desc1', 'ref1', $userTagCategory->id()))); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $userTagCategory = factory(UserTagCategory::class)->create(); + $userTag = factory(UserTag::class)->create(['tag_category_id' => $userTagCategory->id()]); + + $userTagRepository = $this->prophesize(UserTagRepository::class); + $userTagRepository->update($userTag->id(), 'name1', 'desc1', 'ref1', $userTagCategory->id())->shouldBeCalled()->willReturn($userTag); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userTagCache = new \BristolSU\ControlDB\Cache\Tags\UserTag($userTagRepository->reveal(), $cache->reveal()); + + $this->assertTrue($userTag->is($userTagCache->update($userTag->id(), 'name1', 'desc1', 'ref1', $userTagCategory->id()))); + } + + /** @test */ + public function delete_does_not_save_in_the_cache() + { + $userTagCategory = factory(UserTagCategory::class)->create(); + $userTag = factory(UserTag::class)->create(['tag_category_id' => $userTagCategory->id()]); + + $userTagRepository = $this->prophesize(UserTagRepository::class); + $userTagRepository->delete($userTag->id())->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userTagCache = new \BristolSU\ControlDB\Cache\Tags\UserTag($userTagRepository->reveal(), $cache->reveal()); + + $this->assertNull($userTagCache->delete($userTag->id())); + } + + /** @test */ + public function allThroughTagCategory_saves_tags_in_the_cache(){ + $tagCategory = factory(UserTagCategory::class)->create(); + $userTags = factory(UserTag::class, 5)->create(['tag_category_id' => $tagCategory->id()]); + + $userTagRepository = $this->prophesize(UserTagRepository::class); + $userTagRepository->allThroughTagCategory(Argument::that(function($arg) use ($tagCategory) { + return $arg instanceof UserTagCategory && $arg->is($tagCategory); + }))->shouldBeCalled()->willReturn($userTags); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\UserTag::class . '@allThroughTagCategory:' . $tagCategory->id(); + + $userTagCache = new \BristolSU\ControlDB\Cache\Tags\UserTag($userTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertCount(5, $userTagCache->allThroughTagCategory($tagCategory)); + $this->assertTrue($cache->has($key)); + $this->assertInstanceOf(Collection::class, $cache->get($key)); + $this->assertContainsOnlyInstancesOf(UserTag::class, $cache->get($key)); + $this->assertCount(5, $cache->get($key)); + + } + + /** @test */ + public function getById_saves_tags_in_the_cache(){ + $userTag = factory(UserTag::class)->create(); + + $userTagRepository = $this->prophesize(UserTagRepository::class); + $userTagRepository->getById($userTag->id())->shouldBeCalled()->willReturn($userTag); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\UserTag::class . '@getById:' . $userTag->id(); + + $userTagCache = new \BristolSU\ControlDB\Cache\Tags\UserTag($userTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($userTag->is($userTagCache->getById($userTag->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($userTag->is($cache->get($key))); + } + + /** @test */ + public function getTagByFullReference_saves_tags_in_the_cache(){ + $userTag = factory(UserTag::class)->create(); + + $userTagRepository = $this->prophesize(UserTagRepository::class); + $userTagRepository->getTagByFullReference('full.ref')->shouldBeCalled()->willReturn($userTag); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\Tags\UserTag::class . '@getTagByFullReference:full.ref'; + + $userTagCache = new \BristolSU\ControlDB\Cache\Tags\UserTag($userTagRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($userTag->is($userTagCache->getTagByFullReference('full.ref'))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($userTag->is($cache->get($key))); + } + +} \ No newline at end of file diff --git a/tests/Integration/Cache/UserTest.php b/tests/Integration/Cache/UserTest.php new file mode 100644 index 0000000..29c87a6 --- /dev/null +++ b/tests/Integration/Cache/UserTest.php @@ -0,0 +1,135 @@ +create(); + + $userRepository = $this->prophesize(UserRepository::class); + $userRepository->getById($user->id())->shouldBeCalled()->willReturn($user); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\User::class . '@getById:' . $user->id(); + + $userCache = new \BristolSU\ControlDB\Cache\User($userRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($user->is($userCache->getById($user->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($user->is($cache->get($key))); + } + + /** @test */ + public function getByDataProviderId_saves_the_user_in_the_cache(){ + $dataProvider = factory(DataUser::class)->create(); + $user = factory(User::class)->create(['data_provider_id' => $dataProvider->id()]); + + $userRepository = $this->prophesize(UserRepository::class); + $userRepository->getByDataProviderId($user->id())->shouldBeCalled()->willReturn($user); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\User::class . '@getByDataProviderId:' . $dataProvider->id(); + + $userCache = new \BristolSU\ControlDB\Cache\User($userRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertTrue($user->is($userCache->getByDataProviderId($dataProvider->id()))); + $this->assertTrue($cache->has($key)); + $this->assertTrue($user->is($cache->get($key))); + } + + + /** @test */ + public function create_does_not_save_in_the_cache() + { + $dataProvider = factory(DataUser::class)->create(); + $user = factory(User::class)->create(['data_provider_id' => $dataProvider->id()]); + + $userRepository = $this->prophesize(UserRepository::class); + $userRepository->create($dataProvider->id())->shouldBeCalled()->willReturn($user); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userCache = new \BristolSU\ControlDB\Cache\User($userRepository->reveal(), $cache->reveal()); + + $this->assertTrue($user->is($userCache->create($dataProvider->id()))); + } + + /** @test */ + public function delete_does_not_save_in_the_cache() + { + $user = factory(User::class)->create(); + + $userRepository = $this->prophesize(UserRepository::class); + $userRepository->delete($user->id())->shouldBeCalled(); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userCache = new \BristolSU\ControlDB\Cache\User($userRepository->reveal(), $cache->reveal()); + + $this->assertNull($userCache->delete($user->id())); + } + + /** @test */ + public function paginate_does_not_save_in_the_cache() + { + $users = factory(User::class, 5)->create(); + + $userRepository = $this->prophesize(UserRepository::class); + $userRepository->paginate(1, 2)->shouldBeCalled()->willReturn($users); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userCache = new \BristolSU\ControlDB\Cache\User($userRepository->reveal(), $cache->reveal()); + + $this->assertCount(5, $userCache->paginate(1, 2)); + } + + /** @test */ + public function update_does_not_save_in_the_cache() + { + $dataProvider = factory(DataUser::class)->create(); + $user = factory(User::class)->create(['data_provider_id' => $dataProvider->id()]); + + $userRepository = $this->prophesize(UserRepository::class); + $userRepository->update($user->id(), $dataProvider->id())->shouldBeCalled()->willReturn($user); + + $cache = $this->prophesize(Repository::class); + $cache->rememberForever(Argument::any(), Argument::any())->shouldNotBeCalled(); + + $userCache = new \BristolSU\ControlDB\Cache\User($userRepository->reveal(), $cache->reveal()); + + $this->assertTrue($user->is($userCache->update($user->id(), $dataProvider->id()))); + } + + /** @test */ + public function count_saves_the_count_in_the_cache(){ + $userRepository = $this->prophesize(UserRepository::class); + $userRepository->count()->shouldBeCalled()->willReturn(19); + + $cache = app(Repository::class); + $key = \BristolSU\ControlDB\Cache\User::class . '@count'; + + $userCache = new \BristolSU\ControlDB\Cache\User($userRepository->reveal(), $cache); + + $this->assertFalse($cache->has($key)); + $this->assertEquals(19, $userCache->count()); + $this->assertTrue($cache->has($key)); + $this->assertEquals(19, $cache->get($key)); + } + +} \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php index e9c000d..0e5d149 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,11 +6,11 @@ use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\TestResponse; use Orchestra\Testbench\TestCase as BaseTestCase; +use Prophecy\PhpUnit\ProphecyTrait; abstract class TestCase extends BaseTestCase { - - use DatabaseTransactions; + use DatabaseTransactions, ProphecyTrait; public $apiUrl = 'api/control'; diff --git a/tests/Unit/Observers/NotifyObservers/Framework/NotifierTest.php b/tests/Unit/Observers/NotifyObservers/Framework/NotifierTest.php new file mode 100644 index 0000000..232c09b --- /dev/null +++ b/tests/Unit/Observers/NotifyObservers/Framework/NotifierTest.php @@ -0,0 +1,74 @@ +prophesize(ObserverStore::class); + $store->attach('Notifier1', 'Observer1')->shouldBeCalled(); + $store->attach('Notifier1', 'Observer2')->shouldBeCalled(); + + $notifier = new Notifier($store->reveal(), 'Notifier1'); + + $notifier->attach('Observer1'); + $notifier->attach('Observer2'); + } + + /** @test */ + public function detach_detaches_from_the_underlying_store(){ + $store = $this->prophesize(ObserverStore::class); + $store->detach('Notifier1', 'Observer1')->shouldBeCalled(); + $store->detach('Notifier1', 'Observer2')->shouldBeCalled(); + + $notifier = new Notifier($store->reveal(), 'Notifier1'); + + $notifier->detach('Observer1'); + $notifier->detach('Observer2'); + } + + /** @test */ + public function notify_calls_the_correct_function_if_exists_on_each_observer(){ + $store = $this->prophesize(ObserverStore::class); + $store->forNotifier('Notifier1')->shouldBeCalled()->willReturn([ + Obs1::class, Obs2::class + ]); + + $notifier = new Notifier($store->reveal(), 'Notifier1'); + + $notifier->notify('testMethod', 'param1', 'param2'); + } + +} + +class Obs1 { + + public $param1; + + public $param2; + + public $count = 0; + + public function testMethod($param1, $param2) + { + $this->count++; + Assert::assertEquals('param1', $param1); + Assert::assertEquals('param2', $param2); + } + + public function __destruct() + { + Assert::assertEquals(1, $this->count); + } + +} + +class Obs2 { +} \ No newline at end of file diff --git a/tests/Unit/Observers/NotifyObservers/Framework/ObserveTest.php b/tests/Unit/Observers/NotifyObservers/Framework/ObserveTest.php new file mode 100644 index 0000000..744e4fd --- /dev/null +++ b/tests/Unit/Observers/NotifyObservers/Framework/ObserveTest.php @@ -0,0 +1,22 @@ +prophesize(ObserverStore::class); + $observerStore->attach('one', 'two')->shouldBeCalled(); + $this->instance(ObserverStore::class, $observerStore->reveal()); + + Observe::clearResolvedInstances(); + Observe::attach('one', 'two'); + } + +} \ No newline at end of file diff --git a/tests/Unit/Observers/NotifyObservers/Framework/ObserverStoreTest.php b/tests/Unit/Observers/NotifyObservers/Framework/ObserverStoreTest.php new file mode 100644 index 0000000..64c9f48 --- /dev/null +++ b/tests/Unit/Observers/NotifyObservers/Framework/ObserverStoreTest.php @@ -0,0 +1,88 @@ +attach('notifier1', $observer1); + $observerStore->attach('notifier1', $observer2); + $observerStore->attach('notifier1', $observer3); + $observerStore->attach('notifier2', $observer4); + $observerStore->attach('notifier2', $observer5); + + $this->assertEquals([ + 'Observer1', 'Observer2', 'Observer3' + ], $observerStore->forNotifier('notifier1')); + $this->assertEquals([ + 'Observer4', 'Observer5' + ], $observerStore->forNotifier('notifier2')); + } + + /** @test */ + public function observers_can_be_detached(){ + $observer1 = 'Observer1'; + $observer2 = 'Observer2'; + $observer3 = 'Observer3'; + $observer4 = 'Observer4'; + $observer5 = 'Observer5'; + + $observerStore = new ObserverStore(); + $observerStore->attach('notifier1', $observer1); + $observerStore->attach('notifier1', $observer2); + $observerStore->attach('notifier1', $observer3); + $observerStore->attach('notifier2', $observer4); + $observerStore->attach('notifier2', $observer5); + + $this->assertEquals([ + 'Observer1', 'Observer2', 'Observer3' + ], $observerStore->forNotifier('notifier1')); + $this->assertEquals([ + 'Observer4', 'Observer5' + ], $observerStore->forNotifier('notifier2')); + + $observerStore->detach('notifier1', $observer1); + $observerStore->detach('notifier1', $observer3); + $observerStore->detach('notifier2', $observer5); + + $this->assertEquals([ + 'Observer2' + ], $observerStore->forNotifier('notifier1')); + $this->assertEquals([ + 'Observer4' + ], $observerStore->forNotifier('notifier2')); + } + + /** @test */ + public function the_store_is_a_singleton(){ + $observer1 = 'Observer1'; + $observer2 = 'Observer2'; + + $observerStore = app(ObserverStore::class); + $observerStore->attach('notifier1', $observer1); + $observerStore->attach('notifier1', $observer2); + + $this->assertEquals([ + 'Observer1', 'Observer2' + ], $observerStore->forNotifier('notifier1')); + + $this->assertEquals([ + 'Observer1', 'Observer2' + ], app(ObserverStore::class)->forNotifier('notifier1')); + } + + + +} \ No newline at end of file diff --git a/tests/Unit/Repositories/Tags/GroupTagCategoryTest.php b/tests/Unit/Repositories/Tags/GroupTagCategoryTest.php index 1ed6dce..526cc0d 100644 --- a/tests/Unit/Repositories/Tags/GroupTagCategoryTest.php +++ b/tests/Unit/Repositories/Tags/GroupTagCategoryTest.php @@ -93,4 +93,58 @@ public function delete_deletes_a_group_tag_category_model(){ $this->assertTrue($groupTagCategory->trashed()); } + /** @test */ + public function update_updates_a_group_tag_category() + { + $groupTagCategory = factory(GroupTagCategory::class)->create([ + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + ]); + $this->assertDatabaseHas('control_tag_categories', [ + 'id' => $groupTagCategory->id(), + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + 'type' => 'group' + ]); + $repository = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $repository->update($groupTagCategory->id(), 'TagCategoryName2', 'TagCategoryDesc2', 'ref2'); + $this->assertDatabaseMissing('control_tag_categories', [ + 'id' => $groupTagCategory->id(), + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + 'type' => 'group' + ]); + $this->assertDatabaseHas('control_tag_categories', [ + 'id' => $groupTagCategory->id(), + 'name' => 'TagCategoryName2', + 'description' => 'TagCategoryDesc2', + 'reference' => 'ref2', + 'type' => 'group' + ]); + + } + + /** @test */ + public function update_returns_the_updated_group_tag_category() + { + $groupTagCategory = factory(GroupTagCategory::class)->create([ + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + ]); + $this->assertEquals('TagCategoryName', $groupTagCategory->name()); + $this->assertEquals('TagCategoryDesc', $groupTagCategory->description()); + $this->assertEquals('ref', $groupTagCategory->reference()); + + $repository = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $updatedGroupTagCategory = $repository->update($groupTagCategory->id(), 'TagCategoryName2', 'TagCategoryDesc2', 'ref2'); + + $this->assertEquals('TagCategoryName2', $updatedGroupTagCategory->name()); + $this->assertEquals('TagCategoryDesc2', $updatedGroupTagCategory->description()); + $this->assertEquals('ref2', $updatedGroupTagCategory->reference()); + + } } diff --git a/tests/Unit/Repositories/Tags/GroupTagTest.php b/tests/Unit/Repositories/Tags/GroupTagTest.php index e03d37d..25e5174 100644 --- a/tests/Unit/Repositories/Tags/GroupTagTest.php +++ b/tests/Unit/Repositories/Tags/GroupTagTest.php @@ -17,7 +17,7 @@ class GroupTagTest extends TestCase /** @test */ public function getById_returns_a_group_tag_model_with_the_corresponding_id(){ $groupTag = factory(GroupTag::class)->create(['id' => 2]); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); $this->assertTrue( $groupTag->is($groupTagRepo->getById(2)) ); @@ -26,14 +26,14 @@ public function getById_returns_a_group_tag_model_with_the_corresponding_id(){ /** @test */ public function getById_throws_a_modelNotFoundException_if_group_tag_does_not_exist(){ $this->expectException(ModelNotFoundException::class); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); $groupTagRepo->getById(5); } /** @test */ public function all_returns_all_group_tags(){ $groupTags = factory(GroupTag::class, 15)->create(); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); $allTags = $groupTagRepo->all(); $this->assertInstanceOf(Collection::class, $allTags); foreach($groupTags as $groupTag) { @@ -48,7 +48,7 @@ public function getTagByFullReference_returns_a_tag_given_the_full_reference(){ $groupTagCategory = factory(GroupTagCategory::class)->create(['reference' => 'ref1']); $groupTag = factory(GroupTag::class)->create(['reference' => 'ref2', 'tag_category_id' => $groupTagCategory->id]); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); $groupTagFromRepo = $groupTagRepo->getTagByFullReference('ref1.ref2'); $this->assertInstanceOf(GroupTag::class, $groupTagFromRepo); $this->assertTrue($groupTag->is($groupTagFromRepo)); @@ -58,14 +58,14 @@ public function getTagByFullReference_returns_a_tag_given_the_full_reference(){ /** @test */ public function getTagByFullReference_throws_an_exception_if_group_tag_not_found(){ $this->expectException(ModelNotFoundException::class); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); $groupTagRepo->getTagByFullReference('nota.validref'); } /** @test */ public function create_creates_a_group_tag_model(){ - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); $groupTagRepo->create('Name', 'Description', 'reference', 1); $this->assertDatabaseHas('control_tags', [ @@ -78,7 +78,7 @@ public function create_creates_a_group_tag_model(){ /** @test */ public function create_returns_a_group_tag_model(){ - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); $groupTag = $groupTagRepo->create('Name', 'Description', 'reference', 1); $this->assertInstanceOf(GroupTag::class, $groupTag); @@ -91,7 +91,7 @@ public function create_returns_a_group_tag_model(){ /** @test */ public function delete_deletes_a_group_tag_model(){ $groupTag = factory(GroupTag::class)->create(); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); $groupTagRepo->delete($groupTag->id()); $groupTag->refresh(); @@ -104,7 +104,7 @@ public function allThroughTagCategory_returns_all_tags_through_a_tag_category(){ $tags = factory(GroupTag::class, 10)->create(['tag_category_id' => $category->id()]); factory(GroupTag::class, 10)->create(); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); $tagsFromRepo = $groupTagRepo->allThroughTagCategory($category); $this->assertContainsOnlyInstancesOf(GroupTag::class, $tagsFromRepo); foreach($tags as $tag) { @@ -114,4 +114,66 @@ public function allThroughTagCategory_returns_all_tags_through_a_tag_category(){ } } + /** @test */ + public function update_updates_a_group_tag_category() + { + $oldTagCategory = factory(GroupTagCategory::class)->create(); + $newTagCategory = factory(GroupTagCategory::class)->create(); + $groupTag = factory(GroupTag::class)->create([ + 'name' => 'TagName', + 'description' => 'TagDesc', + 'reference' => 'ref', + 'tag_category_id' => $oldTagCategory->id + ]); + $this->assertDatabaseHas('control_tags', [ + 'id' => $groupTag->id(), + 'name' => 'TagName', + 'description' => 'TagDesc', + 'reference' => 'ref', + 'tag_category_id' => (string) $oldTagCategory->id, + ]); + $repository = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $repository->update($groupTag->id(), 'TagName2', 'TagDesc2', 'ref2', $newTagCategory->id()); + $this->assertDatabaseMissing('control_tags', [ + 'id' => $groupTag->id(), + 'name' => 'TagName', + 'description' => 'TagDesc', + 'reference' => 'ref', + 'tag_category_id' => (string) $oldTagCategory->id, + ]); + $this->assertDatabaseHas('control_tags', [ + 'id' => $groupTag->id(), + 'name' => 'TagName2', + 'description' => 'TagDesc2', + 'reference' => 'ref2', + 'tag_category_id' => (string) $newTagCategory->id, + ]); + + } + + /** @test */ + public function update_returns_the_updated_group_tag_category() + { + $oldTagCategory = factory(GroupTagCategory::class)->create(); + $newTagCategory = factory(GroupTagCategory::class)->create(); + $groupTag = factory(GroupTag::class)->create([ + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + 'tag_category_id' => $oldTagCategory->id() + ]); + $this->assertEquals('TagCategoryName', $groupTag->name()); + $this->assertEquals('TagCategoryDesc', $groupTag->description()); + $this->assertEquals('ref', $groupTag->reference()); + $this->assertEquals($oldTagCategory->id(), $groupTag->categoryId()); + + $repository = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $updatedGroupTag = $repository->update($groupTag->id(), 'TagCategoryName2', 'TagCategoryDesc2', 'ref2', $newTagCategory->id()); + + $this->assertEquals('TagCategoryName2', $updatedGroupTag->name()); + $this->assertEquals('TagCategoryDesc2', $updatedGroupTag->description()); + $this->assertEquals('ref2', $updatedGroupTag->reference()); + $this->assertEquals($newTagCategory->id(), $updatedGroupTag->categoryId()); + } + } diff --git a/tests/Unit/Repositories/Tags/PositionTagCategoryTest.php b/tests/Unit/Repositories/Tags/PositionTagCategoryTest.php index ce57fc3..b957e35 100644 --- a/tests/Unit/Repositories/Tags/PositionTagCategoryTest.php +++ b/tests/Unit/Repositories/Tags/PositionTagCategoryTest.php @@ -92,5 +92,60 @@ public function delete_deletes_a_position_tag_category_model(){ $this->assertTrue($positionTagCategory->trashed()); } + /** @test */ + public function update_updates_a_position_tag_category() + { + $positionTagCategory = factory(PositionTagCategory::class)->create([ + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + ]); + $this->assertDatabaseHas('control_tag_categories', [ + 'id' => $positionTagCategory->id(), + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + 'type' => 'position' + ]); + $repository = new \BristolSU\ControlDB\Repositories\Tags\PositionTagCategory(); + $repository->update($positionTagCategory->id(), 'TagCategoryName2', 'TagCategoryDesc2', 'ref2'); + $this->assertDatabaseMissing('control_tag_categories', [ + 'id' => $positionTagCategory->id(), + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + 'type' => 'position' + ]); + $this->assertDatabaseHas('control_tag_categories', [ + 'id' => $positionTagCategory->id(), + 'name' => 'TagCategoryName2', + 'description' => 'TagCategoryDesc2', + 'reference' => 'ref2', + 'type' => 'position' + ]); + + } + + /** @test */ + public function update_returns_the_updated_position_tag_category() + { + $positionTagCategory = factory(PositionTagCategory::class)->create([ + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + ]); + $this->assertEquals('TagCategoryName', $positionTagCategory->name()); + $this->assertEquals('TagCategoryDesc', $positionTagCategory->description()); + $this->assertEquals('ref', $positionTagCategory->reference()); + + $repository = new \BristolSU\ControlDB\Repositories\Tags\PositionTagCategory(); + $updatedPositionTagCategory = $repository->update($positionTagCategory->id(), 'TagCategoryName2', 'TagCategoryDesc2', 'ref2'); + + $this->assertEquals('TagCategoryName2', $updatedPositionTagCategory->name()); + $this->assertEquals('TagCategoryDesc2', $updatedPositionTagCategory->description()); + $this->assertEquals('ref2', $updatedPositionTagCategory->reference()); + + } + } diff --git a/tests/Unit/Repositories/Tags/PositionTagTest.php b/tests/Unit/Repositories/Tags/PositionTagTest.php index 17bc373..027a41e 100644 --- a/tests/Unit/Repositories/Tags/PositionTagTest.php +++ b/tests/Unit/Repositories/Tags/PositionTagTest.php @@ -112,4 +112,66 @@ public function allThroughTagCategory_returns_all_tags_through_a_tag_category(){ )); } } + + /** @test */ + public function update_updates_a_position_tag_category() + { + $oldTagCategory = factory(PositionTagCategory::class)->create(); + $newTagCategory = factory(PositionTagCategory::class)->create(); + $positionTag = factory(PositionTag::class)->create([ + 'name' => 'TagName', + 'description' => 'TagDesc', + 'reference' => 'ref', + 'tag_category_id' => $oldTagCategory->id + ]); + $this->assertDatabaseHas('control_tags', [ + 'id' => $positionTag->id(), + 'name' => 'TagName', + 'description' => 'TagDesc', + 'reference' => 'ref', + 'tag_category_id' => (string) $oldTagCategory->id, + ]); + $repository = new \BristolSU\ControlDB\Repositories\Tags\PositionTag(); + $repository->update($positionTag->id(), 'TagName2', 'TagDesc2', 'ref2', $newTagCategory->id()); + $this->assertDatabaseMissing('control_tags', [ + 'id' => $positionTag->id(), + 'name' => 'TagName', + 'description' => 'TagDesc', + 'reference' => 'ref', + 'tag_category_id' => (string) $oldTagCategory->id, + ]); + $this->assertDatabaseHas('control_tags', [ + 'id' => $positionTag->id(), + 'name' => 'TagName2', + 'description' => 'TagDesc2', + 'reference' => 'ref2', + 'tag_category_id' => (string) $newTagCategory->id, + ]); + + } + + /** @test */ + public function update_returns_the_updated_position_tag_category() + { + $oldTagCategory = factory(PositionTagCategory::class)->create(); + $newTagCategory = factory(PositionTagCategory::class)->create(); + $positionTag = factory(PositionTag::class)->create([ + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + 'tag_category_id' => $oldTagCategory->id() + ]); + $this->assertEquals('TagCategoryName', $positionTag->name()); + $this->assertEquals('TagCategoryDesc', $positionTag->description()); + $this->assertEquals('ref', $positionTag->reference()); + $this->assertEquals($oldTagCategory->id(), $positionTag->categoryId()); + + $repository = new \BristolSU\ControlDB\Repositories\Tags\PositionTag(); + $updatedPositionTag = $repository->update($positionTag->id(), 'TagCategoryName2', 'TagCategoryDesc2', 'ref2', $newTagCategory->id()); + + $this->assertEquals('TagCategoryName2', $updatedPositionTag->name()); + $this->assertEquals('TagCategoryDesc2', $updatedPositionTag->description()); + $this->assertEquals('ref2', $updatedPositionTag->reference()); + $this->assertEquals($newTagCategory->id(), $updatedPositionTag->categoryId()); + } } diff --git a/tests/Unit/Repositories/Tags/RoleTagCategoryTest.php b/tests/Unit/Repositories/Tags/RoleTagCategoryTest.php index 058896b..1f5cc52 100644 --- a/tests/Unit/Repositories/Tags/RoleTagCategoryTest.php +++ b/tests/Unit/Repositories/Tags/RoleTagCategoryTest.php @@ -92,4 +92,58 @@ public function delete_deletes_a_role_tag_category_model(){ $this->assertTrue($roleTagCategory->trashed()); } + /** @test */ + public function update_updates_a_role_tag_category() + { + $roleTagCategory = factory(RoleTagCategory::class)->create([ + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + ]); + $this->assertDatabaseHas('control_tag_categories', [ + 'id' => $roleTagCategory->id(), + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + 'type' => 'role' + ]); + $repository = new \BristolSU\ControlDB\Repositories\Tags\RoleTagCategory(); + $repository->update($roleTagCategory->id(), 'TagCategoryName2', 'TagCategoryDesc2', 'ref2'); + $this->assertDatabaseMissing('control_tag_categories', [ + 'id' => $roleTagCategory->id(), + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + 'type' => 'role' + ]); + $this->assertDatabaseHas('control_tag_categories', [ + 'id' => $roleTagCategory->id(), + 'name' => 'TagCategoryName2', + 'description' => 'TagCategoryDesc2', + 'reference' => 'ref2', + 'type' => 'role' + ]); + + } + + /** @test */ + public function update_returns_the_updated_role_tag_category() + { + $roleTagCategory = factory(RoleTagCategory::class)->create([ + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + ]); + $this->assertEquals('TagCategoryName', $roleTagCategory->name()); + $this->assertEquals('TagCategoryDesc', $roleTagCategory->description()); + $this->assertEquals('ref', $roleTagCategory->reference()); + + $repository = new \BristolSU\ControlDB\Repositories\Tags\RoleTagCategory(); + $updatedRoleTagCategory = $repository->update($roleTagCategory->id(), 'TagCategoryName2', 'TagCategoryDesc2', 'ref2'); + + $this->assertEquals('TagCategoryName2', $updatedRoleTagCategory->name()); + $this->assertEquals('TagCategoryDesc2', $updatedRoleTagCategory->description()); + $this->assertEquals('ref2', $updatedRoleTagCategory->reference()); + + } } diff --git a/tests/Unit/Repositories/Tags/RoleTagTest.php b/tests/Unit/Repositories/Tags/RoleTagTest.php index 292a3cf..32f93e6 100644 --- a/tests/Unit/Repositories/Tags/RoleTagTest.php +++ b/tests/Unit/Repositories/Tags/RoleTagTest.php @@ -110,4 +110,66 @@ public function allThroughTagCategory_returns_all_tags_through_a_tag_category(){ )); } } + + /** @test */ + public function update_updates_a_role_tag_category() + { + $oldTagCategory = factory(RoleTagCategory::class)->create(); + $newTagCategory = factory(RoleTagCategory::class)->create(); + $roleTag = factory(RoleTag::class)->create([ + 'name' => 'TagName', + 'description' => 'TagDesc', + 'reference' => 'ref', + 'tag_category_id' => $oldTagCategory->id + ]); + $this->assertDatabaseHas('control_tags', [ + 'id' => $roleTag->id(), + 'name' => 'TagName', + 'description' => 'TagDesc', + 'reference' => 'ref', + 'tag_category_id' => (string) $oldTagCategory->id, + ]); + $repository = new \BristolSU\ControlDB\Repositories\Tags\RoleTag(); + $repository->update($roleTag->id(), 'TagName2', 'TagDesc2', 'ref2', $newTagCategory->id()); + $this->assertDatabaseMissing('control_tags', [ + 'id' => $roleTag->id(), + 'name' => 'TagName', + 'description' => 'TagDesc', + 'reference' => 'ref', + 'tag_category_id' => (string) $oldTagCategory->id, + ]); + $this->assertDatabaseHas('control_tags', [ + 'id' => $roleTag->id(), + 'name' => 'TagName2', + 'description' => 'TagDesc2', + 'reference' => 'ref2', + 'tag_category_id' => (string) $newTagCategory->id, + ]); + + } + + /** @test */ + public function update_returns_the_updated_role_tag_category() + { + $oldTagCategory = factory(RoleTagCategory::class)->create(); + $newTagCategory = factory(RoleTagCategory::class)->create(); + $roleTag = factory(RoleTag::class)->create([ + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + 'tag_category_id' => $oldTagCategory->id() + ]); + $this->assertEquals('TagCategoryName', $roleTag->name()); + $this->assertEquals('TagCategoryDesc', $roleTag->description()); + $this->assertEquals('ref', $roleTag->reference()); + $this->assertEquals($oldTagCategory->id(), $roleTag->categoryId()); + + $repository = new \BristolSU\ControlDB\Repositories\Tags\RoleTag(); + $updatedRoleTag = $repository->update($roleTag->id(), 'TagCategoryName2', 'TagCategoryDesc2', 'ref2', $newTagCategory->id()); + + $this->assertEquals('TagCategoryName2', $updatedRoleTag->name()); + $this->assertEquals('TagCategoryDesc2', $updatedRoleTag->description()); + $this->assertEquals('ref2', $updatedRoleTag->reference()); + $this->assertEquals($newTagCategory->id(), $updatedRoleTag->categoryId()); + } } diff --git a/tests/Unit/Repositories/Tags/UserTagCategoryTest.php b/tests/Unit/Repositories/Tags/UserTagCategoryTest.php index 22aba8c..4e36117 100644 --- a/tests/Unit/Repositories/Tags/UserTagCategoryTest.php +++ b/tests/Unit/Repositories/Tags/UserTagCategoryTest.php @@ -92,5 +92,59 @@ public function delete_deletes_a_user_tag_category_model(){ $this->assertTrue($userTagCategory->trashed()); } + /** @test */ + public function update_updates_a_user_tag_category() + { + $userTagCategory = factory(UserTagCategory::class)->create([ + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + ]); + $this->assertDatabaseHas('control_tag_categories', [ + 'id' => $userTagCategory->id(), + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + 'type' => 'user' + ]); + $repository = new \BristolSU\ControlDB\Repositories\Tags\UserTagCategory(); + $repository->update($userTagCategory->id(), 'TagCategoryName2', 'TagCategoryDesc2', 'ref2'); + $this->assertDatabaseMissing('control_tag_categories', [ + 'id' => $userTagCategory->id(), + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + 'type' => 'user' + ]); + $this->assertDatabaseHas('control_tag_categories', [ + 'id' => $userTagCategory->id(), + 'name' => 'TagCategoryName2', + 'description' => 'TagCategoryDesc2', + 'reference' => 'ref2', + 'type' => 'user' + ]); + + } + + /** @test */ + public function update_returns_the_updated_user_tag_category() + { + $userTagCategory = factory(UserTagCategory::class)->create([ + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + ]); + $this->assertEquals('TagCategoryName', $userTagCategory->name()); + $this->assertEquals('TagCategoryDesc', $userTagCategory->description()); + $this->assertEquals('ref', $userTagCategory->reference()); + + $repository = new \BristolSU\ControlDB\Repositories\Tags\UserTagCategory(); + $updatedUserTagCategory = $repository->update($userTagCategory->id(), 'TagCategoryName2', 'TagCategoryDesc2', 'ref2'); + + $this->assertEquals('TagCategoryName2', $updatedUserTagCategory->name()); + $this->assertEquals('TagCategoryDesc2', $updatedUserTagCategory->description()); + $this->assertEquals('ref2', $updatedUserTagCategory->reference()); + + } } diff --git a/tests/Unit/Repositories/Tags/UserTagTest.php b/tests/Unit/Repositories/Tags/UserTagTest.php index 1a49401..9b1520f 100644 --- a/tests/Unit/Repositories/Tags/UserTagTest.php +++ b/tests/Unit/Repositories/Tags/UserTagTest.php @@ -110,4 +110,66 @@ public function allThroughTagCategory_returns_all_tags_through_a_tag_category(){ )); } } + + /** @test */ + public function update_updates_a_user_tag_category() + { + $oldTagCategory = factory(UserTagCategory::class)->create(); + $newTagCategory = factory(UserTagCategory::class)->create(); + $userTag = factory(UserTag::class)->create([ + 'name' => 'TagName', + 'description' => 'TagDesc', + 'reference' => 'ref', + 'tag_category_id' => $oldTagCategory->id + ]); + $this->assertDatabaseHas('control_tags', [ + 'id' => $userTag->id(), + 'name' => 'TagName', + 'description' => 'TagDesc', + 'reference' => 'ref', + 'tag_category_id' => (string) $oldTagCategory->id, + ]); + $repository = new \BristolSU\ControlDB\Repositories\Tags\UserTag(); + $repository->update($userTag->id(), 'TagName2', 'TagDesc2', 'ref2', $newTagCategory->id()); + $this->assertDatabaseMissing('control_tags', [ + 'id' => $userTag->id(), + 'name' => 'TagName', + 'description' => 'TagDesc', + 'reference' => 'ref', + 'tag_category_id' => (string) $oldTagCategory->id, + ]); + $this->assertDatabaseHas('control_tags', [ + 'id' => $userTag->id(), + 'name' => 'TagName2', + 'description' => 'TagDesc2', + 'reference' => 'ref2', + 'tag_category_id' => (string) $newTagCategory->id, + ]); + + } + + /** @test */ + public function update_returns_the_updated_user_tag_category() + { + $oldTagCategory = factory(UserTagCategory::class)->create(); + $newTagCategory = factory(UserTagCategory::class)->create(); + $userTag = factory(UserTag::class)->create([ + 'name' => 'TagCategoryName', + 'description' => 'TagCategoryDesc', + 'reference' => 'ref', + 'tag_category_id' => $oldTagCategory->id() + ]); + $this->assertEquals('TagCategoryName', $userTag->name()); + $this->assertEquals('TagCategoryDesc', $userTag->description()); + $this->assertEquals('ref', $userTag->reference()); + $this->assertEquals($oldTagCategory->id(), $userTag->categoryId()); + + $repository = new \BristolSU\ControlDB\Repositories\Tags\UserTag(); + $updatedUserTag = $repository->update($userTag->id(), 'TagCategoryName2', 'TagCategoryDesc2', 'ref2', $newTagCategory->id()); + + $this->assertEquals('TagCategoryName2', $updatedUserTag->name()); + $this->assertEquals('TagCategoryDesc2', $updatedUserTag->description()); + $this->assertEquals('ref2', $updatedUserTag->reference()); + $this->assertEquals($newTagCategory->id(), $updatedUserTag->categoryId()); + } } diff --git a/tests/Unit/Traits/DataGroupTraitTest.php b/tests/Unit/Traits/DataGroupTraitTest.php index fdde42d..d03ee5f 100644 --- a/tests/Unit/Traits/DataGroupTraitTest.php +++ b/tests/Unit/Traits/DataGroupTraitTest.php @@ -22,4 +22,26 @@ public function it_returns_null_if_no_group_found(){ $dataGroup = factory(DataGroup::class)->create(); $this->assertNull($dataGroup->group()); } + + /** @test */ + public function setName_updates_the_name() + { + $dataGroup = factory(DataGroup::class)->create(['email' => 'email@example.com']); + $dataGroupRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\DataGroup::class); + $dataGroupRepo->update($dataGroup->id(), 'NewName', 'email@example.com')->shouldBeCalled()->willReturn($dataGroup); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\DataGroup::class, $dataGroupRepo->reveal()); + + $dataGroup->setName('NewName'); + } + + /** @test */ + public function setEmail_updates_the_email() + { + $dataGroup = factory(DataGroup::class)->create(['name' => 'name1']); + $dataGroupRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\DataGroup::class); + $dataGroupRepo->update($dataGroup->id(), 'name1', 'email2@example.com')->shouldBeCalled()->willReturn($dataGroup); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\DataGroup::class, $dataGroupRepo->reveal()); + + $dataGroup->setEmail('email2@example.com'); + } } \ No newline at end of file diff --git a/tests/Unit/Traits/DataPositionTraitTest.php b/tests/Unit/Traits/DataPositionTraitTest.php index 4fd535f..d711eb2 100644 --- a/tests/Unit/Traits/DataPositionTraitTest.php +++ b/tests/Unit/Traits/DataPositionTraitTest.php @@ -22,4 +22,26 @@ public function it_returns_null_if_no_position_found(){ $dataPosition = factory(DataPosition::class)->create(); $this->assertNull($dataPosition->position()); } + + /** @test */ + public function setName_updates_the_name() + { + $dataPosition = factory(DataPosition::class)->create(['description' => 'description']); + $dataPositionRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\DataPosition::class); + $dataPositionRepo->update($dataPosition->id(), 'NewName', 'description')->shouldBeCalled()->willReturn($dataPosition); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\DataPosition::class, $dataPositionRepo->reveal()); + + $dataPosition->setName('NewName'); + } + + /** @test */ + public function setDescription_updates_the_description() + { + $dataPosition = factory(DataPosition::class)->create(['name' => 'name1']); + $dataPositionRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\DataPosition::class); + $dataPositionRepo->update($dataPosition->id(), 'name1', 'description2')->shouldBeCalled()->willReturn($dataPosition); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\DataPosition::class, $dataPositionRepo->reveal()); + + $dataPosition->setDescription('description2'); + } } \ No newline at end of file diff --git a/tests/Unit/Traits/DataRoleTraitTest.php b/tests/Unit/Traits/DataRoleTraitTest.php index 806d3bb..3999e42 100644 --- a/tests/Unit/Traits/DataRoleTraitTest.php +++ b/tests/Unit/Traits/DataRoleTraitTest.php @@ -22,4 +22,26 @@ public function it_returns_null_if_no_role_found(){ $dataRole = factory(DataRole::class)->create(); $this->assertNull($dataRole->role()); } + + /** @test */ + public function setRoleName_updates_the_roleName() + { + $dataRole = factory(DataRole::class)->create(['email' => 'email@example.com']); + $dataRoleRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\DataRole::class); + $dataRoleRepo->update($dataRole->id(), 'NewRoleName', 'email@example.com')->shouldBeCalled()->willReturn($dataRole); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\DataRole::class, $dataRoleRepo->reveal()); + + $dataRole->setRoleName('NewRoleName'); + } + + /** @test */ + public function setEmail_updates_the_email() + { + $dataRole = factory(DataRole::class)->create(['role_name' => 'roleName1']); + $dataRoleRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\DataRole::class); + $dataRoleRepo->update($dataRole->id(), 'roleName1', 'email2@example.com')->shouldBeCalled()->willReturn($dataRole); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\DataRole::class, $dataRoleRepo->reveal()); + + $dataRole->setEmail('email2@example.com'); + } } \ No newline at end of file diff --git a/tests/Unit/Traits/DataUserTraitTest.php b/tests/Unit/Traits/DataUserTraitTest.php index 7b2a965..926e003 100644 --- a/tests/Unit/Traits/DataUserTraitTest.php +++ b/tests/Unit/Traits/DataUserTraitTest.php @@ -5,6 +5,7 @@ use BristolSU\ControlDB\Models\DataUser; use BristolSU\ControlDB\Models\User; use BristolSU\Tests\ControlDB\TestCase; +use Carbon\Carbon; class DataUserTraitTest extends TestCase { @@ -22,4 +23,95 @@ public function it_returns_null_if_no_user_found(){ $dataUser = factory(DataUser::class)->create(); $this->assertNull($dataUser->user()); } + + /** @test */ + public function setFirstName_updates_the_first_name() + { + $dob = Carbon::create(1977, 05, 11); + $dataUser = factory(DataUser::class)->create([ + 'first_name' => 'Toby', + 'last_name' => 'Twigger', + 'email' => 'email@example.com', + 'dob' => $dob, + 'preferred_name' => 'Toby Tw' + ]); + $dataUserRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class); + $dataUserRepo->update($dataUser->id(), 'Toby2', 'Twigger', 'email@example.com', $dob, 'Toby Tw')->shouldBeCalled()->willReturn($dataUser); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class, $dataUserRepo->reveal()); + + $dataUser->setFirstName('Toby2'); + } + + /** @test */ + public function setName_updates_the_name() + { + $dob = Carbon::create(1977, 05, 11); + $dataUser = factory(DataUser::class)->create([ + 'first_name' => 'Toby', + 'last_name' => 'Twigger', + 'email' => 'email@example.com', + 'dob' => $dob, + 'preferred_name' => 'Toby Tw' + ]); + $dataUserRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class); + $dataUserRepo->update($dataUser->id(), 'Toby', 'Twigger2', 'email@example.com', $dob, 'Toby Tw')->shouldBeCalled()->willReturn($dataUser); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class, $dataUserRepo->reveal()); + + $dataUser->setLastName('Twigger2'); + } + + /** @test */ + public function setEmail_updates_the_email() + { + $dob = Carbon::create(1977, 05, 11); + $dataUser = factory(DataUser::class)->create([ + 'first_name' => 'Toby', + 'last_name' => 'Twigger', + 'email' => 'email@example.com', + 'dob' => $dob, + 'preferred_name' => 'Toby Tw' + ]); + $dataUserRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class); + $dataUserRepo->update($dataUser->id(), 'Toby', 'Twigger', 'email2@example.com', $dob, 'Toby Tw')->shouldBeCalled()->willReturn($dataUser); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class, $dataUserRepo->reveal()); + + $dataUser->setEmail('email2@example.com'); + } + + /** @test */ + public function setDob_updates_the_dob() + { + $dob = Carbon::create(1977, 05, 11); + $newDob = Carbon::create(1988, 05, 11); + $dataUser = factory(DataUser::class)->create([ + 'first_name' => 'Toby', + 'last_name' => 'Twigger', + 'email' => 'email@example.com', + 'dob' => $dob, + 'preferred_name' => 'Toby Tw' + ]); + $dataUserRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class); + $dataUserRepo->update($dataUser->id(), 'Toby', 'Twigger', 'email@example.com', $newDob, 'Toby Tw')->shouldBeCalled()->willReturn($dataUser); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class, $dataUserRepo->reveal()); + + $dataUser->setDob($newDob); + } + + /** @test */ + public function setPreferredName_updates_the_preferred_name() + { + $dob = Carbon::create(1977, 05, 11); + $dataUser = factory(DataUser::class)->create([ + 'first_name' => 'Toby', + 'last_name' => 'Twigger', + 'email' => 'email@example.com', + 'dob' => $dob, + 'preferred_name' => 'Toby Tw' + ]); + $dataUserRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class); + $dataUserRepo->update($dataUser->id(), 'Toby', 'Twigger', 'email@example.com', $dob, 'Toby Tw2')->shouldBeCalled()->willReturn($dataUser); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class, $dataUserRepo->reveal()); + + $dataUser->setPreferredName('Toby Tw2'); + } } \ No newline at end of file diff --git a/tests/Unit/Traits/GroupTraitTest.php b/tests/Unit/Traits/GroupTraitTest.php index f4abbe0..9ed5153 100644 --- a/tests/Unit/Traits/GroupTraitTest.php +++ b/tests/Unit/Traits/GroupTraitTest.php @@ -155,5 +155,19 @@ public function tags_can_be_added_to_a_group() { ]); } } + + /** @test */ + public function setDataProviderId_updates_the_data_provider_id() + { + $oldDataGroup = factory(DataGroup::class)->create(); + $newDataGroup = factory(DataGroup::class)->create(); + $group = factory(Group::class)->create(['data_provider_id' => $oldDataGroup->id()]); + + $groupRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Group::class); + $groupRepo->update($group->id(), $newDataGroup->id())->shouldBeCalled()->willReturn($group); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Group::class, $groupRepo->reveal()); + + $group->setDataProviderId($newDataGroup->id()); + } } \ No newline at end of file diff --git a/tests/Unit/Traits/PositionTraitTest.php b/tests/Unit/Traits/PositionTraitTest.php index 8fd104c..5d8af94 100644 --- a/tests/Unit/Traits/PositionTraitTest.php +++ b/tests/Unit/Traits/PositionTraitTest.php @@ -97,4 +97,18 @@ public function roles_returns_all_roles_the_position_has(){ } } + /** @test */ + public function setDataProviderId_updates_the_data_provider_id() + { + $oldDataPosition = factory(DataPosition::class)->create(); + $newDataPosition = factory(DataPosition::class)->create(); + $position = factory(Position::class)->create(['data_provider_id' => $oldDataPosition->id()]); + + $positionRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Position::class); + $positionRepo->update($position->id(), $newDataPosition->id())->shouldBeCalled()->willReturn($position); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Position::class, $positionRepo->reveal()); + + $position->setDataProviderId($newDataPosition->id()); + } + } \ No newline at end of file diff --git a/tests/Unit/Traits/RoleTraitTest.php b/tests/Unit/Traits/RoleTraitTest.php index e5b1872..111b115 100644 --- a/tests/Unit/Traits/RoleTraitTest.php +++ b/tests/Unit/Traits/RoleTraitTest.php @@ -167,5 +167,46 @@ public function positions_returns_all_positions_associated_with_the_role(){ $this->assertInstanceOf(Position::class, $positionThroughRole); $this->assertTrue($position->is($positionThroughRole)); } - + + /** @test */ + public function setDataProviderId_updates_the_data_provider_id() + { + $oldDataRole = factory(DataRole::class)->create(); + $newDataRole = factory(DataRole::class)->create(); + $role = factory(Role::class)->create(['data_provider_id' => $oldDataRole->id()]); + + $roleRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Role::class); + $roleRepo->update($role->id(), $role->positionId(), $role->groupId(), $newDataRole->id())->shouldBeCalled()->willReturn($role); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Role::class, $roleRepo->reveal()); + + $role->setDataProviderId($newDataRole->id()); + } + + /** @test */ + public function setGroupId_updates_the_group_id() + { + $oldGroup = factory(Group::class)->create(); + $newGroup = factory(Group::class)->create(); + $role = factory(Role::class)->create(['group_id' => $oldGroup->id()]); + + $roleRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Role::class); + $roleRepo->update($role->id(), $role->positionId(), $newGroup->id(), $role->dataProviderId())->shouldBeCalled()->willReturn($role); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Role::class, $roleRepo->reveal()); + + $role->setGroupId($newGroup->id()); + } + + /** @test */ + public function setPositionId_updates_the_position_id() + { + $oldPosition = factory(Position::class)->create(); + $newPosition = factory(Position::class)->create(); + $role = factory(Role::class)->create(['position_id' => $oldPosition->id()]); + + $roleRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Role::class); + $roleRepo->update($role->id(), $newPosition->id(), $role->groupId(), $role->dataProviderId())->shouldBeCalled()->willReturn($role); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Role::class, $roleRepo->reveal()); + + $role->setPositionId($newPosition->id()); + } } \ No newline at end of file diff --git a/tests/Unit/Traits/Tags/GroupTagCategoryTraitTest.php b/tests/Unit/Traits/Tags/GroupTagCategoryTraitTest.php index 9767b41..3ae7868 100644 --- a/tests/Unit/Traits/Tags/GroupTagCategoryTraitTest.php +++ b/tests/Unit/Traits/Tags/GroupTagCategoryTraitTest.php @@ -22,4 +22,45 @@ public function tags_returns_the_linked_tags(){ $this->assertTrue($tag->is($tagsFromRelationship->shift())); } } + + /** @test */ + public function setName_updates_the_group_tag_category_name() + { + $groupTagCategory = factory(GroupTagCategory::class)->create(); + + $groupTagCategoryRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTagCategory::class); + $groupTagCategoryRepository->update($groupTagCategory->id(), 'NewName', $groupTagCategory->description(), $groupTagCategory->reference()) + ->shouldBeCalled()->willReturn($groupTagCategory); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTagCategory::class, $groupTagCategoryRepository->reveal()); + + $groupTagCategory->setName('NewName'); + } + + /** @test */ + public function setDescription_updates_the_group_tag_category_description() + { + $groupTagCategory = factory(GroupTagCategory::class)->create(); + + $groupTagCategoryRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTagCategory::class); + $groupTagCategoryRepository->update($groupTagCategory->id(), $groupTagCategory->name(), 'NewDescription', $groupTagCategory->reference()) + ->shouldBeCalled()->willReturn($groupTagCategory); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTagCategory::class, $groupTagCategoryRepository->reveal()); + + $groupTagCategory->setDescription('NewDescription'); + } + + /** @test */ + public function setReference_updates_the_group_tag_category_reference() + { + $groupTagCategory = factory(GroupTagCategory::class)->create(); + + $groupTagCategoryRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTagCategory::class); + $groupTagCategoryRepository->update($groupTagCategory->id(), $groupTagCategory->name(), $groupTagCategory->description(), 'NewReference') + ->shouldBeCalled()->willReturn($groupTagCategory); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTagCategory::class, $groupTagCategoryRepository->reveal()); + + $groupTagCategory->setReference('NewReference'); + } + + } \ No newline at end of file diff --git a/tests/Unit/Traits/Tags/GroupTagTraitTest.php b/tests/Unit/Traits/Tags/GroupTagTraitTest.php index 55ee0e2..19569c4 100644 --- a/tests/Unit/Traits/Tags/GroupTagTraitTest.php +++ b/tests/Unit/Traits/Tags/GroupTagTraitTest.php @@ -90,4 +90,57 @@ public function fullReference_returns_the_category_reference_and_the_tag_referen $this->assertEquals('categoryreference1.tagreference1', $groupTag->fullReference()); } + /** @test */ + public function setName_updates_the_group_tag_name() + { + $groupTag = factory(GroupTag::class)->create(); + + $groupTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTag::class); + $groupTagRepository->update($groupTag->id(), 'NewName', $groupTag->description(), $groupTag->reference(), $groupTag->categoryId()) + ->shouldBeCalled()->willReturn($groupTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTag::class, $groupTagRepository->reveal()); + + $groupTag->setName('NewName'); + } + + /** @test */ + public function setDescription_updates_the_group_tag_description() + { + $groupTag = factory(GroupTag::class)->create(); + + $groupTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTag::class); + $groupTagRepository->update($groupTag->id(), $groupTag->name(), 'NewDescription', $groupTag->reference(), $groupTag->categoryId()) + ->shouldBeCalled()->willReturn($groupTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTag::class, $groupTagRepository->reveal()); + + $groupTag->setDescription('NewDescription'); + } + + /** @test */ + public function setReference_updates_the_group_tag_reference() + { + $groupTag = factory(GroupTag::class)->create(); + + $groupTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTag::class); + $groupTagRepository->update($groupTag->id(), $groupTag->name(), $groupTag->description(), 'NewReference', $groupTag->categoryId()) + ->shouldBeCalled()->willReturn($groupTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTag::class, $groupTagRepository->reveal()); + + $groupTag->setReference('NewReference'); + } + + /** @test */ + public function setTagCategoryId_updates_the_group_tag_category_id() + { + $groupTag = factory(GroupTag::class)->create(); + $groupTagCategory = factory(GroupTagCategory::class)->create(); + + $groupTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTag::class); + $groupTagRepository->update($groupTag->id(), $groupTag->name(), $groupTag->description(), $groupTag->reference(), $groupTagCategory->id()) + ->shouldBeCalled()->willReturn($groupTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTag::class, $groupTagRepository->reveal()); + + $groupTag->setTagCategoryId($groupTagCategory->id()); + } + } \ No newline at end of file diff --git a/tests/Unit/Traits/Tags/PositionTagCategoryTraitTest.php b/tests/Unit/Traits/Tags/PositionTagCategoryTraitTest.php index c1d88c3..38143db 100644 --- a/tests/Unit/Traits/Tags/PositionTagCategoryTraitTest.php +++ b/tests/Unit/Traits/Tags/PositionTagCategoryTraitTest.php @@ -23,5 +23,43 @@ public function tags_returns_the_linked_tags(){ $this->assertTrue($tag->is($tagsFromRelationship->shift())); } } - + + /** @test */ + public function setName_updates_the_position_tag_category_name() + { + $positionTagCategory = factory(PositionTagCategory::class)->create(); + + $positionTagCategooryRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTagCategory::class); + $positionTagCategooryRepository->update($positionTagCategory->id(), 'NewName', $positionTagCategory->description(), $positionTagCategory->reference()) + ->shouldBeCalled()->willReturn($positionTagCategory); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTagCategory::class, $positionTagCategooryRepository->reveal()); + + $positionTagCategory->setName('NewName'); + } + + /** @test */ + public function setDescription_updates_the_position_tag_category_description() + { + $positionTagCategory = factory(PositionTagCategory::class)->create(); + + $positionTagCategooryRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTagCategory::class); + $positionTagCategooryRepository->update($positionTagCategory->id(), $positionTagCategory->name(), 'NewDescription', $positionTagCategory->reference()) + ->shouldBeCalled()->willReturn($positionTagCategory); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTagCategory::class, $positionTagCategooryRepository->reveal()); + + $positionTagCategory->setDescription('NewDescription'); + } + + /** @test */ + public function setReference_updates_the_position_tag_category_reference() + { + $positionTagCategory = factory(PositionTagCategory::class)->create(); + + $positionTagCategooryRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTagCategory::class); + $positionTagCategooryRepository->update($positionTagCategory->id(), $positionTagCategory->name(), $positionTagCategory->description(), 'NewReference') + ->shouldBeCalled()->willReturn($positionTagCategory); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTagCategory::class, $positionTagCategooryRepository->reveal()); + + $positionTagCategory->setReference('NewReference'); + } } \ No newline at end of file diff --git a/tests/Unit/Traits/Tags/PositionTagTraitTest.php b/tests/Unit/Traits/Tags/PositionTagTraitTest.php index 59580e7..b37b9f6 100644 --- a/tests/Unit/Traits/Tags/PositionTagTraitTest.php +++ b/tests/Unit/Traits/Tags/PositionTagTraitTest.php @@ -90,4 +90,58 @@ public function fullReference_returns_the_category_reference_and_the_tag_referen $this->assertEquals('categoryreference1.tagreference1', $positionTag->fullReference()); } + + /** @test */ + public function setName_updates_the_position_tag_name() + { + $positionTag = factory(PositionTag::class)->create(); + + $positionTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTag::class); + $positionTagRepository->update($positionTag->id(), 'NewName', $positionTag->description(), $positionTag->reference(), $positionTag->categoryId()) + ->shouldBeCalled()->willReturn($positionTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTag::class, $positionTagRepository->reveal()); + + $positionTag->setName('NewName'); + } + + /** @test */ + public function setDescription_updates_the_position_tag_description() + { + $positionTag = factory(PositionTag::class)->create(); + + $positionTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTag::class); + $positionTagRepository->update($positionTag->id(), $positionTag->name(), 'NewDescription', $positionTag->reference(), $positionTag->categoryId()) + ->shouldBeCalled()->willReturn($positionTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTag::class, $positionTagRepository->reveal()); + + $positionTag->setDescription('NewDescription'); + } + + /** @test */ + public function setReference_updates_the_position_tag_reference() + { + $positionTag = factory(PositionTag::class)->create(); + + $positionTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTag::class); + $positionTagRepository->update($positionTag->id(), $positionTag->name(), $positionTag->description(), 'NewReference', $positionTag->categoryId()) + ->shouldBeCalled()->willReturn($positionTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTag::class, $positionTagRepository->reveal()); + + $positionTag->setReference('NewReference'); + } + + /** @test */ + public function setTagCategoryId_updates_the_position_tag_category_id() + { + $positionTag = factory(PositionTag::class)->create(); + $positionTagCategory = factory(PositionTagCategory::class)->create(); + + $positionTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTag::class); + $positionTagRepository->update($positionTag->id(), $positionTag->name(), $positionTag->description(), $positionTag->reference(), $positionTagCategory->id()) + ->shouldBeCalled()->willReturn($positionTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\PositionTag::class, $positionTagRepository->reveal()); + + $positionTag->setTagCategoryId($positionTagCategory->id()); + } + } \ No newline at end of file diff --git a/tests/Unit/Traits/Tags/RoleTagCategoryTraitTest.php b/tests/Unit/Traits/Tags/RoleTagCategoryTraitTest.php index 7cca351..671c120 100644 --- a/tests/Unit/Traits/Tags/RoleTagCategoryTraitTest.php +++ b/tests/Unit/Traits/Tags/RoleTagCategoryTraitTest.php @@ -22,4 +22,43 @@ public function tags_returns_the_linked_tags(){ $this->assertTrue($tag->is($tagsFromRelationship->shift())); } } + + /** @test */ + public function setName_updates_the_role_tag_category_name() + { + $roleTagCategory = factory(RoleTagCategory::class)->create(); + + $roleTagCategooryRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTagCategory::class); + $roleTagCategooryRepository->update($roleTagCategory->id(), 'NewName', $roleTagCategory->description(), $roleTagCategory->reference()) + ->shouldBeCalled()->willReturn($roleTagCategory); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTagCategory::class, $roleTagCategooryRepository->reveal()); + + $roleTagCategory->setName('NewName'); + } + + /** @test */ + public function setDescription_updates_the_role_tag_category_description() + { + $roleTagCategory = factory(RoleTagCategory::class)->create(); + + $roleTagCategooryRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTagCategory::class); + $roleTagCategooryRepository->update($roleTagCategory->id(), $roleTagCategory->name(), 'NewDescription', $roleTagCategory->reference()) + ->shouldBeCalled()->willReturn($roleTagCategory); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTagCategory::class, $roleTagCategooryRepository->reveal()); + + $roleTagCategory->setDescription('NewDescription'); + } + + /** @test */ + public function setReference_updates_the_role_tag_category_reference() + { + $roleTagCategory = factory(RoleTagCategory::class)->create(); + + $roleTagCategooryRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTagCategory::class); + $roleTagCategooryRepository->update($roleTagCategory->id(), $roleTagCategory->name(), $roleTagCategory->description(), 'NewReference') + ->shouldBeCalled()->willReturn($roleTagCategory); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTagCategory::class, $roleTagCategooryRepository->reveal()); + + $roleTagCategory->setReference('NewReference'); + } } \ No newline at end of file diff --git a/tests/Unit/Traits/Tags/RoleTagTraitTest.php b/tests/Unit/Traits/Tags/RoleTagTraitTest.php index 4f53dd5..3587dcd 100644 --- a/tests/Unit/Traits/Tags/RoleTagTraitTest.php +++ b/tests/Unit/Traits/Tags/RoleTagTraitTest.php @@ -3,7 +3,6 @@ namespace BristolSU\Tests\ControlDB\Unit\Traits\Tags; use BristolSU\ControlDB\Models\Role; -use BristolSU\ControlDB\Models\Group; use BristolSU\ControlDB\Models\Position; use BristolSU\ControlDB\Models\Tags\RoleTag; use BristolSU\ControlDB\Models\Tags\RoleTagCategory; @@ -64,12 +63,12 @@ public function roles_can_be_removed_from_the_tag(){ /** @test */ public function role_returns_all_roles_tagged(){ $roleTag = factory(RoleTag::class)->create(); - // Models which could be linked to a tag. Users, positions and groups should never be returned + // Models which could be linked to a tag. Users, positions and roles should never be returned $taggedRoles = factory(Role::class, 5)->create(); $untaggedRoles = factory(Role::class, 5)->create(); $users = factory(User::class, 5)->create(); $positions = factory(Position::class, 5)->create(); - $groups = factory(Group::class, 5)->create(); + $roles = factory(Role::class, 5)->create(); DB::table('control_taggables')->insert($taggedRoles->map(function($role) use ($roleTag) { return ['tag_id' => $roleTag->id, 'taggable_id' => $role->id, 'taggable_type' => 'role']; @@ -90,4 +89,57 @@ public function fullReference_returns_the_category_reference_and_the_tag_referen $this->assertEquals('categoryreference1.tagreference1', $roleTag->fullReference()); } + + /** @test */ + public function setName_updates_the_role_tag_name() + { + $roleTag = factory(RoleTag::class)->create(); + + $roleTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTag::class); + $roleTagRepository->update($roleTag->id(), 'NewName', $roleTag->description(), $roleTag->reference(), $roleTag->categoryId()) + ->shouldBeCalled()->willReturn($roleTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTag::class, $roleTagRepository->reveal()); + + $roleTag->setName('NewName'); + } + + /** @test */ + public function setDescription_updates_the_role_tag_description() + { + $roleTag = factory(RoleTag::class)->create(); + + $roleTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTag::class); + $roleTagRepository->update($roleTag->id(), $roleTag->name(), 'NewDescription', $roleTag->reference(), $roleTag->categoryId()) + ->shouldBeCalled()->willReturn($roleTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTag::class, $roleTagRepository->reveal()); + + $roleTag->setDescription('NewDescription'); + } + + /** @test */ + public function setReference_updates_the_role_tag_reference() + { + $roleTag = factory(RoleTag::class)->create(); + + $roleTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTag::class); + $roleTagRepository->update($roleTag->id(), $roleTag->name(), $roleTag->description(), 'NewReference', $roleTag->categoryId()) + ->shouldBeCalled()->willReturn($roleTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTag::class, $roleTagRepository->reveal()); + + $roleTag->setReference('NewReference'); + } + + /** @test */ + public function setTagCategoryId_updates_the_role_tag_category_id() + { + $roleTag = factory(RoleTag::class)->create(); + $roleTagCategory = factory(RoleTagCategory::class)->create(); + + $roleTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTag::class); + $roleTagRepository->update($roleTag->id(), $roleTag->name(), $roleTag->description(), $roleTag->reference(), $roleTagCategory->id()) + ->shouldBeCalled()->willReturn($roleTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\RoleTag::class, $roleTagRepository->reveal()); + + $roleTag->setTagCategoryId($roleTagCategory->id()); + } } \ No newline at end of file diff --git a/tests/Unit/Traits/Tags/UserTagCategoryTraitTest.php b/tests/Unit/Traits/Tags/UserTagCategoryTraitTest.php index 74c327a..ea485bd 100644 --- a/tests/Unit/Traits/Tags/UserTagCategoryTraitTest.php +++ b/tests/Unit/Traits/Tags/UserTagCategoryTraitTest.php @@ -23,4 +23,43 @@ public function tags_returns_the_linked_tags(){ $this->assertTrue($tag->is($tagsFromRelationship->shift())); } } + + /** @test */ + public function setName_updates_the_user_tag_category_name() + { + $userTagCategory = factory(UserTagCategory::class)->create(); + + $userTagCategooryRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTagCategory::class); + $userTagCategooryRepository->update($userTagCategory->id(), 'NewName', $userTagCategory->description(), $userTagCategory->reference()) + ->shouldBeCalled()->willReturn($userTagCategory); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTagCategory::class, $userTagCategooryRepository->reveal()); + + $userTagCategory->setName('NewName'); + } + + /** @test */ + public function setDescription_updates_the_user_tag_category_description() + { + $userTagCategory = factory(UserTagCategory::class)->create(); + + $userTagCategooryRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTagCategory::class); + $userTagCategooryRepository->update($userTagCategory->id(), $userTagCategory->name(), 'NewDescription', $userTagCategory->reference()) + ->shouldBeCalled()->willReturn($userTagCategory); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTagCategory::class, $userTagCategooryRepository->reveal()); + + $userTagCategory->setDescription('NewDescription'); + } + + /** @test */ + public function setReference_updates_the_user_tag_category_reference() + { + $userTagCategory = factory(UserTagCategory::class)->create(); + + $userTagCategooryRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTagCategory::class); + $userTagCategooryRepository->update($userTagCategory->id(), $userTagCategory->name(), $userTagCategory->description(), 'NewReference') + ->shouldBeCalled()->willReturn($userTagCategory); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTagCategory::class, $userTagCategooryRepository->reveal()); + + $userTagCategory->setReference('NewReference'); + } } \ No newline at end of file diff --git a/tests/Unit/Traits/Tags/UserTagTraitTest.php b/tests/Unit/Traits/Tags/UserTagTraitTest.php index 1058aca..92798b3 100644 --- a/tests/Unit/Traits/Tags/UserTagTraitTest.php +++ b/tests/Unit/Traits/Tags/UserTagTraitTest.php @@ -90,4 +90,58 @@ public function fullReference_returns_the_category_reference_and_the_tag_referen $this->assertEquals('categoryreference1.tagreference1', $userTag->fullReference()); } + + /** @test */ + public function setName_updates_the_user_tag_name() + { + $userTag = factory(UserTag::class)->create(); + + $userTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTag::class); + $userTagRepository->update($userTag->id(), 'NewName', $userTag->description(), $userTag->reference(), $userTag->categoryId()) + ->shouldBeCalled()->willReturn($userTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTag::class, $userTagRepository->reveal()); + + $userTag->setName('NewName'); + } + + /** @test */ + public function setDescription_updates_the_user_tag_description() + { + $userTag = factory(UserTag::class)->create(); + + $userTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTag::class); + $userTagRepository->update($userTag->id(), $userTag->name(), 'NewDescription', $userTag->reference(), $userTag->categoryId()) + ->shouldBeCalled()->willReturn($userTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTag::class, $userTagRepository->reveal()); + + $userTag->setDescription('NewDescription'); + } + + /** @test */ + public function setReference_updates_the_user_tag_reference() + { + $userTag = factory(UserTag::class)->create(); + + $userTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTag::class); + $userTagRepository->update($userTag->id(), $userTag->name(), $userTag->description(), 'NewReference', $userTag->categoryId()) + ->shouldBeCalled()->willReturn($userTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTag::class, $userTagRepository->reveal()); + + $userTag->setReference('NewReference'); + } + + /** @test */ + public function setTagCategoryId_updates_the_user_tag_category_id() + { + $userTag = factory(UserTag::class)->create(); + $userTagCategory = factory(UserTagCategory::class)->create(); + + $userTagRepository = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTag::class); + $userTagRepository->update($userTag->id(), $userTag->name(), $userTag->description(), $userTag->reference(), $userTagCategory->id()) + ->shouldBeCalled()->willReturn($userTag); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\Tags\UserTag::class, $userTagRepository->reveal()); + + $userTag->setTagCategoryId($userTagCategory->id()); + } + } \ No newline at end of file diff --git a/tests/Unit/Traits/UserTraitTest.php b/tests/Unit/Traits/UserTraitTest.php index 626065c..8f0e6b4 100644 --- a/tests/Unit/Traits/UserTraitTest.php +++ b/tests/Unit/Traits/UserTraitTest.php @@ -203,4 +203,18 @@ public function tags_can_be_removed_from_a_user() { ]); } } + + /** @test */ + public function setDataProviderId_updates_the_data_provider_id() + { + $oldDataUser = factory(DataUser::class)->create(); + $newDataUser = factory(DataUser::class)->create(); + $user = factory(User::class)->create(['data_provider_id' => $oldDataUser->id()]); + + $userRepo = $this->prophesize(\BristolSU\ControlDB\Contracts\Repositories\User::class); + $userRepo->update($user->id(), $newDataUser->id())->shouldBeCalled()->willReturn($user); + $this->instance(\BristolSU\ControlDB\Contracts\Repositories\User::class, $userRepo->reveal()); + + $user->setDataProviderId($newDataUser->id()); + } } \ No newline at end of file From d56a6d8d986391cb4543871e0734f07f58cba0b0 Mon Sep 17 00:00:00 2001 From: Toby Twigger Date: Mon, 27 Apr 2020 13:41:01 +0100 Subject: [PATCH 5/7] Update php --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f7aa548..80745fd 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": "^7.2", + "php": "^7.3", "ext-json": "*" }, "require-dev": { From 8960ebb84da60344e1543a7a4b1a7f9cd576430d Mon Sep 17 00:00:00 2001 From: Toby Twigger Date: Mon, 27 Apr 2020 13:43:03 +0100 Subject: [PATCH 6/7] Update changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78b2c96..6586fd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.1] - (27/04/2020) + ### Added - Repositories to cache all get repository calls - Observer framework for repositories @@ -142,7 +144,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - model/repository contracts -[Unreleased]: https://github.com/bristol-su/control/compare/v2.0...HEAD +[Unreleased]: https://github.com/bristol-su/control/compare/v2.1...HEAD +[2.1]: https://github.com/bristol-su/control/compare/v2.0...v2.1 [2.0]: https://github.com/bristol-su/control/compare/v1.3.0...v2.0 [1.3.0]: https://github.com/bristol-su/control/compare/v1.2.4...v1.3.0 [1.2.4]: https://github.com/bristol-su/control/compare/v1.2.3...v1.2.4 From 4cfcae4bdc9d7af9e97b5e96baec5403aaa5a3f8 Mon Sep 17 00:00:00 2001 From: Toby Twigger Date: Mon, 27 Apr 2020 13:59:03 +0100 Subject: [PATCH 7/7] Fix bug with test --- tests/Unit/Repositories/Tags/GroupTagTest.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/Unit/Repositories/Tags/GroupTagTest.php b/tests/Unit/Repositories/Tags/GroupTagTest.php index 25e5174..2f18a3a 100644 --- a/tests/Unit/Repositories/Tags/GroupTagTest.php +++ b/tests/Unit/Repositories/Tags/GroupTagTest.php @@ -17,7 +17,7 @@ class GroupTagTest extends TestCase /** @test */ public function getById_returns_a_group_tag_model_with_the_corresponding_id(){ $groupTag = factory(GroupTag::class)->create(['id' => 2]); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); $this->assertTrue( $groupTag->is($groupTagRepo->getById(2)) ); @@ -26,14 +26,14 @@ public function getById_returns_a_group_tag_model_with_the_corresponding_id(){ /** @test */ public function getById_throws_a_modelNotFoundException_if_group_tag_does_not_exist(){ $this->expectException(ModelNotFoundException::class); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); $groupTagRepo->getById(5); } /** @test */ public function all_returns_all_group_tags(){ $groupTags = factory(GroupTag::class, 15)->create(); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); $allTags = $groupTagRepo->all(); $this->assertInstanceOf(Collection::class, $allTags); foreach($groupTags as $groupTag) { @@ -48,7 +48,7 @@ public function getTagByFullReference_returns_a_tag_given_the_full_reference(){ $groupTagCategory = factory(GroupTagCategory::class)->create(['reference' => 'ref1']); $groupTag = factory(GroupTag::class)->create(['reference' => 'ref2', 'tag_category_id' => $groupTagCategory->id]); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); $groupTagFromRepo = $groupTagRepo->getTagByFullReference('ref1.ref2'); $this->assertInstanceOf(GroupTag::class, $groupTagFromRepo); $this->assertTrue($groupTag->is($groupTagFromRepo)); @@ -58,14 +58,14 @@ public function getTagByFullReference_returns_a_tag_given_the_full_reference(){ /** @test */ public function getTagByFullReference_throws_an_exception_if_group_tag_not_found(){ $this->expectException(ModelNotFoundException::class); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); $groupTagRepo->getTagByFullReference('nota.validref'); } /** @test */ public function create_creates_a_group_tag_model(){ - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); $groupTagRepo->create('Name', 'Description', 'reference', 1); $this->assertDatabaseHas('control_tags', [ @@ -78,7 +78,7 @@ public function create_creates_a_group_tag_model(){ /** @test */ public function create_returns_a_group_tag_model(){ - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); $groupTag = $groupTagRepo->create('Name', 'Description', 'reference', 1); $this->assertInstanceOf(GroupTag::class, $groupTag); @@ -91,7 +91,7 @@ public function create_returns_a_group_tag_model(){ /** @test */ public function delete_deletes_a_group_tag_model(){ $groupTag = factory(GroupTag::class)->create(); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); $groupTagRepo->delete($groupTag->id()); $groupTag->refresh(); @@ -104,7 +104,7 @@ public function allThroughTagCategory_returns_all_tags_through_a_tag_category(){ $tags = factory(GroupTag::class, 10)->create(['tag_category_id' => $category->id()]); factory(GroupTag::class, 10)->create(); - $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $groupTagRepo = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); $tagsFromRepo = $groupTagRepo->allThroughTagCategory($category); $this->assertContainsOnlyInstancesOf(GroupTag::class, $tagsFromRepo); foreach($tags as $tag) { @@ -132,7 +132,7 @@ public function update_updates_a_group_tag_category() 'reference' => 'ref', 'tag_category_id' => (string) $oldTagCategory->id, ]); - $repository = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $repository = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); $repository->update($groupTag->id(), 'TagName2', 'TagDesc2', 'ref2', $newTagCategory->id()); $this->assertDatabaseMissing('control_tags', [ 'id' => $groupTag->id(), @@ -167,7 +167,7 @@ public function update_returns_the_updated_group_tag_category() $this->assertEquals('ref', $groupTag->reference()); $this->assertEquals($oldTagCategory->id(), $groupTag->categoryId()); - $repository = new \BristolSU\ControlDB\Repositories\Tags\GroupTagCategory(); + $repository = new \BristolSU\ControlDB\Repositories\Tags\GroupTag(); $updatedGroupTag = $repository->update($groupTag->id(), 'TagCategoryName2', 'TagCategoryDesc2', 'ref2', $newTagCategory->id()); $this->assertEquals('TagCategoryName2', $updatedGroupTag->name());