From c2b5584670671db56ee910bc7cc323dcb18300e7 Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Tue, 27 Aug 2024 05:59:44 +0000 Subject: [PATCH 1/6] Add phpunit to composer.json Adapt path for phpunit script --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 74d79723c..7bb3ad5c8 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,8 @@ "require-dev": { "squizlabs/php_codesniffer": "^3.7.1", "phpcompatibility/php-compatibility": "^9.3.5", - "kint-php/kint": "^4.2.3" + "kint-php/kint": "^4.2.3", + "phpunit/phpunit": "^11.3" }, "require": { "php": ">=8.1", @@ -36,7 +37,7 @@ "fix": "./tools/php-cs-fixer fix -v", "lint": "./tools/php-cs-fixer fix -vv --dry-run", "test": [ - "./tools/phpunit", + "./vendor/bin/phpunit", "@lint" ], "sniffer:php8": "phpcs -p ./ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --report-full=./php8-report.log --ignore=./vendor/*,./tools/*,./.git/*,./tpl_c/*,./build/*,./.phpdoc/*,./var/*,./Web/scripts/*,./Web/css/* --runtime-set testVersion 8.0" From d3ad98b2f39942a6f250f37b12c5a0fd3e7865e1 Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Tue, 27 Aug 2024 06:00:01 +0000 Subject: [PATCH 2/6] Migrate phpunit.xml --- phpunit.xml.dist | 117 +++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 69 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5d280515d..527468c7e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,73 +1,52 @@ - - - - - - - - - ./tests - - - - ./tests/Application - - - - ./tests/Domain - - - - ./tests/Plugins - - - - ./tests/Presenters - - - - ./tests/WebService - - - - ./tests/WebServices - - - - - - - Controls - Domain - Jobs - lib - Pages - Plugins - Presenters - Web - WebServices - - - lib/external - - - - - - + + + + + + + + ./tests + + + ./tests/Application + + + ./tests/Domain + + + ./tests/Plugins + + + ./tests/Presenters + + + ./tests/WebService + + + ./tests/WebServices + + + + + + + + + Controls + Domain + Jobs + lib + Pages + Plugins + Presenters + Web + WebServices + + + lib/external + + From 5a490c287dfebeeadd290aeb000b978930d1aa30 Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Tue, 27 Aug 2024 06:17:49 +0000 Subject: [PATCH 3/6] Add missing implementations and add test names Make tests executable --- .gitignore | 3 +++ Domain/CreditCost.php | 1 + .../Admin/GroupAdminGroupsRepositoryTest.php | 2 +- ...roupAdminManageReservationsServiceTest.php | 2 +- .../Admin/ManageReservationsServiceTest.php | 2 +- ...urceAdminManageReservationsServiceTest.php | 2 +- .../ResourceAdminResourceRepositoryTest.php | 2 +- ...duleAdminManageReservationsServiceTest.php | 2 +- .../ScheduleAdminScheduleRepositoryTest.php | 2 +- .../Attributes/AttributeListTest.php | 2 +- .../Attributes/AttributeServiceTest.php | 2 +- .../Attributes/AttributeValidatorTest.php | 2 +- .../Authentication/AccountActivationTest.php | 2 +- .../Authentication/AuthenticationTest.php | 2 +- .../Authentication/GuestUserServiceTest.php | 2 +- .../Authentication/PasswordEncryptionTest.php | 2 +- .../Authentication/PasswordMigrationTest.php | 2 +- .../Authentication/PostRegistrationTest.php | 2 +- .../Authentication/RegistrationTest.php | 2 +- .../Authentication/WebAuthenticationTest.php | 2 +- .../WebServiceAuthenticationTest.php | 2 +- .../AuthorizationServiceTest.php | 2 +- .../Authorization/PrivacyFilterTest.php | 2 +- .../Reporting/CannedReportTest.php | 2 +- .../Reporting/Report_RangeTest.php | 2 +- .../Reporting/ReportingServiceTest.php | 2 +- .../AccessoryAvailabilityRuleTest.php | 2 +- .../Reservation/AccessoryResourceRuleTest.php | 2 +- .../AdminEmailNotificationTest.php | 2 +- .../Reservation/AdminExcludedRuleTest.php | 2 +- .../Reservation/AttachmentExtensionTest.php | 2 +- .../Reservation/BlackoutsServiceTest.php | 2 +- .../Reservation/CreditsRuleTest.php | 2 +- .../CustomAttributeValidationRuleTest.php | 2 +- .../ExistingResourceAvailabilityRuleTest.php | 2 +- .../GuestEmailNotificationTest.php | 2 +- .../InvitationEmailNotificationTest.php | 2 +- .../OwnerEmailNotificationTest.php | 2 +- .../ParticipantEmailNotificationTest.php | 2 +- .../ParticipationNotificationTest.php | 2 +- .../PermissionValidationRuleTest.php | 2 +- .../Application/Reservation/QuotaRuleTest.php | 2 +- .../ReminderValidationRuleTest.php | 2 +- .../Reservation/RequiresApprovalRuleTest.php | 2 +- .../ReservationAuthorizationTest.php | 2 +- .../ReservationCanBeCheckedInRuleTest.php | 2 +- .../ReservationCanBeCheckedOutRuleTest.php | 2 +- .../Reservation/ReservationComponentTest.php | 2 +- .../ReservationConflictResolutionTest.php | 2 +- .../ReservationDateTimeRuleTest.php | 2 +- .../ReservationNotificationFactoryTest.php | 2 +- .../ReservationStartTimeRuleTest.php | 2 +- .../ReservationValidationFactoryTest.php | 2 +- ...ReservationValidationRuleProcessorTest.php | 2 +- .../ResourceAvailabilityRuleTest.php | 2 +- .../Reservation/ResourceCountRuleTest.php | 2 +- .../Reservation/ResourceCrossDayRuleTest.php | 2 +- .../ResourceMaximumDurationRuleTest.php | 2 +- .../ResourceMaximumNoticeRuleTest.php | 2 +- .../ResourceMinimumDurationRuleTest.php | 2 +- .../ResourceMinimumNoticeRuleTest.php | 2 +- .../ResourceParticipationRuleTest.php | 2 +- .../Reservation/RetryOptionsTest.php | 2 +- .../ScheduleAvailabilityRuleTest.php | 2 +- .../Reservation/SchedulePeriodRuleTest.php | 2 +- ...uleTotalConcurrentReservationsRuleTest.php | 2 +- .../Schedule/CalendarMonthTest.php | 2 +- .../CalendarSubscriptionServiceTest.php | 2 +- .../Application/Schedule/CalendarWeekTest.php | 2 +- .../Application/Schedule/DailyLayoutTest.php | 2 +- .../Schedule/LayoutValidatorTest.php | 2 +- .../Schedule/ReservationListingTest.php | 2 +- .../Schedule/ResourcePermissionStoreTest.php | 2 +- .../Schedule/ResourceServiceTest.php | 2 +- .../ScheduleLayoutSerializableTest.php | 2 +- .../Schedule/ScheduleLayoutTest.php | 2 +- .../Schedule/ScheduleReservationListTest.php | 2 +- .../Schedule/ScheduleResourceFilterTest.php | 2 +- .../Schedule/SlotLabelFactoryTest.php | 2 +- .../User/ManageUsersServiceTest.php | 2 +- .../AnnouncementRepositoryTest.php | 2 +- .../Attribute/AttributeRepositoryTest.php | 2 +- .../Domain/Attribute/CustomAttributeTest.php | 2 +- .../Payment/PayPalPaymentResultTest.php | 2 +- .../Domain/Payment/PaymentRepositoryTest.php | 2 +- .../Reporting/ReportCommandBuilderTest.php | 2 +- .../Reporting/ReportingRepositoryTest.php | 2 +- .../Reservation/BlackoutRepositoryTest.php | 2 +- .../ExistingReservationDeleteTest.php | 2 +- .../Reservation/ExistingReservationTest.php | 2 +- .../Reservation/QuotaRepositoryTest.php | 2 +- tests/Domain/Reservation/QuotaTest.php | 2 +- .../Reservation/QuotaWhenModifyingTest.php | 2 +- .../Reservation/ReminderRepositoryTest.php | 2 +- .../Domain/Reservation/RepeatOptionsTest.php | 2 +- .../Reservation/ReservationRepositoryTest.php | 2 +- .../Reservation/ReservationServiceTest.php | 2 +- tests/Domain/Reservation/ReservationTest.php | 2 +- .../ReservationViewRepositoryTest.php | 2 +- .../ReservationWaitlistRepositoryTest.php | 2 +- .../Resource/AccessoryRepositoryTest.php | 2 +- .../Domain/Resource/PermissionServiceTest.php | 2 +- tests/Domain/Resource/ResourceGroupTest.php | 2 +- .../Resource/ResourceRepositoryTest.php | 2 +- tests/Domain/Resource/ResourcesTest.php | 2 +- .../Schedule/ScheduleRepositoryTest.php | 2 +- .../Schedule/ScheduleUserRepositoryTest.php | 2 +- tests/Domain/User/GroupRepositoryTest.php | 2 +- tests/Domain/User/UserRepositoryTest.php | 2 +- .../Domain/User/UserSessionRepositoryTest.php | 2 +- tests/Domain/User/UserTest.php | 2 +- tests/Infrastructure/Common/DateTest.php | 2 +- .../Common/PluginManagerTest__BROKEN.php | 2 +- .../Common/SmartyControlTest.php | 2 +- tests/Infrastructure/Common/ValidatorTest.php | 2 +- tests/Infrastructure/Config/ConfigTest.php | 2 +- .../Database/DatabaseCommandTest.php | 2 +- .../Infrastructure/Database/DatabaseTest.php | 2 +- .../ActiveDirectoryTest_BROKEN.php | 2 +- .../Authentication/Ldap/LdapTest_BROKEN.php | 4 ++-- tests/Presenters/ActivationPresenterTest.php | 2 +- .../Admin/ImportICalPresenterTest.php | 2 +- .../Admin/ManageAccessoriesPresenterTest.php | 2 +- .../Admin/ManageAttributesPresenterTest.php | 2 +- .../Admin/ManageBlackoutsPresenterTest.php | 2 +- .../ManageConfigurationPresenterTest.php | 2 +- .../ManageEmailTemplatesPresenterTest.php | 2 +- .../Admin/ManagePaymentsPresenterTest.php | 2 +- .../Admin/ManageQuotasPresenterTest.php | 2 +- .../Admin/ManageReservationsPresenterTest.php | 2 +- .../ManageResourceGroupsPresenterTest.php | 2 +- .../ManageResourceTypesPresenterTest.php | 2 +- .../Admin/ManageSchedulesPresenterTest.php | 2 +- .../Admin/ManageUsersPresenterTest.php | 2 +- .../AvailableAccessoriesPresenterTest.php | 2 +- .../CalendarExportPresenterTest.php | 2 +- tests/Presenters/CalendarPresenterTest.php | 2 +- .../CalendarSubscriptionPresenterTest.php | 2 +- .../CalendarSubscriptionValidatorTest.php | 2 +- tests/Presenters/CheckoutPresenterTest.php | 2 +- .../Dashboard/AnnouncementPresenterTest.php | 2 +- ...sourceAvailabilityControlPresenterTest.php | 2 +- .../UpcomingReservationsPresenterTest.php | 2 +- .../EmbeddedCalendarPresenterTest.php | 2 +- .../Integrate/SlackPresenterTest.php | 2 +- tests/Presenters/LoginPresenterTest.php | 4 ++-- .../MonitorDisplayPresenterTest.php | 2 +- .../Presenters/ParticipationPresenterTest.php | 2 +- tests/Presenters/PasswordPresenterTest.php | 2 +- .../PersonalCalendarPresenterTest.php | 2 +- tests/Presenters/RegisterPresenterTest.php | 2 +- .../Reports/GenerateReportPresenterTest.php | 2 +- .../Reports/ReportDefinitionTest.php | 2 +- .../Reports/SavedReportsPresenterTest.php | 2 +- .../EditReservationPresenterTest.php | 2 +- .../ExistingReservationInitializerTest.php | 2 +- .../GuestReservationPresenterTest.php | 2 +- .../NewReservationPresenterTest.php | 2 +- .../ReservationApprovalPresenterTest.php | 2 +- .../ReservationAttachmentPresenterTest.php | 2 +- .../ReservationAttributesPresenterTest.php | 2 +- .../ReservationCheckinPresenterTest.php | 2 +- .../ReservationCreditsPresenterTest.php | 2 +- .../ReservationDeletePresenterTest.php | 2 +- .../ReservationEmailPresenterTest.php | 2 +- .../Reservation/ReservationHandlerTest.php | 2 +- .../ReservationInitializationTest.php | 2 +- .../ReservationMovePresenterTest.php | 2 +- .../ReservationSavePresenterTest.php | 2 +- .../ReservationUpdatePresenterTest.php | 2 +- ...servationUserAvailabilityPresenterTest.php | 2 +- .../ReservationWaitlistPresenterTest.php | 2 +- .../ResourceDisplayPresenterTest.php | 2 +- tests/Presenters/SchedulePresenterTest.php | 4 +++- .../SearchReservationsPresenterTest.php | 2 +- .../SearchAvailabilityPresenterTest.php | 2 +- .../UnavailableResourcesPresenterTest.php | 2 +- tests/Presenters/UserCreditsPresenterTest.php | 2 +- .../UserDetailsPopupPresenterTest.php | 2 +- .../WebService/SlimWebServiceRegistryTest.php | 2 +- tests/WebService/WebServiceSecurityTest.php | 2 +- .../WebService/WebServiceUserSessionTest.php | 2 +- .../WebServices/AccessoriesWebServiceTest.php | 2 +- tests/WebServices/AccountWebServiceTest.php | 2 +- .../WebServices/AttributesWebServiceTest.php | 2 +- .../AuthenticationWebServiceTest.php | 2 +- .../Controllers/AccountControllerTest.php | 2 +- .../AttributeSaveControllerTest.php | 2 +- .../ReservationSaveControllerTest.php | 2 +- .../ResourceSaveControllerTest.php | 2 +- .../Controllers/UserSaveControllerTest.php | 2 +- tests/WebServices/GroupsWebServiceTest.php | 2 +- .../ReservationWriteWebServiceTest.php | 2 +- .../ReservationsWebServiceTest.php | 2 +- tests/WebServices/ResourcesWebServiceTest.php | 2 +- .../ResourcesWriteWebServiceTest.php | 2 +- tests/WebServices/SchedulesWebServiceTest.php | 2 +- tests/WebServices/UsersWebServiceTest.php | 2 +- .../WebServices/UsersWriteWebServiceTest.php | 2 +- .../AccountRequestValidatorTest.php | 2 +- .../ResourceRequestValidatorTest.php | 2 +- .../Validators/UserRequestValidatorTest.php | 2 +- tests/fakes/FakeExistingReservationPage.php | 2 ++ tests/fakes/FakePaymentRepository.php | 6 +++++- tests/fakes/FakeReservationViewRepository.php | 4 ++++ tests/fakes/FakeResourceRepository.php | 19 +++++++++++++++++++ tests/fakes/FakeWebAuthentication.php | 2 ++ 207 files changed, 240 insertions(+), 203 deletions(-) diff --git a/.gitignore b/.gitignore index 9d45268ea..633484b68 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,6 @@ # php8 phpcompatibility report php8-report.log + +# phpunit cache +.phpunit.cache/test-results diff --git a/Domain/CreditCost.php b/Domain/CreditCost.php index 344502617..c0babbee2 100644 --- a/Domain/CreditCost.php +++ b/Domain/CreditCost.php @@ -6,6 +6,7 @@ class CreditCost { /** + * Number of Credits for the given cost * @var int */ private $count; diff --git a/tests/Application/Admin/GroupAdminGroupsRepositoryTest.php b/tests/Application/Admin/GroupAdminGroupsRepositoryTest.php index 3175bb5e3..591449ecc 100644 --- a/tests/Application/Admin/GroupAdminGroupsRepositoryTest.php +++ b/tests/Application/Admin/GroupAdminGroupsRepositoryTest.php @@ -2,7 +2,7 @@ require_once(ROOT_DIR . 'lib/Application/Admin/namespace.php'); -class GroupAdminGroupsRepositoryTests extends TestBase +class GroupAdminGroupsRepositoryTest extends TestBase { public function testGetsListOfGroupsThatThisUserCanAdminister() { diff --git a/tests/Application/Admin/GroupAdminManageReservationsServiceTest.php b/tests/Application/Admin/GroupAdminManageReservationsServiceTest.php index edcc791f7..c34a69dd5 100644 --- a/tests/Application/Admin/GroupAdminManageReservationsServiceTest.php +++ b/tests/Application/Admin/GroupAdminManageReservationsServiceTest.php @@ -2,7 +2,7 @@ require_once(ROOT_DIR . 'lib/Application/Admin/namespace.php'); -class GroupAdminManageReservationsServiceTests extends TestBase +class GroupAdminManageReservationsServiceTest extends TestBase { public function testGetsListOfReservationsThatThisUserCanAdminister() { diff --git a/tests/Application/Admin/ManageReservationsServiceTest.php b/tests/Application/Admin/ManageReservationsServiceTest.php index ed0bc2411..97aa631e4 100644 --- a/tests/Application/Admin/ManageReservationsServiceTest.php +++ b/tests/Application/Admin/ManageReservationsServiceTest.php @@ -2,7 +2,7 @@ require_once(ROOT_DIR . 'lib/Application/Admin/namespace.php'); -class ManageReservationsServiceTests extends TestBase +class ManageReservationsServiceTest extends TestBase { /** * @var IReservationViewRepository|PHPUnit_Framework_MockObject_MockObject diff --git a/tests/Application/Admin/ResourceAdminManageReservationsServiceTest.php b/tests/Application/Admin/ResourceAdminManageReservationsServiceTest.php index 6d281a0dd..48d2730ba 100644 --- a/tests/Application/Admin/ResourceAdminManageReservationsServiceTest.php +++ b/tests/Application/Admin/ResourceAdminManageReservationsServiceTest.php @@ -2,7 +2,7 @@ require_once(ROOT_DIR . 'lib/Application/Admin/namespace.php'); -class ResourceAdminManageReservationsServiceTests extends TestBase +class ResourceAdminManageReservationsServiceTest extends TestBase { /** * @var IReservationViewRepository|PHPUnit_Framework_MockObject_MockObject diff --git a/tests/Application/Admin/ResourceAdminResourceRepositoryTest.php b/tests/Application/Admin/ResourceAdminResourceRepositoryTest.php index 1255b96c1..9b85aa577 100644 --- a/tests/Application/Admin/ResourceAdminResourceRepositoryTest.php +++ b/tests/Application/Admin/ResourceAdminResourceRepositoryTest.php @@ -2,7 +2,7 @@ require_once(ROOT_DIR . 'lib/Application/Admin/namespace.php'); -class ResourceAdminResourceRepositoryTests extends TestBase +class ResourceAdminResourceRepositoryTest extends TestBase { /** * @var IUserRepository|PHPUnit_Framework_MockObject_MockObject diff --git a/tests/Application/Admin/ScheduleAdminManageReservationsServiceTest.php b/tests/Application/Admin/ScheduleAdminManageReservationsServiceTest.php index 4ee545332..e546aee52 100644 --- a/tests/Application/Admin/ScheduleAdminManageReservationsServiceTest.php +++ b/tests/Application/Admin/ScheduleAdminManageReservationsServiceTest.php @@ -2,7 +2,7 @@ require_once(ROOT_DIR . 'lib/Application/Admin/namespace.php'); -class ScheduleAdminManageReservationsServiceTests extends TestBase +class ScheduleAdminManageReservationsServiceTest extends TestBase { /** * @var IReservationViewRepository|PHPUnit_Framework_MockObject_MockObject diff --git a/tests/Application/Admin/ScheduleAdminScheduleRepositoryTest.php b/tests/Application/Admin/ScheduleAdminScheduleRepositoryTest.php index c472403f7..2d1ebb36f 100644 --- a/tests/Application/Admin/ScheduleAdminScheduleRepositoryTest.php +++ b/tests/Application/Admin/ScheduleAdminScheduleRepositoryTest.php @@ -2,7 +2,7 @@ require_once(ROOT_DIR . 'lib/Application/Admin/namespace.php'); -class ScheduleAdminScheduleRepositoryTests extends TestBase +class ScheduleAdminScheduleRepositoryTest extends TestBase { /** * @var IUserRepository|PHPUnit_Framework_MockObject_MockObject diff --git a/tests/Application/Attributes/AttributeListTest.php b/tests/Application/Attributes/AttributeListTest.php index da022182a..caea1cedf 100644 --- a/tests/Application/Attributes/AttributeListTest.php +++ b/tests/Application/Attributes/AttributeListTest.php @@ -2,7 +2,7 @@ require_once(ROOT_DIR . 'lib/Application/Attributes/namespace.php'); -class AttributeListTests extends TestBase +class AttributeListTest extends TestBase { public function testCanGetLabelsOfAllAttributes() { diff --git a/tests/Application/Attributes/AttributeServiceTest.php b/tests/Application/Attributes/AttributeServiceTest.php index 4f6432095..07444269f 100644 --- a/tests/Application/Attributes/AttributeServiceTest.php +++ b/tests/Application/Attributes/AttributeServiceTest.php @@ -2,7 +2,7 @@ require_once(ROOT_DIR . 'lib/Application/Attributes/namespace.php'); -class AttributeServiceTests extends TestBase +class AttributeServiceTest extends TestBase { /** * @var AttributeService diff --git a/tests/Application/Attributes/AttributeValidatorTest.php b/tests/Application/Attributes/AttributeValidatorTest.php index 7283202cf..0d989c42c 100644 --- a/tests/Application/Attributes/AttributeValidatorTest.php +++ b/tests/Application/Attributes/AttributeValidatorTest.php @@ -2,7 +2,7 @@ require_once(ROOT_DIR . 'lib/Application/Attributes/namespace.php'); -class AttributeValidatorTests extends TestBase +class AttributeValidatorTest extends TestBase { public function testChecksAttributesAgainstService() { diff --git a/tests/Application/Authentication/AccountActivationTest.php b/tests/Application/Authentication/AccountActivationTest.php index 836ea42c5..541092f25 100644 --- a/tests/Application/Authentication/AccountActivationTest.php +++ b/tests/Application/Authentication/AccountActivationTest.php @@ -1,6 +1,6 @@ _CreditCost = new CreditCost(); } - public function UpdateCreditCost(CreditCost $cost) + public function DeleteCreditCost($creditCount) { } + + public function GetCreditCosts() { } + + public function UpdateCreditCost($cost) { $this->_LastCost = $cost; } diff --git a/tests/fakes/FakeReservationViewRepository.php b/tests/fakes/FakeReservationViewRepository.php index e33786643..308b224ea 100644 --- a/tests/fakes/FakeReservationViewRepository.php +++ b/tests/fakes/FakeReservationViewRepository.php @@ -51,6 +51,10 @@ public function __construct() $this->_FilterResults = new PageableData(); } + public function GetReservationsPendingApproval(Date $startDate, $userIds = ReservationViewRepository::ALL_USERS, $userLevel = ReservationUserLevel::OWNER, $scheduleIds = ReservationViewRepository::ALL_SCHEDULES, $resourceIds = ReservationViewRepository::ALL_RESOURCES, $consolidateByReferenceNumber = false, $participantIds = ReservationViewRepository::ALL_USERS) { } + + public function GetReservationsMissingCheckInCheckOut(?Date $startDate = null, Date $endDate, $userIds = ReservationViewRepository::ALL_USERS, $userLevel = ReservationUserLevel::OWNER, $scheduleIds = ReservationViewRepository::ALL_SCHEDULES, $resourceIds = ReservationViewRepository::ALL_RESOURCES, $consolidateByReferenceNumber = false, $participantIds = ReservationViewRepository::ALL_USERS) { } + public function GetReservationForEditing($referenceNumber) { return $this->_ReservationView; diff --git a/tests/fakes/FakeResourceRepository.php b/tests/fakes/FakeResourceRepository.php index 4155483ae..5bd137906 100644 --- a/tests/fakes/FakeResourceRepository.php +++ b/tests/fakes/FakeResourceRepository.php @@ -27,6 +27,25 @@ class FakeResourceRepository implements IResourceRepository public $_PublicResourceIds = []; + public function GetResourceIdList(): array + { + throw new Exception('Not implemented'); + } + + public function GetUserResourceList() { } + + public function GetUserResourceIdList() { } + + public function GetUserList($resourceIds, $pageNumber, $pageSize, $sortField = null, $sortDirection = null, $filter = null) { } + + public function GetUserResourcePermissions($userId, $resourceIds = []) { } + + public function GetUserGroupResourcePermissions($userId, $resourceIds = []) { } + + public function GetResourceAdminResourceIds($userId, $resourceIds = []) { } + + public function GetScheduleAdminResourceIds($userId, $resourceIds = []) { } + public function GetScheduleResources($scheduleId) { return $this->_ScheduleResourceList; diff --git a/tests/fakes/FakeWebAuthentication.php b/tests/fakes/FakeWebAuthentication.php index a2d87a41e..465545813 100644 --- a/tests/fakes/FakeWebAuthentication.php +++ b/tests/fakes/FakeWebAuthentication.php @@ -168,6 +168,8 @@ class FakeWebAuthentication implements IWebAuthentication public $_IsLoggedIn = false; public $_AreCredentialsKnown = false; + public function postLogout(UserSession $user) { } + public function Validate($username, $password) { $this->_LastLogin = $username; From be075d0937d81679a319a4ac6756401c3fe6ec63 Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Sat, 31 Aug 2024 08:10:12 +0000 Subject: [PATCH 4/6] Fix AddHours in DateClass for negative values The entire helper class does not seem useful to me. I Just made it work. --- lib/Common/Date.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Common/Date.php b/lib/Common/Date.php index 2513301dd..34ada0b00 100644 --- a/lib/Common/Date.php +++ b/lib/Common/Date.php @@ -510,7 +510,7 @@ public function SubtractMinutes($minutes) */ public function AddHours($hours) { - return new Date($this->Format(self::SHORT_FORMAT) . " +" . $hours . " hours", $this->timezone); + return new Date($this->Format(self::SHORT_FORMAT) . $this->getOperator($hours) . abs($hours) . " hours", $this->timezone); } /** From 1df5c347db7e942940ef798df55f4c0916d39f41 Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Sat, 31 Aug 2024 06:34:43 +0000 Subject: [PATCH 5/6] Fix phpunit tests --- Pages/ResourceDisplayPage.php | 8 +- Presenters/ResourceDisplayPresenter.php | 2 +- .../Admin/GroupAdminGroupsRepositoryTest.php | 2 +- ...roupAdminManageReservationsServiceTest.php | 2 +- .../Admin/ManageReservationsServiceTest.php | 8 +- ...urceAdminManageReservationsServiceTest.php | 4 +- .../ResourceAdminResourceRepositoryTest.php | 50 +++--- ...duleAdminManageReservationsServiceTest.php | 4 +- .../ScheduleAdminScheduleRepositoryTest.php | 24 ++- .../Attributes/AttributeValidatorTest.php | 2 +- .../Authentication/AccountActivationTest.php | 6 +- .../Authentication/AuthenticationTest.php | 10 +- .../Authentication/RegistrationTest.php | 10 +- .../WebServiceAuthenticationTest.php | 8 +- .../AuthorizationServiceTest.php | 74 +++------ .../Authorization/PrivacyFilterTest.php | 8 +- .../AccessoryAvailabilityRuleTest.php | 56 +++---- .../AdminEmailNotificationTest.php | 40 ++--- .../Reservation/AdminExcludedRuleTest.php | 43 ++---- .../Reservation/BlackoutsServiceTest.php | 117 ++++++-------- .../CustomAttributeValidationRuleTest.php | 27 ++-- .../ExistingResourceAvailabilityRuleTest.php | 24 ++- .../GuestEmailNotificationTest.php | 12 +- .../InvitationEmailNotificationTest.php | 19 +-- .../OwnerEmailNotificationTest.php | 4 +- .../ParticipantEmailNotificationTest.php | 38 ++--- .../PermissionValidationRuleTest.php | 2 +- .../Application/Reservation/QuotaRuleTest.php | 16 +- .../Reservation/RequiresApprovalRuleTest.php | 4 +- .../ReservationCanBeCheckedInRuleTest.php | 19 ++- .../ReservationCanBeCheckedOutRuleTest.php | 15 +- .../Reservation/ReservationComponentTest.php | 144 +++++++++--------- .../ReservationConflictResolutionTest.php | 2 +- .../ReservationNotificationFactoryTest.php | 8 +- .../ReservationStartTimeRuleTest.php | 8 +- .../ReservationValidationFactoryTest.php | 6 +- ...ReservationValidationRuleProcessorTest.php | 10 +- .../ResourceAvailabilityRuleTest.php | 54 ++++--- .../Reservation/ResourceCrossDayRuleTest.php | 4 +- .../Reservation/SchedulePeriodRuleTest.php | 46 +++--- .../CalendarSubscriptionServiceTest.php | 6 +- .../Application/Schedule/DailyLayoutTest.php | 10 +- .../Schedule/ResourcePermissionStoreTest.php | 6 +- .../Schedule/ResourceServiceTest.php | 138 ++++++----------- .../Schedule/ScheduleReservationListTest.php | 4 +- .../Schedule/ScheduleResourceFilterTest.php | 4 +- .../Schedule/SlotLabelFactoryTest.php | 2 + .../User/ManageUsersServiceTest.php | 25 ++- tests/Domain/Reservation/QuotaTest.php | 10 +- .../Reservation/QuotaWhenModifyingTest.php | 2 +- .../Reservation/ReservationRepositoryTest.php | 2 +- .../Reservation/ReservationServiceTest.php | 6 +- tests/Domain/Reservation/ReservationTest.php | 2 +- .../Domain/Resource/PermissionServiceTest.php | 4 +- .../Resource/ResourceRepositoryTest.php | 6 +- .../Schedule/ScheduleRepositoryTest.php | 29 ++-- tests/Presenters/ActivationPresenterTest.php | 4 +- .../Admin/ManageAccessoriesPresenterTest.php | 18 +-- .../Admin/ManageAttributesPresenterTest.php | 6 +- .../Admin/ManageBlackoutsPresenterTest.php | 64 ++++---- .../ManageConfigurationPresenterTest.php | 8 +- .../Admin/ManagePaymentsPresenterTest.php | 11 +- .../Admin/ManageQuotasPresenterTest.php | 32 ++-- .../Admin/ManageReservationsPresenterTest.php | 133 ++++++++-------- .../ManageResourceGroupsPresenterTest.php | 22 +-- .../ManageResourceTypesPresenterTest.php | 18 +-- .../Admin/ManageSchedulesPresenterTest.php | 52 ++++--- .../Admin/ManageUsersPresenterTest.php | 28 ++-- .../CalendarExportPresenterTest.php | 12 +- tests/Presenters/CalendarPresenterTest.php | 28 ++-- .../CalendarSubscriptionPresenterTest.php | 18 +-- .../CalendarSubscriptionValidatorTest.php | 16 +- tests/Presenters/CheckoutPresenterTest.php | 5 +- .../UpcomingReservationsPresenterTest.php | 4 +- tests/Presenters/LoginPresenterTest.php | 8 +- .../Presenters/ParticipationPresenterTest.php | 56 +++---- tests/Presenters/PasswordPresenterTest.php | 12 +- .../PersonalCalendarPresenterTest.php | 16 +- tests/Presenters/RegisterPresenterTest.php | 9 +- .../Reports/GenerateReportPresenterTest.php | 2 +- .../Reports/SavedReportsPresenterTest.php | 8 +- .../EditReservationPresenterTest.php | 6 +- .../GuestReservationPresenterTest.php | 2 +- .../NewReservationPresenterTest.php | 2 +- .../ReservationApprovalPresenterTest.php | 8 +- .../ReservationAttachmentPresenterTest.php | 38 ++--- .../ReservationAttributesPresenterTest.php | 10 +- .../ReservationCheckinPresenterTest.php | 8 +- .../ReservationCreditsPresenterTest.php | 2 +- .../ReservationDeletePresenterTest.php | 10 +- .../Reservation/ReservationHandlerTest.php | 8 +- .../ReservationInitializationTest.php | 4 +- .../ReservationMovePresenterTest.php | 8 +- .../ReservationSavePresenterTest.php | 22 +-- .../ReservationUpdatePresenterTest.php | 28 ++-- .../ResourceDisplayPresenterTest.php | 28 ++-- tests/Presenters/SchedulePresenterTest.php | 90 +++++------ .../SearchAvailabilityPresenterTest.php | 4 +- tests/Presenters/UserCreditsPresenterTest.php | 2 +- tests/WebService/WebServiceSecurityTest.php | 96 +++++------- .../WebServices/AccessoriesWebServiceTest.php | 6 +- .../WebServices/AttributesWebServiceTest.php | 6 +- .../AuthenticationWebServiceTest.php | 6 +- .../ReservationSaveControllerTest.php | 14 +- .../ResourceSaveControllerTest.php | 41 +++-- .../Controllers/UserSaveControllerTest.php | 22 +-- tests/WebServices/GroupsWebServiceTest.php | 6 +- .../ReservationWriteWebServiceTest.php | 16 +- .../ReservationsWebServiceTest.php | 14 +- tests/WebServices/ResourcesWebServiceTest.php | 61 +++++--- .../ResourcesWriteWebServiceTest.php | 12 +- tests/WebServices/SchedulesWebServiceTest.php | 57 +++---- tests/WebServices/UsersWebServiceTest.php | 64 ++++---- .../WebServices/UsersWriteWebServiceTest.php | 16 +- .../ResourceRequestValidatorTest.php | 2 +- .../Validators/UserRequestValidatorTest.php | 51 +++---- tests/fakes/FakePaymentRepository.php | 7 +- tests/fakes/FakeResourceAccess.php | 4 +- 118 files changed, 1226 insertions(+), 1341 deletions(-) diff --git a/Pages/ResourceDisplayPage.php b/Pages/ResourceDisplayPage.php index f06dff0d6..6e858c412 100644 --- a/Pages/ResourceDisplayPage.php +++ b/Pages/ResourceDisplayPage.php @@ -71,6 +71,12 @@ public function GetTimezone(); */ public function GetBeginTime(); + /** + * + * @return string + */ + public function GetBeginDate(); + /** * @return string */ @@ -237,7 +243,7 @@ public function GetStartDate() } return $startDate; } - + public function BindResource(BookableResource $resource) { $this->Set('ResourceName', $resource->GetName()); diff --git a/Presenters/ResourceDisplayPresenter.php b/Presenters/ResourceDisplayPresenter.php index 48a18846a..bdf1a8fff 100644 --- a/Presenters/ResourceDisplayPresenter.php +++ b/Presenters/ResourceDisplayPresenter.php @@ -248,7 +248,7 @@ public function Reserve() $maxDate = Date::Now()->ToTimezone($timezone)->AddDays($maxFutureDays+1)->GetDate(); $resultCollector = new ReservationResultCollector(); - + if ($date->GetBegin()->GreaterThan($maxDate)) { $resultCollector->SetSaveSuccessfulMessage(false); $resultCollector->SetErrors(["Unauthorized"]); diff --git a/tests/Application/Admin/GroupAdminGroupsRepositoryTest.php b/tests/Application/Admin/GroupAdminGroupsRepositoryTest.php index 591449ecc..c590e2394 100644 --- a/tests/Application/Admin/GroupAdminGroupsRepositoryTest.php +++ b/tests/Application/Admin/GroupAdminGroupsRepositoryTest.php @@ -16,7 +16,7 @@ public function testGetsListOfGroupsThatThisUserCanAdminister() $userRepo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($user)); + ->willReturn($user); $groupRepository = new GroupAdminGroupRepository($userRepo, $this->fakeUser); diff --git a/tests/Application/Admin/GroupAdminManageReservationsServiceTest.php b/tests/Application/Admin/GroupAdminManageReservationsServiceTest.php index c34a69dd5..3d736a015 100644 --- a/tests/Application/Admin/GroupAdminManageReservationsServiceTest.php +++ b/tests/Application/Admin/GroupAdminManageReservationsServiceTest.php @@ -19,7 +19,7 @@ public function testGetsListOfReservationsThatThisUserCanAdminister() $userRepo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($user)); + ->willReturn($user); $service = new GroupAdminManageReservationsService($reservationRepo, $userRepo, $reservationAuth, $handler, $persistenceService); diff --git a/tests/Application/Admin/ManageReservationsServiceTest.php b/tests/Application/Admin/ManageReservationsServiceTest.php index 97aa631e4..ec8be77c1 100644 --- a/tests/Application/Admin/ManageReservationsServiceTest.php +++ b/tests/Application/Admin/ManageReservationsServiceTest.php @@ -58,7 +58,7 @@ public function testLoadsFilteredResultsAndChecksAuthorizationAgainstPendingRese $this->reservationViewRepository->expects($this->once()) ->method('GetList') ->with($pageNumber, $pageSize, null, null, $filter->GetFilter()) - ->will($this->returnValue($data)); + ->willReturn($data); $actualData = $this->service->LoadFiltered($pageNumber, $pageSize, null, null, $filter, $this->fakeUser); @@ -74,12 +74,12 @@ public function testLoadsReservationIfTheUserCanEdit() $this->reservationViewRepository->expects($this->once()) ->method('GetReservationForEditing') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($reservation)); + ->willReturn($reservation); $this->reservationAuthorization->expects($this->once()) ->method('CanEdit') ->with($this->equalTo($reservation), $this->equalTo($user)) - ->will($this->returnValue(true)); + ->willReturn(true); $res = $this->service->LoadByReferenceNumber($referenceNumber, $user); @@ -103,7 +103,7 @@ public function testUpdatesReservationAttributeIfTheUserCanEdit() $this->persistenceService->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($reservation)); + ->willReturn($reservation); $this->reservationHandler->expects($this->once()) ->method('Handle') diff --git a/tests/Application/Admin/ResourceAdminManageReservationsServiceTest.php b/tests/Application/Admin/ResourceAdminManageReservationsServiceTest.php index 48d2730ba..b9629eab5 100644 --- a/tests/Application/Admin/ResourceAdminManageReservationsServiceTest.php +++ b/tests/Application/Admin/ResourceAdminManageReservationsServiceTest.php @@ -53,7 +53,7 @@ public function testLoadsFilteredResultsAndChecksAuthorizationAgainstPendingRese $this->userRepository->expects($this->once()) ->method('LoadGroups') ->with($this->equalTo($this->fakeUser->UserId), $this->equalTo(RoleLevel::RESOURCE_ADMIN)) - ->will($this->returnValue($groups)); + ->willReturn($groups); $filter = new ReservationFilter(); $expectedFilter = $filter->GetFilter(); @@ -63,7 +63,7 @@ public function testLoadsFilteredResultsAndChecksAuthorizationAgainstPendingRese $this->reservationViewRepository->expects($this->once()) ->method('GetList') ->with($pageNumber, $pageSize, null, null, $expectedFilter) - ->will($this->returnValue($data)); + ->willReturn($data); $actualData = $this->service->LoadFiltered($pageNumber, $pageSize, null, null, $filter, $this->fakeUser); diff --git a/tests/Application/Admin/ResourceAdminResourceRepositoryTest.php b/tests/Application/Admin/ResourceAdminResourceRepositoryTest.php index 9b85aa577..79634cbf2 100644 --- a/tests/Application/Admin/ResourceAdminResourceRepositoryTest.php +++ b/tests/Application/Admin/ResourceAdminResourceRepositoryTest.php @@ -1,11 +1,13 @@ userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($user)); + ->willReturn($user); $ra = new FakeResourceAccess(); - $this->db->SetRows($ra->GetRows()); - - $user->expects($this->at(0)) - ->method('IsResourceAdminFor') - ->with($this->equalTo($ra->_Resources[0])) - ->will($this->returnValue(false)); + $this->db->SetRows($ra->Rows()); - $user->expects($this->at(1)) + $user->expects($this->exactly(2)) ->method('IsResourceAdminFor') - ->with($this->equalTo($ra->_Resources[1])) - ->will($this->returnValue(true)); + ->willReturnCallback(function ($resource) use ($ra) + { + return $this + ->equalTo($ra->_Resources[1]) + ->evaluate($resource, '', true); + }); $repo = new ResourceAdminResourceRepository($this->userRepository, $this->fakeUser); $resources = $repo->GetResourceList(); @@ -58,7 +59,7 @@ public function testOnlyGetsPageableResourcesWhereUserIsAdmin() $this->userRepository->expects($this->once()) ->method('LoadGroups') ->with($this->equalTo($this->fakeUser->UserId), $this->equalTo([RoleLevel::SCHEDULE_ADMIN, RoleLevel::RESOURCE_ADMIN])) - ->will($this->returnValue($groups)); + ->willReturn($groups); $repo = new ResourceAdminResourceRepository($this->userRepository, $this->fakeUser); $repo->GetList($pageNum, $pageSize, null, null, $existingFilter); @@ -78,16 +79,16 @@ public function testDoesNotUpdateResourceIfUserDoesNotHaveAccess() $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($user)); + ->willReturn($user); $repo = new ResourceAdminResourceRepository($this->userRepository, $this->fakeUser); $resource = new FakeBookableResource(1); $resource->SetAdminGroupId(2); - $user->expects($this->at(0)) + $user->expects($this->once()) ->method('IsResourceAdminFor') ->with($this->equalTo($resource)) - ->will($this->returnValue(false)); + ->willReturn(false); $actualEx = null; try { @@ -105,20 +106,19 @@ public function testGetsScheduleResourcesUserHasAdminRightsTo() $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($user)); + ->willReturn($user); $ra = new FakeResourceAccess(); - $this->db->SetRows($ra->GetRows()); - - $user->expects($this->at(0)) - ->method('IsResourceAdminFor') - ->with($this->equalTo($ra->_Resources[0])) - ->will($this->returnValue(false)); + $this->db->SetRows($ra->Rows()); - $user->expects($this->at(1)) + $user->expects($this->exactly(2)) ->method('IsResourceAdminFor') - ->with($this->equalTo($ra->_Resources[1])) - ->will($this->returnValue(true)); + ->willReturnCallback(function ($resource) use ($ra) + { + return $this + ->equalTo($ra->_Resources[1]) + ->evaluate($resource, '', true); + }); $repo = new ResourceAdminResourceRepository($this->userRepository, $this->fakeUser); $resources = $repo->GetScheduleResources($scheduleId); diff --git a/tests/Application/Admin/ScheduleAdminManageReservationsServiceTest.php b/tests/Application/Admin/ScheduleAdminManageReservationsServiceTest.php index e546aee52..52274bfe3 100644 --- a/tests/Application/Admin/ScheduleAdminManageReservationsServiceTest.php +++ b/tests/Application/Admin/ScheduleAdminManageReservationsServiceTest.php @@ -53,7 +53,7 @@ public function testLoadsFilteredResultsAndChecksAuthorizationAgainstPendingRese $this->userRepository->expects($this->once()) ->method('LoadGroups') ->with($this->equalTo($this->fakeUser->UserId), $this->equalTo(RoleLevel::SCHEDULE_ADMIN)) - ->will($this->returnValue($groups)); + ->willReturn($groups); $filter = new ReservationFilter(); $expectedFilter = $filter->GetFilter(); @@ -63,7 +63,7 @@ public function testLoadsFilteredResultsAndChecksAuthorizationAgainstPendingRese $this->reservationViewRepository->expects($this->once()) ->method('GetList') ->with($pageNumber, $pageSize, null, null, $expectedFilter) - ->will($this->returnValue($data)); + ->willReturn($data); $actualData = $this->service->LoadFiltered($pageNumber, $pageSize, null, null, $filter, $this->fakeUser); diff --git a/tests/Application/Admin/ScheduleAdminScheduleRepositoryTest.php b/tests/Application/Admin/ScheduleAdminScheduleRepositoryTest.php index 2d1ebb36f..e27571a02 100644 --- a/tests/Application/Admin/ScheduleAdminScheduleRepositoryTest.php +++ b/tests/Application/Admin/ScheduleAdminScheduleRepositoryTest.php @@ -34,20 +34,19 @@ public function testOnlyGetsSchedulesWhereUserIsAdmin() $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($user)); + ->willReturn($user); $ra = new FakeScheduleRepository(); $this->db->SetRows($ra->GetRows()); - $user->expects($this->at(0)) + $user->expects($this->exactly(2)) ->method('IsScheduleAdminFor') - ->with($this->equalTo($ra->_AllRows[0])) - ->will($this->returnValue(false)); - - $user->expects($this->at(1)) - ->method('IsScheduleAdminFor') - ->with($this->equalTo($ra->_AllRows[1])) - ->will($this->returnValue(true)); + ->willReturnCallback(function ($schedule) use ($ra) + { + return $this + ->equalTo($ra->_AllRows[1]) + ->evaluate($schedule, '', true); + }); $schedules = $this->repo->GetAll(); @@ -62,15 +61,14 @@ public function testDoesNotUpdateScheduleIfUserDoesNotHaveAccess() $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($user)); + ->willReturn($user); $schedule = new FakeSchedule(1); $schedule->SetAdminGroupId(2); - $user->expects($this->at(0)) + $user->expects($this->atLeastOnce()) ->method('IsScheduleAdminFor') - ->with($this->equalTo($schedule)) - ->will($this->returnValue(false)); + ->willReturn(false); $actualEx = null; try { diff --git a/tests/Application/Attributes/AttributeValidatorTest.php b/tests/Application/Attributes/AttributeValidatorTest.php index 0d989c42c..ea0d3f5a3 100644 --- a/tests/Application/Attributes/AttributeValidatorTest.php +++ b/tests/Application/Attributes/AttributeValidatorTest.php @@ -18,7 +18,7 @@ public function testChecksAttributesAgainstService() $service->expects($this->once()) ->method('Validate') ->with($this->equalTo($category), $this->equalTo($attributes), $this->equalTo($entityId)) - ->will($this->returnValue($serviceResult)); + ->willReturn($serviceResult); $validator = new AttributeValidator($service, $category, $attributes, $entityId); $validator->Validate(); diff --git a/tests/Application/Authentication/AccountActivationTest.php b/tests/Application/Authentication/AccountActivationTest.php index 541092f25..f23265903 100644 --- a/tests/Application/Authentication/AccountActivationTest.php +++ b/tests/Application/Authentication/AccountActivationTest.php @@ -51,7 +51,7 @@ public function testWhenActivationCodeIsValid() $this->activationRepo->expects($this->once()) ->method('FindUserIdByCode') ->with($this->equalTo($activationCode)) - ->will($this->returnValue($userId)); + ->willReturn($userId); $this->activationRepo->expects($this->once()) ->method('DeleteActivation') @@ -60,7 +60,7 @@ public function testWhenActivationCodeIsValid() $this->userRepo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue($user)); + ->willReturn($user); $this->userRepo->expects($this->once()) ->method('Update') @@ -80,7 +80,7 @@ public function testWhenActivationCodeIsInvalid() $this->activationRepo->expects($this->once()) ->method('FindUserIdByCode') ->with($this->equalTo($activationCode)) - ->will($this->returnValue(null)); + ->willReturn(null); $result = $this->activation->Activate($activationCode); diff --git a/tests/Application/Authentication/AuthenticationTest.php b/tests/Application/Authentication/AuthenticationTest.php index 35bd29da3..20a6dfbcd 100644 --- a/tests/Application/Authentication/AuthenticationTest.php +++ b/tests/Application/Authentication/AuthenticationTest.php @@ -137,7 +137,7 @@ public function testLoginGetsUserDataFromDatabase() $this->userRepository->expects($this->once()) ->method('LoadByUsername') ->with($this->equalTo($this->username)) - ->will($this->returnValue($this->user)); + ->willReturn($this->user); LoginTime::$Now = time(); @@ -150,22 +150,22 @@ public function testLoginGetsUserDataFromDatabase() $this->authorization->expects($this->once()) ->method('IsApplicationAdministrator') ->with($this->equalTo($this->user)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->authorization->expects($this->once()) ->method('IsGroupAdministrator') ->with($this->equalTo($this->user)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->authorization->expects($this->once()) ->method('IsResourceAdministrator') ->with($this->equalTo($this->user)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->authorization->expects($this->once()) ->method('IsScheduleAdministrator') ->with($this->equalTo($this->user)) - ->will($this->returnValue(true)); + ->willReturn(true); $context = new WebLoginContext(new LoginData(false, $language)); $actualSession = $this->auth->Login($this->username, $context); diff --git a/tests/Application/Authentication/RegistrationTest.php b/tests/Application/Authentication/RegistrationTest.php index baec63824..31aadaac1 100644 --- a/tests/Application/Authentication/RegistrationTest.php +++ b/tests/Application/Authentication/RegistrationTest.php @@ -197,7 +197,7 @@ public function testAutoAssignsAllResourcesForThisUser() $this->userRepository->expects($this->once()) ->method('Add') ->with($this->anything()) - ->will($this->returnValue($expectedUserId)); + ->willReturn($expectedUserId); $this->registration->Register( $this->login, @@ -282,17 +282,17 @@ public function testSynchronizeUpdatesExistingUser() $this->userRepository->expects($this->once()) ->method('UserExists') ->with($this->equalTo($email), $this->equalTo($username)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->userRepository->expects($this->once()) ->method('LoadByUsername') ->with($this->equalTo($username)) - ->will($this->returnValue($updatedUser)); + ->willReturn($updatedUser); $this->userRepository->expects($this->once()) ->method('Update') ->with($this->equalTo($updatedUser)) - ->will($this->returnValue($updatedUser)); + ->willReturn($updatedUser); $user = new AuthenticatedUser($username, $email, $fname, $lname, 'password', 'en_US', 'UTC', $phone, $inst, $title, ['1', '2']); $expectedCommand = new UpdateUserFromLdapCommand($username, $email, $fname, $lname, $encryptedPassword, $salt, $phone, $inst, $title); @@ -342,7 +342,7 @@ public function testSynchronizeRegistersNewUser() $this->userRepository->expects($this->once()) ->method('UserExists') ->with($this->equalTo($email), $this->equalTo($username)) - ->will($this->returnValue(null)); + ->willReturn(null); $this->userRepository->expects($this->once()) ->method('Add') diff --git a/tests/Application/Authentication/WebServiceAuthenticationTest.php b/tests/Application/Authentication/WebServiceAuthenticationTest.php index 29676f2c7..b6e6b5c98 100644 --- a/tests/Application/Authentication/WebServiceAuthenticationTest.php +++ b/tests/Application/Authentication/WebServiceAuthenticationTest.php @@ -54,7 +54,7 @@ public function testSuccessfulLoginSetsSessionInDatabase() $this->userSessionRepository->expects($this->once()) ->method('LoadBySessionToken') ->with($this->equalTo($expectedSession->SessionToken)) - ->will($this->returnValue(null)); + ->willReturn(null); $this->userSessionRepository->expects($this->once()) ->method('Add') @@ -74,7 +74,7 @@ public function testUpdateWhenSessionExistsInDatabase() $this->userSessionRepository->expects($this->once()) ->method('LoadBySessionToken') ->with($this->equalTo($expectedSession->SessionToken)) - ->will($this->returnValue(new WebServiceUserSession(123))); + ->willReturn(new WebServiceUserSession(123)); $this->userSessionRepository->expects($this->once()) ->method('Update') @@ -96,7 +96,7 @@ public function testLogsUserOutIfUserIdAndSessionTokenMatch() $this->userSessionRepository->expects($this->once()) ->method('LoadBySessionToken') ->with($this->equalTo($sessionToken)) - ->will($this->returnValue($userSession)); + ->willReturn($userSession); $this->userSessionRepository->expects($this->once()) ->method('Delete') @@ -117,7 +117,7 @@ public function testDoesNotLogUserOutIfUserIdAndSessionTokenMismatch() $this->userSessionRepository->expects($this->once()) ->method('LoadBySessionToken') ->with($this->equalTo($sessionToken)) - ->will($this->returnValue($userSession)); + ->willReturn($userSession); $this->webAuth->Logout($userId, $sessionToken); diff --git a/tests/Application/Authorization/AuthorizationServiceTest.php b/tests/Application/Authorization/AuthorizationServiceTest.php index db75a3173..254cd86f5 100644 --- a/tests/Application/Authorization/AuthorizationServiceTest.php +++ b/tests/Application/Authorization/AuthorizationServiceTest.php @@ -34,21 +34,16 @@ public function testCanReserveForOthersIfUserIsAdminOrGroupAdmin() $groupAdmin->expects($this->once()) ->method('IsGroupAdmin') - ->will($this->returnValue(true)); + ->willReturn(true); $normalDude->expects($this->once()) ->method('IsGroupAdmin') - ->will($this->returnValue(false)); + ->willReturn(false); - $this->userRepository->expects($this->at(0)) + $this->userRepository->expects($this->exactly(2)) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue($groupAdmin)); - - $this->userRepository->expects($this->at(1)) - ->method('LoadById') - ->with($this->equalTo($userId)) - ->will($this->returnValue($normalDude)); + ->willReturn($groupAdmin, $normalDude); $asAdmin = $this->authorizationService->CanReserveForOthers($adminUser); $asGroupAdmin = $this->authorizationService->CanReserveForOthers($user); @@ -73,36 +68,19 @@ public function testCanReserveForAnotherUserIfAdminOrGroupAdmin() $reserveForUser = $this->createMock('User'); // group admin - $this->userRepository->expects($this->at(0)) - ->method('LoadById') - ->with($this->equalTo($userId)) - ->will($this->returnValue($groupAdmin)); - - $this->userRepository->expects($this->at(1)) + $this->userRepository->expects($this->exactly(4)) ->method('LoadById') - ->with($this->equalTo($reserveForId)) - ->will($this->returnValue($reserveForUser)); + ->willReturn($groupAdmin, $reserveForUser, $normalDude, $reserveForUser); $groupAdmin->expects($this->once()) ->method('IsAdminFor') ->with($this->equalTo($reserveForUser)) - ->will($this->returnValue(true)); - - // normal dude - $this->userRepository->expects($this->at(2)) - ->method('LoadById') - ->with($this->equalTo($userId)) - ->will($this->returnValue($normalDude)); - - $this->userRepository->expects($this->at(3)) - ->method('LoadById') - ->with($this->equalTo($reserveForId)) - ->will($this->returnValue($reserveForUser)); + ->willReturn(true); $normalDude->expects($this->once()) ->method('IsAdminFor') ->with($this->equalTo($reserveForUser)) - ->will($this->returnValue(false)); + ->willReturn(false); $asAdmin = $this->authorizationService->CanReserveFor($adminUser, $reserveForId); $asGroupAdmin = $this->authorizationService->CanReserveFor($user, $reserveForId); @@ -128,36 +106,20 @@ public function testCanApproveForAnotherUserIfAdminOrGroupAdmin() $reserveForUser = $this->createMock('User'); // group admin - $this->userRepository->expects($this->at(0)) - ->method('LoadById') - ->with($this->equalTo($userId)) - ->will($this->returnValue($groupAdmin)); - - $this->userRepository->expects($this->at(1)) + $this->userRepository->expects($this->exactly(4)) ->method('LoadById') - ->with($this->equalTo($reserveForId)) - ->will($this->returnValue($reserveForUser)); + ->willReturn($groupAdmin, $reserveForUser, $normalDude, $reserveForUser); $groupAdmin->expects($this->once()) ->method('IsAdminFor') ->with($this->equalTo($reserveForUser)) - ->will($this->returnValue(true)); + ->willReturn(true); // normal dude - $this->userRepository->expects($this->at(2)) - ->method('LoadById') - ->with($this->equalTo($userId)) - ->will($this->returnValue($normalDude)); - - $this->userRepository->expects($this->at(3)) - ->method('LoadById') - ->with($this->equalTo($reserveForId)) - ->will($this->returnValue($reserveForUser)); - $normalDude->expects($this->once()) ->method('IsAdminFor') ->with($this->equalTo($reserveForUser)) - ->will($this->returnValue(false)); + ->willReturn(false); $asAdmin = $this->authorizationService->CanApproveFor($adminUser, $reserveForId); $asGroupAdmin = $this->authorizationService->CanApproveFor($user, $reserveForId); @@ -244,15 +206,15 @@ public function testCanEditReservationOnResourceIfUserIsAdminOfThatResource() $groupAdmin = $this->createMock('User'); $resource = $this->createMock('IResource'); - $this->userRepository->expects($this->at(0)) + $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue($groupAdmin)); + ->willReturn($groupAdmin); $groupAdmin->expects($this->once()) ->method('IsResourceAdminFor') ->with($this->equalTo($resource)) - ->will($this->returnValue(true)); + ->willReturn(true); $canEdit = $this->authorizationService->CanEditForResource($userSession, $resource); @@ -268,15 +230,15 @@ public function testCanApproveReservationOnResourceIfUserIsAdminOfThatResource() $groupAdmin = $this->createMock('User'); $resource = $this->createMock('IResource'); - $this->userRepository->expects($this->at(0)) + $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue($groupAdmin)); + ->willReturn($groupAdmin); $groupAdmin->expects($this->once()) ->method('IsResourceAdminFor') ->with($this->equalTo($resource)) - ->will($this->returnValue(true)); + ->willReturn(true); $canApprove = $this->authorizationService->CanApproveForResource($userSession, $resource); diff --git a/tests/Application/Authorization/PrivacyFilterTest.php b/tests/Application/Authorization/PrivacyFilterTest.php index acf521acd..919d0fd14 100644 --- a/tests/Application/Authorization/PrivacyFilterTest.php +++ b/tests/Application/Authorization/PrivacyFilterTest.php @@ -79,7 +79,7 @@ public function testChecksReservationAuthorizationAndCachesResultIfUserNotAnAdmi $this->reservationAuthorization->expects($this->once()) ->method('CanViewDetails') ->with($this->equalTo($reservation), $this->equalTo($user)) - ->will($this->returnValue(true)); + ->willReturn(true); $canView = $this->privacyFilter->CanViewUser($user, $reservation); $canView2 = $this->privacyFilter->CanViewUser($user, $reservation); @@ -144,7 +144,7 @@ public function testReservationDetailsChecksReservationAuthorizationAndCachesRes $this->reservationAuthorization->expects($this->once()) ->method('CanViewDetails') ->with($this->equalTo($reservation), $this->equalTo($user)) - ->will($this->returnValue(true)); + ->willReturn(true); $canView = $this->privacyFilter->CanViewDetails($user, $reservation); $canView2 = $this->privacyFilter->CanViewDetails($user, $reservation); @@ -165,7 +165,7 @@ public function testHidesPast() $this->reservationAuthorization->expects($this->once()) ->method('CanViewDetails') ->with($this->equalTo($res), $this->equalTo($user)) - ->will($this->returnValue(false)); + ->willReturn(false); $canView = $this->privacyFilter->CanViewDetails($user, $res); @@ -184,7 +184,7 @@ public function testHidesFuture() $this->reservationAuthorization->expects($this->once()) ->method('CanViewDetails') ->with($this->equalTo($res), $this->equalTo($user)) - ->will($this->returnValue(false)); + ->willReturn(false); $canView = $this->privacyFilter->CanViewDetails($user, $res); diff --git a/tests/Application/Reservation/AccessoryAvailabilityRuleTest.php b/tests/Application/Reservation/AccessoryAvailabilityRuleTest.php index 9ba135279..dc6be8699 100644 --- a/tests/Application/Reservation/AccessoryAvailabilityRuleTest.php +++ b/tests/Application/Reservation/AccessoryAvailabilityRuleTest.php @@ -60,25 +60,19 @@ public function testRuleIsValidIfTotalQuantityReservedIsLessThanQuantityAvailabl $accessoryReservation = new AccessoryReservation(2, $startDate, $endDate, $accessory1->AccessoryId, 3); $accessoryReservationForOtherResource = new AccessoryReservation(2, $startDate, $endDate, $accessory1->AccessoryId, 3); - $this->accessoryRepository->expects($this->at(0)) + $this->accessoryRepository->expects($this->exactly(2)) ->method('LoadById') - ->with($accessory1->AccessoryId) - ->will($this->returnValue(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable))); - - $this->accessoryRepository->expects($this->at(1)) - ->method('LoadById') - ->with($accessory2->AccessoryId) - ->will($this->returnValue(new Accessory($accessory2->AccessoryId, 'name1', $quantityAvailable))); + ->willReturnMap([ + [$accessory1->AccessoryId, new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable)], + [$accessory2->AccessoryId, new Accessory($accessory2->AccessoryId, 'name2', $quantityAvailable)] + ]); - $this->reservationRepository->expects($this->at(0)) + $this->reservationRepository->expects($this->exactly(2)) ->method('GetAccessoriesWithin') - ->with($this->equalTo($dr1)) - ->will($this->returnValue([$accessoryReservation, $accessoryReservationForOtherResource])); - - $this->reservationRepository->expects($this->at(1)) - ->method('GetAccessoriesWithin') - ->with($this->equalTo($dr2)) - ->will($this->returnValue([])); + ->willReturnMap([ + [$dr1, [$accessoryReservation, $accessoryReservationForOtherResource]], + [$dr2, []] + ]); $result = $this->rule->Validate($reservation, null); @@ -102,15 +96,15 @@ public function testGetsConflictingReservationTimes() $lowerQuantity2 = new AccessoryReservation(3, $startDate, $endDate, $accessory1->AccessoryId, 2); $notOnReservation = new AccessoryReservation(4, $startDate, $endDate, 100, 1); - $this->accessoryRepository->expects($this->at(0)) + $this->accessoryRepository->expects($this->once()) ->method('LoadById') ->with($accessory1->AccessoryId) - ->will($this->returnValue(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable))); + ->willReturn(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable)); - $this->reservationRepository->expects($this->at(0)) + $this->reservationRepository->expects($this->once()) ->method('GetAccessoriesWithin') ->with($this->equalTo($dr1)) - ->will($this->returnValue([$lowerQuantity1, $lowerQuantity2, $notOnReservation])); + ->willReturn([$lowerQuantity1, $lowerQuantity2, $notOnReservation]); $result = $this->rule->Validate($reservation, null); @@ -128,15 +122,15 @@ public function testNoConflictsButTooHigh() $reservation->WithDuration($dr1); $reservation->WithAccessory($accessory1); - $this->accessoryRepository->expects($this->at(0)) + $this->accessoryRepository->expects($this->once()) ->method('LoadById') ->with($accessory1->AccessoryId) - ->will($this->returnValue(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable))); + ->willReturn(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable)); $this->reservationRepository->expects($this->once(0)) ->method('GetAccessoriesWithin') ->with($this->anything()) - ->will($this->returnValue([])); + ->willReturn([]); $result = $this->rule->Validate($reservation, null); @@ -157,10 +151,10 @@ public function testUnlimitedQuantity() $dr1 = new DateRange($startDate, $endDate); $reservation->WithDuration($dr1); - $this->accessoryRepository->expects($this->at(0)) + $this->accessoryRepository->expects($this->once()) ->method('LoadById') ->with($accessory1->AccessoryId) - ->will($this->returnValue(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable))); + ->willReturn(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable)); $result = $this->rule->Validate($reservation, null); @@ -186,14 +180,14 @@ public function testExistingLongRunningReservation() $a1 = new AccessoryReservation(2, Date::Parse('2010-04-04 10:00', 'UTC'), Date::Parse('2010-04-04 12:00', 'UTC'), $accessory1->AccessoryId, 1); $a2 = new AccessoryReservation(3, Date::Parse('2010-04-04 13:00', 'UTC'), Date::Parse('2010-04-04 15:00', 'UTC'), $accessory1->AccessoryId, 1); - $this->accessoryRepository->expects($this->at(0)) + $this->accessoryRepository->expects($this->once()) ->method('LoadById') ->with($accessory1->AccessoryId) - ->will($this->returnValue(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable))); + ->willReturn(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable)); - $this->reservationRepository->expects($this->any()) + $this->reservationRepository->expects($this->atLeast(1)) ->method('GetAccessoriesWithin') - ->will($this->returnValue([$accessoryReservation, $a1, $a2])); + ->willReturn([$accessoryReservation, $a1, $a2]); $result = $this->rule->Validate($reservation, null); @@ -221,11 +215,11 @@ public function testMultipleReservationsButNoneOverlapping() $this->accessoryRepository->expects($this->any()) ->method('LoadById') ->with($accessory->AccessoryId) - ->will($this->returnValue(new Accessory($accessory->AccessoryId, 'name1', $quantityAvailable))); + ->willReturn(new Accessory($accessory->AccessoryId, 'name1', $quantityAvailable)); $this->reservationRepository->expects($this->any()) ->method('GetAccessoriesWithin') - ->will($this->returnValue([$ar1, $ar2, $ar3, $ar4])); + ->willReturn([$ar1, $ar2, $ar3, $ar4]); $result = $this->rule->Validate($reservation, null); diff --git a/tests/Application/Reservation/AdminEmailNotificationTest.php b/tests/Application/Reservation/AdminEmailNotificationTest.php index 50a76b3a4..081198c2f 100644 --- a/tests/Application/Reservation/AdminEmailNotificationTest.php +++ b/tests/Application/Reservation/AdminEmailNotificationTest.php @@ -47,21 +47,21 @@ public function testSendsReservationCreatedEmailIfAdminWantsIt() $userRepo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($owner)); + ->willReturn($owner); $userRepo->expects($this->once()) ->method('GetResourceAdmins') ->with($this->equalTo($resourceId)) - ->will($this->returnValue($resourceAdmins)); + ->willReturn($resourceAdmins); $userRepo->expects($this->once()) ->method('GetApplicationAdmins') - ->will($this->returnValue($appAdmins)); + ->willReturn($appAdmins); $userRepo->expects($this->once()) ->method('GetGroupAdmins') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($groupAdmins)); + ->willReturn($groupAdmins); $this->EnableNotifyFor(ConfigKeys::NOTIFY_CREATE_RESOURCE_ADMINS); $this->EnableNotifyFor(ConfigKeys::NOTIFY_CREATE_APPLICATION_ADMINS); @@ -107,21 +107,21 @@ public function testSendsReservationUpdatedEmailIfAdminWantsIt() $userRepo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($owner)); + ->willReturn($owner); $userRepo->expects($this->once()) ->method('GetResourceAdmins') ->with($this->equalTo($resourceId)) - ->will($this->returnValue($resourceAdmins)); + ->willReturn($resourceAdmins); $userRepo->expects($this->once()) ->method('GetApplicationAdmins') - ->will($this->returnValue($appAdmins)); + ->willReturn($appAdmins); $userRepo->expects($this->once()) ->method('GetGroupAdmins') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($groupAdmins)); + ->willReturn($groupAdmins); $this->EnableNotifyFor(ConfigKeys::NOTIFY_UPDATE_RESOURCE_ADMINS); $this->EnableNotifyFor(ConfigKeys::NOTIFY_UPDATE_APPLICATION_ADMINS); @@ -168,21 +168,21 @@ public function testSendsReservationCreatedRequiresApprovalEmailIfAdminWantsIt() $userRepo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($owner)); + ->willReturn($owner); $userRepo->expects($this->once()) ->method('GetResourceAdmins') ->with($this->equalTo($resourceId)) - ->will($this->returnValue($resourceAdmins)); + ->willReturn($resourceAdmins); $userRepo->expects($this->once()) ->method('GetApplicationAdmins') - ->will($this->returnValue($appAdmins)); + ->willReturn($appAdmins); $userRepo->expects($this->once()) ->method('GetGroupAdmins') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($groupAdmins)); + ->willReturn($groupAdmins); $this->EnableNotifyFor(ConfigKeys::NOTIFY_APPROVAL_RESOURCE_ADMINS); $this->EnableNotifyFor(ConfigKeys::NOTIFY_APPROVAL_APPLICATION_ADMINS); @@ -254,21 +254,21 @@ public function testSendsReservationUpdatedRequiresApprovalEmailIfAdminWantsIt() $userRepo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($owner)); + ->willReturn($owner); $userRepo->expects($this->once()) ->method('GetResourceAdmins') ->with($this->equalTo($resourceId)) - ->will($this->returnValue($resourceAdmins)); + ->willReturn($resourceAdmins); $userRepo->expects($this->once()) ->method('GetApplicationAdmins') - ->will($this->returnValue($appAdmins)); + ->willReturn($appAdmins); $userRepo->expects($this->once()) ->method('GetGroupAdmins') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($groupAdmins)); + ->willReturn($groupAdmins); $this->EnableNotifyFor(ConfigKeys::NOTIFY_APPROVAL_RESOURCE_ADMINS); $this->EnableNotifyFor(ConfigKeys::NOTIFY_APPROVAL_APPLICATION_ADMINS); @@ -314,21 +314,21 @@ public function testSendsReservationDeletedEmailIfAdminWantsIt() $userRepo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($owner)); + ->willReturn($owner); $userRepo->expects($this->once()) ->method('GetResourceAdmins') ->with($this->equalTo($resourceId)) - ->will($this->returnValue($resourceAdmins)); + ->willReturn($resourceAdmins); $userRepo->expects($this->once()) ->method('GetApplicationAdmins') - ->will($this->returnValue($appAdmins)); + ->willReturn($appAdmins); $userRepo->expects($this->once()) ->method('GetGroupAdmins') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($groupAdmins)); + ->willReturn($groupAdmins); $this->EnableNotifyFor(ConfigKeys::NOTIFY_DELETE_RESOURCE_ADMINS); $this->EnableNotifyFor(ConfigKeys::NOTIFY_DELETE_APPLICATION_ADMINS); diff --git a/tests/Application/Reservation/AdminExcludedRuleTest.php b/tests/Application/Reservation/AdminExcludedRuleTest.php index 32efb0802..82ad620c0 100644 --- a/tests/Application/Reservation/AdminExcludedRuleTest.php +++ b/tests/Application/Reservation/AdminExcludedRuleTest.php @@ -65,17 +65,11 @@ public function testIfUserIsAdminForAllResources_ReturnTrue() $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($this->user)); + ->willReturn($this->user); - $this->user->expects($this->at(0)) + $this->user->expects($this->exactly(2)) ->method('IsResourceAdminFor') - ->with($this->equalTo($this->resource1)) - ->will($this->returnValue(true)); - - $this->user->expects($this->at(1)) - ->method('IsResourceAdminFor') - ->with($this->equalTo($this->resource2)) - ->will($this->returnValue(true)); + ->willReturn(true); $result = $this->rule->Validate($this->reservationSeries, null); @@ -90,22 +84,18 @@ public function testIfUserIsNotAdminForAtLeastOneResource_InvokeBaseRule() $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($this->user)); - - $this->user->expects($this->at(0)) - ->method('IsResourceAdminFor') - ->with($this->equalTo($this->resource1)) - ->will($this->returnValue(true)); + ->willReturn($this->user); - $this->user->expects($this->at(1)) + $this->user->expects($this->exactly(2)) ->method('IsResourceAdminFor') - ->with($this->equalTo($this->resource2)) - ->will($this->returnValue(false)); + ->willReturnCallback(function ($resource) { + return $this->equalTo($this->resource1)->evaluate($resource, '', true); + }); $this->baseRule->expects($this->once()) ->method('Validate') ->with($this->equalTo($this->reservationSeries)) - ->will($this->returnValue($expectedResult)); + ->willReturn($expectedResult); $result = $this->rule->Validate($this->reservationSeries, null); @@ -120,20 +110,17 @@ public function testIfUserIsAdminForReservationUserReturnTrue() $adminUser = $this->createMock('User'); $reservationUser = $this->createMock('User'); - $this->userRepository->expects($this->at(0)) - ->method('LoadById') - ->with($this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($adminUser)); - - $this->userRepository->expects($this->at(1)) + $this->userRepository->expects($this->exactly(2)) ->method('LoadById') - ->with($this->equalTo($this->reservationSeries->UserId())) - ->will($this->returnValue($reservationUser)); + ->willReturnMap([ + [$this->fakeUser->UserId, $adminUser], + [$this->reservationSeries->UserId(), $reservationUser] + ]); $adminUser->expects($this->once()) ->method('IsAdminFor') ->with($this->equalTo($reservationUser)) - ->will($this->returnValue(true)); + ->willReturn(true); $result = $this->rule->Validate($this->reservationSeries, null); diff --git a/tests/Application/Reservation/BlackoutsServiceTest.php b/tests/Application/Reservation/BlackoutsServiceTest.php index 6435c4596..677b45e33 100644 --- a/tests/Application/Reservation/BlackoutsServiceTest.php +++ b/tests/Application/Reservation/BlackoutsServiceTest.php @@ -58,7 +58,7 @@ public function testCreatesBlackoutForEachResourceWhenNoConflicts() $this->reservationViewRepository->expects($this->once()) ->method('GetBlackoutsWithin') ->with($this->equalTo($date)) - ->will($this->returnValue([$blackoutBefore, $blackoutAfter, $blackoutDuring])); + ->willReturn([$blackoutBefore, $blackoutAfter, $blackoutDuring]); $reservationBefore = new TestReservationItemView(1, Date::Parse('2010-01-01'), $start, 1); $reservationAfter = new TestReservationItemView(2, $end, Date::Parse('2012-01-01'), 2); @@ -66,7 +66,7 @@ public function testCreatesBlackoutForEachResourceWhenNoConflicts() $this->reservationViewRepository->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($start), $this->equalTo($end)) - ->will($this->returnValue([$reservationBefore, $reservationAfter])); + ->willReturn([$reservationBefore, $reservationAfter]); $series = BlackoutSeries::Create($userId, $title, $date); $series->AddResourceId($resourceIds[0]); @@ -93,7 +93,7 @@ public function testDoesNotAddAnyBlackoutsIfThereAreConflictingBlackoutTimes() $this->reservationViewRepository->expects($this->atLeastOnce()) ->method('GetBlackoutsWithin') ->with($this->anything()) - ->will($this->returnValue([$blackoutDuring])); + ->willReturn([$blackoutDuring]); $result = $this->service->Add($date, $resourceIds, $title, $this->conflictHandler, new RepeatNone()); @@ -116,24 +116,18 @@ public function testConflictHandlerActsOnEachConflictingReservationAndSavesBlack $this->reservationViewRepository->expects($this->once()) ->method('GetBlackoutsWithin') ->with($this->equalTo($date)) - ->will($this->returnValue([])); + ->willReturn([]); $reservation1 = new TestReservationItemView(1, $start, $end, 2); $reservation2 = new TestReservationItemView(2, $start, $end, 2); $this->reservationViewRepository->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($start), $this->equalTo($end)) - ->will($this->returnValue([$reservation1, $reservation2])); + ->willReturn([$reservation1, $reservation2]); - $this->conflictHandler->expects($this->at(0)) + $this->conflictHandler->expects($this->exactly(2)) ->method('Handle') - ->with($this->equalTo($reservation1)) - ->will($this->returnValue(true)); - - $this->conflictHandler->expects($this->at(1)) - ->method('Handle') - ->with($this->equalTo($reservation2)) - ->will($this->returnValue(true)); + ->willReturn(true); $result = $this->service->Add($date, $resourceIds, $title, $this->conflictHandler, new RepeatNone()); @@ -155,24 +149,20 @@ public function testConflictHandlerReportsConflictingReservationAndDoesNotSaveBl $this->reservationViewRepository->expects($this->once()) ->method('GetBlackoutsWithin') ->with($this->equalTo($date)) - ->will($this->returnValue([])); + ->willReturn([]); $reservation1 = new TestReservationItemView(1, $start, $end, 2); $reservation2 = new TestReservationItemView(2, $start, $end, 2); $this->reservationViewRepository->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($start), $this->equalTo($end)) - ->will($this->returnValue([$reservation1, $reservation2])); + ->willReturn([$reservation1, $reservation2]); - $this->conflictHandler->expects($this->at(0)) + $this->conflictHandler->expects($this->exactly(2)) ->method('Handle') - ->with($this->equalTo($reservation1)) - ->will($this->returnValue(false)); - - $this->conflictHandler->expects($this->at(1)) - ->method('Handle') - ->with($this->equalTo($reservation2)) - ->will($this->returnValue(false)); + ->willReturnCallback(function ($reservation) use ($reservation2) { + return $this->equalTo($reservation2)->evaluate($reservation, '', true); + }); $result = $this->service->Add($date, $resourceIds, $title, $this->conflictHandler, new RepeatNone()); @@ -204,20 +194,17 @@ public function testChecksAndCreatesForEachRecurringDate() $series->AddBlackout(new Blackout($date)); } - for ($i = 0; $i < count($allDates); $i++) { - $date = $allDates[$i]; - $this->reservationViewRepository->expects($this->at($i)) - ->method('GetBlackoutsWithin') - ->with($this->equalTo($date)) - ->will($this->returnValue([])); - - $this->reservationViewRepository->expects($this->at($i + count($allDates))) // index is per mock, not per method - ->method('GetReservations') - ->with($this->equalTo($date->GetBegin()), $this->equalTo($date->GetEnd())) - ->will($this->returnValue([])); - } + $this->assertEquals(4, count($allDates), 'should create 4 blackouts'); - $this->assertEquals(4, $i, 'should create 4 blackouts'); + $this->reservationViewRepository + ->expects($this->exactly(count($allDates))) + ->method('GetBlackoutsWithin') + ->willReturn([]); + + $this->reservationViewRepository + ->expects($this->exactly(count($allDates))) + ->method('GetReservations') + ->willReturn([]); $result = $this->service->Add($range, $resourceIds, $title, $this->conflictHandler, $repeatDaily); $this->assertTrue($result->WasSuccessful()); @@ -282,7 +269,7 @@ public function testGetsBlackoutsThatUserCanManageIfNotAdmin() $this->userRepository->expects($this->once()) ->method('LoadGroups') ->with($this->equalTo($userId), $this->equalTo($roles)) - ->will($this->returnValue($groups)); + ->willReturn($groups); $this->reservationViewRepository->expects($this->once()) ->method('GetBlackoutList') @@ -293,7 +280,7 @@ public function testGetsBlackoutsThatUserCanManageIfNotAdmin() $this->isNull(), $this->equalTo($expectedFilter) ) - ->will($this->returnValue(new PageableData($blackouts))); + ->willReturn(new PageableData($blackouts)); $this->service->LoadFiltered($pageNumber, $pageSize, null, null, $filter, $this->fakeUser); } @@ -311,14 +298,14 @@ public function testLoadsBlackoutByInstanceId() $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue($user)); + ->willReturn($user); $this->blackoutRepository->_Series = $series; $user->expects($this->once()) ->method('IsResourceAdminFor') ->with($this->equalTo($resource)) - ->will($this->returnValue(true)); + ->willReturn(true); $actualSeries = $this->service->LoadBlackout($id, $userId); @@ -352,22 +339,22 @@ public function testUpdatesBlackoutForEachResourceWhenNoConflicts() $this->reservationViewRepository->expects($this->once()) ->method('GetBlackoutsWithin') ->with($this->equalTo($date)) - ->will($this->returnValue([$blackoutBefore, $blackoutAfter, $blackoutDuringDiffResource, $blackoutDuringSameSeries])); + ->willReturn([$blackoutBefore, $blackoutAfter, $blackoutDuringDiffResource, $blackoutDuringSameSeries]); $this->reservationViewRepository->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($start), $this->equalTo($end)) - ->will($this->returnValue([$reservationBefore, $reservationAfter])); + ->willReturn([$reservationBefore, $reservationAfter]); $user->expects($this->any()) ->method('IsResourceAdminFor') ->with($this->anything()) - ->will($this->returnValue(true)); + ->willReturn(true); $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue($user)); + ->willReturn($user); $this->blackoutRepository->_Series = $series; @@ -405,17 +392,17 @@ public function testDoesNotUpdateAnyBlackoutsIfThereAreConflictingBlackoutTimes( $this->reservationViewRepository->expects($this->atLeastOnce()) ->method('GetBlackoutsWithin') ->with($this->anything()) - ->will($this->returnValue([$blackoutDuring])); + ->willReturn([$blackoutDuring]); $user->expects($this->any()) ->method('IsResourceAdminFor') ->with($this->anything()) - ->will($this->returnValue(true)); + ->willReturn(true); $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue($user)); + ->willReturn($user); $this->blackoutRepository->_Series = $series; @@ -452,34 +439,28 @@ public function testConflictHandlerActsOnEachConflictingReservationAndUpdatesBla $user->expects($this->any()) ->method('IsResourceAdminFor') ->with($this->anything()) - ->will($this->returnValue(true)); + ->willReturn(true); $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue($user)); + ->willReturn($user); $this->reservationViewRepository->expects($this->once()) ->method('GetBlackoutsWithin') ->with($this->equalTo($date)) - ->will($this->returnValue([])); + ->willReturn([]); $reservation1 = new TestReservationItemView(1, $start, $end, 2); $reservation2 = new TestReservationItemView(2, $start, $end, 2); $this->reservationViewRepository->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($start), $this->equalTo($end)) - ->will($this->returnValue([$reservation1, $reservation2])); - - $this->conflictHandler->expects($this->at(0)) - ->method('Handle') - ->with($this->equalTo($reservation1)) - ->will($this->returnValue(true)); + ->willReturn([$reservation1, $reservation2]); - $this->conflictHandler->expects($this->at(1)) + $this->conflictHandler->expects($this->exactly(2)) ->method('Handle') - ->with($this->equalTo($reservation2)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->blackoutRepository->_Series = $series; @@ -517,34 +498,28 @@ public function testConflictHandlerReportsConflictingReservationAndDoesNotUpdate $user->expects($this->any()) ->method('IsResourceAdminFor') ->with($this->anything()) - ->will($this->returnValue(true)); + ->willReturn(true); $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue($user)); + ->willReturn($user); $this->reservationViewRepository->expects($this->once()) ->method('GetBlackoutsWithin') ->with($this->equalTo($date)) - ->will($this->returnValue([])); + ->willReturn([]); $reservation1 = new TestReservationItemView(1, $start, $end, 2); $reservation2 = new TestReservationItemView(2, $start, $end, 2); $this->reservationViewRepository->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($start), $this->equalTo($end)) - ->will($this->returnValue([$reservation1, $reservation2])); - - $this->conflictHandler->expects($this->at(0)) - ->method('Handle') - ->with($this->equalTo($reservation1)) - ->will($this->returnValue(false)); + ->willReturn([$reservation1, $reservation2]); - $this->conflictHandler->expects($this->at(1)) + $this->conflictHandler->expects($this->exactly(2)) ->method('Handle') - ->with($this->equalTo($reservation2)) - ->will($this->returnValue(false)); + ->willReturn(false); $this->blackoutRepository->_Series = $series; diff --git a/tests/Application/Reservation/CustomAttributeValidationRuleTest.php b/tests/Application/Reservation/CustomAttributeValidationRuleTest.php index 6158e1087..b116e571f 100644 --- a/tests/Application/Reservation/CustomAttributeValidationRuleTest.php +++ b/tests/Application/Reservation/CustomAttributeValidationRuleTest.php @@ -52,17 +52,14 @@ public function setUp(): void $this->bookedBy->_IsResourceAdmin = false; $this->bookedBy->_SetIsAdminForUser(false); - $this->userRepository->expects($this->at(0)) + $this->userRepository->expects($this->exactly(2)) ->method('LoadById') - ->with($this->equalTo($this->reservation->UserId())) - ->will($this->returnValue($this->user)); + ->willReturnMap([ + [$this->reservation->UserId(), $this->user], + [$this->reservation->BookedBy()->UserId, $this->bookedBy] + ]); - $this->userRepository->expects($this->at(1)) - ->method('LoadById') - ->with($this->equalTo($this->reservation->BookedBy()->UserId)) - ->will($this->returnValue($this->bookedBy)); - - $this->rule = $rule = new CustomAttributeValidationRule($this->attributeService, $this->userRepository); + $this->rule = new CustomAttributeValidationRule($this->attributeService, $this->userRepository); } public function teardown(): void @@ -81,7 +78,7 @@ public function testChecksEachAttributeInCategory() $this->attributeService->expects($this->once()) ->method('Validate') ->with($this->equalTo(CustomAttributeCategory::RESERVATION), $this->equalTo($this->reservation->AttributeValues()), $this->equalTo([]), $this->isFalse(), $this->isFalse()) - ->will($this->returnValue($validationResult)); + ->willReturn($validationResult); $userAttribute = new FakeCustomAttribute(); $userAttribute->WithSecondaryEntities(CustomAttributeCategory::USER, 123); @@ -101,7 +98,7 @@ public function testWhenAllAttributesAreValid() $this->attributeService->expects($this->once()) ->method('Validate') ->with($this->equalTo(CustomAttributeCategory::RESERVATION), $this->equalTo($this->reservation->AttributeValues()), $this->equalTo([]), $this->isFalse(), $this->isFalse()) - ->will($this->returnValue($validationResult)); + ->willReturn($validationResult); $result = $this->rule->Validate($this->reservation, null); @@ -116,7 +113,7 @@ public function testWhenUserIsAnAdmin_ThenEvaluateAdminOnlyAttributes() $this->attributeService->expects($this->once()) ->method('Validate') ->with($this->equalTo(CustomAttributeCategory::RESERVATION), $this->equalTo($this->reservation->AttributeValues()), $this->equalTo([]), $this->isFalse(), $this->isTrue()) - ->will($this->returnValue($validationResult)); + ->willReturn($validationResult); $result = $this->rule->Validate($this->reservation, null); @@ -137,7 +134,7 @@ public function testWhenTheInvalidAttributeIsForASecondaryUser_AndTheReservation $attributeService->expects($this->once()) ->method('Validate') ->with($this->equalTo(CustomAttributeCategory::RESERVATION), $this->equalTo($this->reservation->AttributeValues())) - ->will($this->returnValue($validationResult)); + ->willReturn($validationResult); $rule = new CustomAttributeValidationRule($attributeService, $this->userRepository); @@ -162,7 +159,7 @@ public function testWhenTheInvalidAttributeIsForASecondaryResource_AndTheReserva $attributeService->expects($this->once()) ->method('Validate') ->with($this->equalTo(CustomAttributeCategory::RESERVATION), $this->equalTo($this->reservation->AttributeValues())) - ->will($this->returnValue($validationResult)); + ->willReturn($validationResult); $rule = new CustomAttributeValidationRule($attributeService, $this->userRepository); @@ -189,7 +186,7 @@ public function testWhenTheInvalidAttributeIsForASecondaryResourceType_AndTheRes $attributeService->expects($this->once()) ->method('Validate') ->with($this->equalTo(CustomAttributeCategory::RESERVATION), $this->equalTo($this->reservation->AttributeValues())) - ->will($this->returnValue($validationResult)); + ->willReturn($validationResult); $rule = new CustomAttributeValidationRule($attributeService, $this->userRepository); diff --git a/tests/Application/Reservation/ExistingResourceAvailabilityRuleTest.php b/tests/Application/Reservation/ExistingResourceAvailabilityRuleTest.php index 6edf07d24..e8e77db65 100644 --- a/tests/Application/Reservation/ExistingResourceAvailabilityRuleTest.php +++ b/tests/Application/Reservation/ExistingResourceAvailabilityRuleTest.php @@ -57,7 +57,7 @@ public function testDoesNotConflictIfBeingDeletedOrUpdated() $this->strategy->expects($this->exactly(2)) ->method('GetItemsBetween') ->with($this->anything(), $this->anything()) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $rule = new ExistingResourceAvailabilityRule(new ReservationConflictIdentifier($this->strategy), $this->timezone); $ruleResult = $rule->Validate($series, null); @@ -84,7 +84,7 @@ public function testDoesNotConflictIfCurrentInstanceBeingUpdated() $this->strategy->expects($this->once()) ->method('GetItemsBetween') ->with($this->anything(), $this->anything()) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $rule = new ExistingResourceAvailabilityRule(new ReservationConflictIdentifier($this->strategy), $this->timezone); $ruleResult = $rule->Validate($series, null); @@ -112,7 +112,7 @@ public function testConflictsIfResourceReservationExistsAtSameTime() $this->strategy->expects($this->once()) ->method('GetItemsBetween') ->with($this->anything(), $this->anything()) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $rule = new ExistingResourceAvailabilityRule(new ReservationConflictIdentifier($this->strategy), $this->timezone); $ruleResult = $rule->Validate($series, null); @@ -142,7 +142,7 @@ public function testNoConflictsIfReservationExistsAtSameTimeForDifferentResource $this->strategy->expects($this->once()) ->method('GetItemsBetween') ->with($this->anything(), $this->anything()) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $rule = new ExistingResourceAvailabilityRule(new ReservationConflictIdentifier($this->strategy), $this->timezone); $ruleResult = $rule->Validate($series, null); @@ -210,7 +210,7 @@ public function testRuleIsValidIfNoConflictsForTheReservationResourcesWithBuffer $strategy->expects($this->once()) ->method('GetItemsBetween') ->with($this->equalTo($startDate->AddMinutes(-60)), $this->equalTo($endDate->AddMinutes(60))) - ->will($this->returnValue([$scheduleReservation1, $scheduleReservation2, $scheduleReservation3, $scheduleReservation4, $scheduleReservation5])); + ->willReturn([$scheduleReservation1, $scheduleReservation2, $scheduleReservation3, $scheduleReservation4, $scheduleReservation5]); $rule = new ExistingResourceAvailabilityRule(new ReservationConflictIdentifier($strategy), "UTC"); $result = $rule->Validate($reservation, null); @@ -253,7 +253,7 @@ public function testGetsConflictingReservationTimesForSingleDateSingleResourceWi $strategy->expects($this->once()) ->method('GetItemsBetween') ->with($this->equalTo($startDate->AddMinutes(-60)), $this->equalTo($endDate->AddMinutes(60))) - ->will($this->returnValue([$conflict1, $conflict2, $nonConflict1, $nonConflict2, $nonConflict3])); + ->willReturn([$conflict1, $conflict2, $nonConflict1, $nonConflict2, $nonConflict3]); $rule = new ExistingResourceAvailabilityRule(new ReservationConflictIdentifier($strategy), "UTC"); @@ -287,7 +287,7 @@ public function testNoConflictIfOverlappingCountIsLessThanWhatResourcesAllow() $this->strategy->expects($this->once()) ->method('GetItemsBetween') ->with($this->anything(), $this->anything()) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $rule = new ExistingResourceAvailabilityRule(new ReservationConflictIdentifier($this->strategy), $this->timezone); $ruleResult = $rule->Validate($series, null); @@ -351,15 +351,9 @@ public function testConflictIfOverlappingCountIsMoreThanWhatResourcesAllowOnSing new TestReservationItemView(++$currentId, $instance->StartDate(), $instance->EndDate(), $resourceId, "r$currentId"), ]; - $this->strategy->expects($this->at(0)) - ->method('GetItemsBetween') - ->with($this->anything(), $this->anything()) - ->will($this->returnValue($reservationsInstance1)); - - $this->strategy->expects($this->at(1)) + $this->strategy->expects($this->exactly(2)) ->method('GetItemsBetween') - ->with($this->anything(), $this->anything()) - ->will($this->returnValue($reservationsInstance2)); + ->willReturn($reservationsInstance1, $reservationsInstance2); $rule = new ExistingResourceAvailabilityRule(new ReservationConflictIdentifier($this->strategy), $this->timezone); $ruleResult = $rule->Validate($series, null); diff --git a/tests/Application/Reservation/GuestEmailNotificationTest.php b/tests/Application/Reservation/GuestEmailNotificationTest.php index 0e63570f8..1e99133fd 100644 --- a/tests/Application/Reservation/GuestEmailNotificationTest.php +++ b/tests/Application/Reservation/GuestEmailNotificationTest.php @@ -34,10 +34,10 @@ public function testSendsReservationCreatedEmailIfThereAreNewParticipants() $userRepo = $this->createMock('IUserRepository'); $attributeRepo = $this->createMock('IAttributeRepository'); - $userRepo->expects($this->at(0)) + $userRepo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($owner)); + ->willReturn($owner); $notification = new GuestAddedEmailNotification($userRepo, $attributeRepo); $notification->Notify($series); @@ -71,10 +71,10 @@ public function testSendsReservationDeletedEmails() $userRepo = $this->createMock('IUserRepository'); $attributeRepo = $this->createMock('IAttributeRepository'); - $userRepo->expects($this->at(0)) + $userRepo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($owner)); + ->willReturn($owner); $notification = new GuestDeletedEmailNotification($userRepo, $attributeRepo); $notification->Notify($series); @@ -107,10 +107,10 @@ public function testSendsReservationUpdatedEmailToExistingParticipants() $userRepo = $this->createMock('IUserRepository'); $attributeRepo = $this->createMock('IAttributeRepository'); - $userRepo->expects($this->at(0)) + $userRepo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($owner)); + ->willReturn($owner); $notification = new GuestUpdatedEmailNotification($userRepo, $attributeRepo); $notification->Notify($series); diff --git a/tests/Application/Reservation/InvitationEmailNotificationTest.php b/tests/Application/Reservation/InvitationEmailNotificationTest.php index 77dcfbafc..4eb10bd4a 100644 --- a/tests/Application/Reservation/InvitationEmailNotificationTest.php +++ b/tests/Application/Reservation/InvitationEmailNotificationTest.php @@ -34,20 +34,13 @@ public function testSendsInvitationEmailToNewInvitees() $userRepo = $this->createMock('IUserRepository'); $attributeRepo = $this->createMock('IAttributeRepository'); - $userRepo->expects($this->at(0)) + $userRepo->expects($this->exactly(3)) ->method('LoadById') - ->with($this->equalTo($ownerId)) - ->will($this->returnValue($owner)); - - $userRepo->expects($this->at(1)) - ->method('LoadById') - ->with($this->equalTo($inviteeId1)) - ->will($this->returnValue($invitee1)); - - $userRepo->expects($this->at(2)) - ->method('LoadById') - ->with($this->equalTo($inviteeId2)) - ->will($this->returnValue($invitee2)); + ->willReturnMap([ + [$ownerId, $owner], + [$inviteeId1, $invitee1], + [$inviteeId2, $invitee2] + ]); $notification = new InviteeAddedEmailNotification($userRepo, $attributeRepo); $notification->Notify($series); diff --git a/tests/Application/Reservation/OwnerEmailNotificationTest.php b/tests/Application/Reservation/OwnerEmailNotificationTest.php index 60b1c1b2d..73e4fa046 100644 --- a/tests/Application/Reservation/OwnerEmailNotificationTest.php +++ b/tests/Application/Reservation/OwnerEmailNotificationTest.php @@ -104,7 +104,7 @@ public function testSendsReservationDeletedEmailIfUserWantsIt() // $user->expects($this->once()) // ->method('WantsEventEmail') // ->with($this->equalTo($event)) - // ->will($this->returnValue(true)); + // ->willReturn(true); // } public function LoadsUser($userRepo, $ownerId) @@ -115,7 +115,7 @@ public function LoadsUser($userRepo, $ownerId) $userRepo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($ownerId)) - ->will($this->returnValue($user)); + ->willReturn($user); return $user; } diff --git a/tests/Application/Reservation/ParticipantEmailNotificationTest.php b/tests/Application/Reservation/ParticipantEmailNotificationTest.php index a02c9f9c7..90dcefb20 100644 --- a/tests/Application/Reservation/ParticipantEmailNotificationTest.php +++ b/tests/Application/Reservation/ParticipantEmailNotificationTest.php @@ -34,20 +34,13 @@ public function testSendsReservationCreatedEmailIfThereAreNewParticipants() $userRepo = $this->createMock('IUserRepository'); $attributeRepo = $this->createMock('IAttributeRepository'); - $userRepo->expects($this->at(0)) + $userRepo->expects($this->exactly(3)) ->method('LoadById') - ->with($this->equalTo($ownerId)) - ->will($this->returnValue($owner)); - - $userRepo->expects($this->at(1)) - ->method('LoadById') - ->with($this->equalTo($participantId1)) - ->will($this->returnValue($participant1)); - - $userRepo->expects($this->at(2)) - ->method('LoadById') - ->with($this->equalTo($participantId2)) - ->will($this->returnValue($participant2)); + ->willReturnMap([ + [$ownerId, $owner], + [$participantId1, $participant1], + [$participantId2, $participant2] + ]); $notification = new ParticipantAddedEmailNotification($userRepo, $attributeRepo); $notification->Notify($series); @@ -78,20 +71,13 @@ public function testSendsReservationDeletedEmails() $userRepo = $this->createMock('IUserRepository'); $attributeRepo = $this->createMock('IAttributeRepository'); - $userRepo->expects($this->at(0)) - ->method('LoadById') - ->with($this->equalTo($ownerId)) - ->will($this->returnValue($owner)); - - $userRepo->expects($this->at(1)) - ->method('LoadById') - ->with($this->equalTo($participantId1)) - ->will($this->returnValue($participant1)); - - $userRepo->expects($this->at(2)) + $userRepo->expects($this->exactly(3)) ->method('LoadById') - ->with($this->equalTo($participantId2)) - ->will($this->returnValue($participant2)); + ->willReturnMap([ + [$ownerId, $owner], + [$participantId1, $participant1], + [$participantId2, $participant2] + ]); $notification = new ParticipantDeletedEmailNotification($userRepo, $attributeRepo); $notification->Notify($series); diff --git a/tests/Application/Reservation/PermissionValidationRuleTest.php b/tests/Application/Reservation/PermissionValidationRuleTest.php index 0144f6fe7..a851a3949 100644 --- a/tests/Application/Reservation/PermissionValidationRuleTest.php +++ b/tests/Application/Reservation/PermissionValidationRuleTest.php @@ -46,7 +46,7 @@ public function testChecksIfUserHasPermission() $factory->expects($this->once()) ->method('GetPermissionService') - ->will($this->returnValue($service)); + ->willReturn($service); $rule = new PermissionValidationRule($factory); $result = $rule->Validate($reservation, null); diff --git a/tests/Application/Reservation/QuotaRuleTest.php b/tests/Application/Reservation/QuotaRuleTest.php index eb9bc7a8a..286993ead 100644 --- a/tests/Application/Reservation/QuotaRuleTest.php +++ b/tests/Application/Reservation/QuotaRuleTest.php @@ -80,17 +80,17 @@ public function testWhenQuotaThatAppliesToReservationResourceAndUserGroupIsNotEx $this->quotaRepository->expects($this->once()) ->method('LoadAll') - ->will($this->returnValue($quotas)); + ->willReturn($quotas); $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue($user)); + ->willReturn($user); $this->scheduleRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($scheduleId)) - ->will($this->returnValue($schedule)); + ->willReturn($schedule); $this->ChecksAgainstQuota($quota1, $series, $this->reservationViewRepository, $schedule, $user); $this->ChecksAgainstQuota($quota2, $series, $this->reservationViewRepository, $schedule, $user); @@ -141,17 +141,17 @@ public function testFirstQuotaExceeded() $this->quotaRepository->expects($this->once()) ->method('LoadAll') - ->will($this->returnValue($quotas)); + ->willReturn($quotas); $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue($user)); + ->willReturn($user); $this->scheduleRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($scheduleId)) - ->will($this->returnValue($schedule)); + ->willReturn($schedule); $this->ChecksAgainstQuota($quota1, $series, $this->reservationViewRepository, $schedule, $user, true); @@ -175,7 +175,7 @@ private function ChecksAgainstQuota($quota, $series, $repo, $schedule, $user, $e $quota->expects($this->once()) ->method('ExceedsQuota') ->with($this->equalTo($series), $this->equalTo($user), $this->equalTo($schedule), $this->equalTo($repo)) - ->will($this->returnValue($exceeds)); + ->willReturn($exceeds); } private function mockQuota() @@ -183,7 +183,7 @@ private function mockQuota() $mock = $this->createMock('IQuota'); $mock->expects($this->any()) ->method('ToString') - ->will($this->returnValue('')); + ->willReturn(''); return $mock; } diff --git a/tests/Application/Reservation/RequiresApprovalRuleTest.php b/tests/Application/Reservation/RequiresApprovalRuleTest.php index dcacd0442..3aa1dc1b8 100644 --- a/tests/Application/Reservation/RequiresApprovalRuleTest.php +++ b/tests/Application/Reservation/RequiresApprovalRuleTest.php @@ -37,7 +37,7 @@ public function testMarksReservationAsRequiringApprovalIfUserIsNotApprover() $this->authorizationService->expects($this->once()) ->method('CanApproveForResource') ->with($this->equalTo($this->fakeUser), $this->equalTo($resource)) - ->will($this->returnValue(false)); + ->willReturn(false); $this->rule->Validate($series, null); @@ -68,7 +68,7 @@ public function testDoesNotMarkAsRequiringApprovalIfUserCanApproveForResource() $this->authorizationService->expects($this->once()) ->method('CanApproveForResource') ->with($this->equalTo($this->fakeUser), $this->equalTo($resource)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->rule->Validate($series, null); diff --git a/tests/Application/Reservation/ReservationCanBeCheckedInRuleTest.php b/tests/Application/Reservation/ReservationCanBeCheckedInRuleTest.php index 3357e160b..e415e0850 100644 --- a/tests/Application/Reservation/ReservationCanBeCheckedInRuleTest.php +++ b/tests/Application/Reservation/ReservationCanBeCheckedInRuleTest.php @@ -2,9 +2,16 @@ class ReservationCanBeCheckedInRuleTest extends TestBase { + /** + * + * @var UserSession + */ + private $userSession; + public function setUp(): void { parent::setup(); + $this->userSession = new UserSession(123); } public function testCanBeCheckedInIfWithinWindowWithAutoRelease() @@ -24,7 +31,7 @@ public function testCanBeCheckedInIfWithinWindowWithAutoRelease() $series->WithCurrentInstance($reservation); $series->AddResource($resource2); - $rule = new ReservationCanBeCheckedInRule(); + $rule = new ReservationCanBeCheckedInRule($this->userSession); $result = $rule->Validate($series, null); $this->assertTrue($result->IsValid()); } @@ -42,7 +49,7 @@ public function testCanBeCheckedInIfWithinWindowWithoutAutoRelease() $series->WithPrimaryResource($resource1); $series->WithCurrentInstance($reservation); - $rule = new ReservationCanBeCheckedInRule(); + $rule = new ReservationCanBeCheckedInRule($this->userSession); $result = $rule->Validate($series, null); $this->assertTrue($result->IsValid()); } @@ -60,7 +67,7 @@ public function testCannotBeCheckedInIfPastEnd() $series->WithPrimaryResource($resource1); $series->WithCurrentInstance($reservation); - $rule = new ReservationCanBeCheckedInRule(); + $rule = new ReservationCanBeCheckedInRule($this->userSession); $result = $rule->Validate($series, null); $this->assertFalse($result->IsValid()); } @@ -74,7 +81,7 @@ public function testCannotBeCheckedInIfNoResourceHasCheckinEnabled() $series->WithPrimaryResource($resource1); $series->WithCurrentInstance(new TestReservation()); - $rule = new ReservationCanBeCheckedInRule(); + $rule = new ReservationCanBeCheckedInRule($this->userSession); $result = $rule->Validate($series, null); $this->assertFalse($result->IsValid()); } @@ -96,7 +103,7 @@ public function testCannotBeCheckedInIfPastReleaseTime() $series->WithCurrentInstance($reservation); $series->AddResource($resource2); - $rule = new ReservationCanBeCheckedInRule(); + $rule = new ReservationCanBeCheckedInRule($this->userSession); $result = $rule->Validate($series, null); $this->assertFalse($result->IsValid()); } @@ -112,7 +119,7 @@ public function testCannotBeCheckedInIfMoreThanFiveMinutesUntilStart() $series->WithPrimaryResource($resource1); $series->WithCurrentInstance($reservation); - $rule = new ReservationCanBeCheckedInRule(); + $rule = new ReservationCanBeCheckedInRule($this->userSession); $result = $rule->Validate($series, null); $this->assertFalse($result->IsValid()); } diff --git a/tests/Application/Reservation/ReservationCanBeCheckedOutRuleTest.php b/tests/Application/Reservation/ReservationCanBeCheckedOutRuleTest.php index 1e204e5b6..ff5bc9322 100644 --- a/tests/Application/Reservation/ReservationCanBeCheckedOutRuleTest.php +++ b/tests/Application/Reservation/ReservationCanBeCheckedOutRuleTest.php @@ -2,9 +2,16 @@ class ReservationCanBeCheckedOutRuleTest extends TestBase { + /** + * + * @var UserSession + */ + private $userSession; + public function setUp(): void { parent::setup(); + $this->userSession = new UserSession(123); } public function testCanBeCheckedOutIfCheckedInAndPastStartDate() @@ -24,7 +31,7 @@ public function testCanBeCheckedOutIfCheckedInAndPastStartDate() $series->AddResource($resource2); $series->Checkin($this->fakeUser); - $rule = new ReservationCanBeCheckedOutRule(); + $rule = new ReservationCanBeCheckedOutRule($this->userSession); $result = $rule->Validate($series, null); $this->assertTrue($result->IsValid()); } @@ -42,7 +49,7 @@ public function testCannotBeCheckedOutIfNotCheckedIn() $series->WithPrimaryResource($resource1); $series->WithCurrentInstance($reservation); - $rule = new ReservationCanBeCheckedOutRule(); + $rule = new ReservationCanBeCheckedOutRule($this->userSession); $result = $rule->Validate($series, null); $this->assertFalse($result->IsValid()); } @@ -59,7 +66,7 @@ public function testCannotBeCheckedOutIfNotStarted() $series->WithCurrentInstance($reservation); $series->Checkin($this->fakeUser); - $rule = new ReservationCanBeCheckedOutRule(); + $rule = new ReservationCanBeCheckedOutRule($this->userSession); $result = $rule->Validate($series, null); $this->assertFalse($result->IsValid()); } @@ -76,7 +83,7 @@ public function testCannotBeCheckedOutCheckoutNotEnabled() $series->WithCurrentInstance($reservation); $series->Checkin($this->fakeUser); - $rule = new ReservationCanBeCheckedOutRule(); + $rule = new ReservationCanBeCheckedOutRule($this->userSession); $result = $rule->Validate($series, null); $this->assertFalse($result->IsValid()); } diff --git a/tests/Application/Reservation/ReservationComponentTest.php b/tests/Application/Reservation/ReservationComponentTest.php index c0e7b668d..8ecec06d3 100644 --- a/tests/Application/Reservation/ReservationComponentTest.php +++ b/tests/Application/Reservation/ReservationComponentTest.php @@ -93,21 +93,21 @@ public function testBindsUserData() $this->initializer->expects($this->once()) ->method('GetOwnerId') - ->will($this->returnValue($this->userId)); + ->willReturn($this->userId); $this->initializer->expects($this->atLeastOnce()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->userRepository->expects($this->once()) ->method('GetById') ->with($this->equalTo($this->userId)) - ->will($this->returnValue($userDto)); + ->willReturn($userDto); $this->reservationAuthorization->expects($this->once()) ->method('CanChangeUsers') ->with($this->fakeUser) - ->will($this->returnValue(true)); + ->willReturn(true); $this->fakeConfig->SetSectionKey(ConfigSection::PRIVACY, ConfigKeys::PRIVACY_HIDE_USER_DETAILS, 'true'); $this->initializer->expects($this->once()) @@ -134,15 +134,15 @@ public function testBindsResourceData() $this->initializer->expects($this->atLeastOnce()) ->method('GetScheduleId') - ->will($this->returnValue($requestedScheduleId)); + ->willReturn($requestedScheduleId); $this->initializer->expects($this->atLeastOnce()) ->method('GetResourceId') - ->will($this->returnValue($requestedResourceId)); + ->willReturn($requestedResourceId); $this->initializer->expects($this->atLeastOnce()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $bookedResource = new TestResourceDto( @@ -204,13 +204,13 @@ public function testBindsResourceData() $this->resourceService->expects($this->once()) ->method('GetResourceGroups') ->with($this->equalTo($requestedScheduleId), $this->equalTo($this->fakeUser)) - ->will($this->returnValue($groups)); + ->willReturn($groups); // accessories $accessoryList = [new Accessory(1, 'a1', 30), new Accessory(2, 'a2', 20)]; $this->resourceService->expects($this->once()) ->method('GetAccessories') - ->will($this->returnValue($accessoryList)); + ->willReturn($accessoryList); $this->initializer->expects($this->once()) ->method('BindResourceGroups') @@ -243,15 +243,15 @@ public function testRedirectsIfUserHasPermissionToZeroResources() $this->initializer->expects($this->once()) ->method('GetScheduleId') - ->will($this->returnValue($requestedScheduleId)); + ->willReturn($requestedScheduleId); $this->initializer->expects($this->once()) ->method('GetResourceId') - ->will($this->returnValue($requestedResourceId)); + ->willReturn($requestedResourceId); $this->initializer->expects($this->once()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $resourceList = []; $groups = new FakeResourceGroupTree(); @@ -260,7 +260,7 @@ public function testRedirectsIfUserHasPermissionToZeroResources() $this->resourceService->expects($this->once()) ->method('GetResourceGroups') ->with($this->equalTo($requestedScheduleId), $this->equalTo($this->fakeUser)) - ->will($this->returnValue($groups)); + ->willReturn($groups); $this->initializer->expects($this->once()) ->method('RedirectToError') @@ -291,31 +291,31 @@ public function testBindsDates() $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->initializer->expects($this->any()) ->method('GetTimezone') - ->will($this->returnValue($timezone)); + ->willReturn($timezone); $this->initializer->expects($this->any()) ->method('GetReservationDate') - ->will($this->returnValue($dateInUserTimezone)); + ->willReturn($dateInUserTimezone); $this->initializer->expects($this->any()) ->method('GetStartDate') - ->will($this->returnValue($startDate)); + ->willReturn($startDate); $this->initializer->expects($this->any()) ->method('GetEndDate') - ->will($this->returnValue($endDate)); + ->willReturn($endDate); $this->initializer->expects($this->any()) ->method('GetScheduleId') - ->will($this->returnValue($scheduleId)); + ->willReturn($scheduleId); $this->initializer->expects($this->any()) ->method('PrimaryResource') - ->will($this->returnValue($resourceDto)); + ->willReturn($resourceDto); $startPeriods = [new SchedulePeriod(Date::Now(), Date::Now())]; $endPeriods = [new SchedulePeriod(Date::Now()->AddDays(1), Date::Now()->AddDays(1))]; @@ -324,15 +324,16 @@ public function testBindsDates() $this->scheduleRepository->_Layout = $layout; $this->scheduleRepository->_Schedule = $schedule; - $layout->expects($this->at(0)) + $layout->expects($this->exactly(2)) ->method('GetLayout') - ->with($this->equalTo($startDate), $this->equalTo(true)) - ->will($this->returnValue($startPeriods)); - - $layout->expects($this->at(1)) - ->method('GetLayout') - ->with($this->equalTo($endDate), $this->equalTo(true)) - ->will($this->returnValue($endPeriods)); + ->willReturnCallback(function(Date $date, $hideBlockedPeriods) use ($startDate, $endDate, $startPeriods, $endPeriods) + { + if ($date->Equals($startDate) && $hideBlockedPeriods) + return $startPeriods; + if ($date->Equals($endDate) && $hideBlockedPeriods) + return $endPeriods; + throw new Exception("Unexpected arguments"); + }); $this->initializer->expects($this->once()) ->method('SetDates') @@ -372,31 +373,31 @@ public function testBindsDatesWhenResourceHasMinimumTime() $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->initializer->expects($this->any()) ->method('GetTimezone') - ->will($this->returnValue($timezone)); + ->willReturn($timezone); $this->initializer->expects($this->any()) ->method('GetReservationDate') - ->will($this->returnValue($dateInUserTimezone)); + ->willReturn($dateInUserTimezone); $this->initializer->expects($this->any()) ->method('GetStartDate') - ->will($this->returnValue($startDate)); + ->willReturn($startDate); $this->initializer->expects($this->any()) ->method('GetEndDate') - ->will($this->returnValue($endDate)); + ->willReturn($endDate); $this->initializer->expects($this->any()) ->method('GetScheduleId') - ->will($this->returnValue($scheduleId)); + ->willReturn($scheduleId); $this->initializer->expects($this->any()) ->method('PrimaryResource') - ->will($this->returnValue($resourceDto)); + ->willReturn($resourceDto); $startPeriods = [new SchedulePeriod(Date::Now(), Date::Now())]; $endPeriods = [new SchedulePeriod(Date::Now()->AddDays(1), Date::Now()->AddDays(1))]; @@ -405,15 +406,16 @@ public function testBindsDatesWhenResourceHasMinimumTime() $this->scheduleRepository->_Layout = $layout; $this->scheduleRepository->_Schedule = new FakeSchedule(); - $layout->expects($this->at(0)) - ->method('GetLayout') - ->with($this->equalTo($startDate)) - ->will($this->returnValue($startPeriods)); - - $layout->expects($this->at(1)) + $layout->expects($this->exactly(2)) ->method('GetLayout') - ->with($this->equalTo($endDate)) - ->will($this->returnValue($endPeriods)); + ->willReturnCallback(function(Date $date) use ($startDate, $endDate, $startPeriods, $endPeriods) + { + if($date->Equals($startDate)) + return $startPeriods; + if($date->Equals($endDate)) + return $endPeriods; + throw new Exception("Unexpeced argument"); + }); $this->initializer->expects($this->once()) ->method('SetDates') @@ -430,7 +432,7 @@ public function testBindsDatesWhenResourceHasMinimumTime() $this->initializer->expects($this->once()) ->method('IsNew') - ->will($this->returnValue(true)); + ->willReturn(true); $binder = new ReservationDateBinder($this->scheduleRepository); $binder->Bind($this->initializer); @@ -447,27 +449,27 @@ public function testMovesFirstPeriodToEndIfTimeIsLaterInTheDay() $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->initializer->expects($this->any()) ->method('GetTimezone') - ->will($this->returnValue($timezone)); + ->willReturn($timezone); $this->initializer->expects($this->any()) ->method('GetReservationDate') - ->will($this->returnValue($dateInUserTimezone)); + ->willReturn($dateInUserTimezone); $this->initializer->expects($this->any()) ->method('GetStartDate') - ->will($this->returnValue($requestedDate)); + ->willReturn($requestedDate); $this->initializer->expects($this->any()) ->method('GetEndDate') - ->will($this->returnValue($requestedDate)); + ->willReturn($requestedDate); $this->initializer->expects($this->any()) ->method('GetScheduleId') - ->will($this->returnValue($scheduleId)); + ->willReturn($scheduleId); $periods = [ new SchedulePeriod( @@ -489,7 +491,7 @@ public function testMovesFirstPeriodToEndIfTimeIsLaterInTheDay() $layout->expects($this->any()) ->method('GetLayout') ->with($this->equalTo($requestedDate)) - ->will($this->returnValue($periods)); + ->willReturn($periods); $this->initializer->expects($this->once()) ->method('SetDates') @@ -645,7 +647,7 @@ public function testBindsReservationDetails() $this->reservationAuthorization->expects($this->once()) ->method('CanEdit') ->with($this->equalTo($this->reservationView), $this->equalTo($this->fakeUser)) - ->will($this->returnValue($isEditable)); + ->willReturn($isEditable); $this->page->expects($this->once()) ->method('SetIsEditable') @@ -655,7 +657,7 @@ public function testBindsReservationDetails() $this->reservationAuthorization->expects($this->once()) ->method('CanApprove') ->with($this->equalTo($this->reservationView), $this->equalTo($this->fakeUser)) - ->will($this->returnValue($isApprovable)); + ->willReturn($isApprovable); $this->page->expects($this->once()) ->method('SetIsApprovable') @@ -680,23 +682,23 @@ public function testBindsReservationDetails() $this->initializer->expects($this->atLeastOnce()) ->method('GetTimezone') - ->will($this->returnValue($timezone)); + ->willReturn($timezone); $this->initializer->expects($this->atLeastOnce()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $canViewDetails = true; $canViewUser = true; $this->privacyFilter->expects($this->once()) ->method('CanViewDetails') ->with($this->equalTo($this->fakeUser), $this->equalTo($this->reservationView)) - ->will($this->returnValue($canViewDetails)); + ->willReturn($canViewDetails); $this->privacyFilter->expects($this->once()) ->method('CanViewUser') ->with($this->equalTo($this->fakeUser), $this->equalTo($this->reservationView)) - ->will($this->returnValue($canViewUser)); + ->willReturn($canViewUser); $this->initializer->expects($this->once()) ->method('ShowUserDetails') @@ -725,11 +727,11 @@ public function testCheckInIsRequiredIfAtLeastOneResourceRequiresIt_And_Reservat $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->reservationAuthorization->expects($this->once()) ->method('CanEdit') - ->will($this->returnValue(true)); + ->willReturn(true); $this->reservationDetailsBinder = new ReservationDetailsBinder( $this->reservationAuthorization, @@ -758,7 +760,7 @@ public function testCheckInNotRequiredIfCheckedIn() $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->reservationDetailsBinder = new ReservationDetailsBinder( $this->reservationAuthorization, @@ -785,7 +787,7 @@ public function testCheckInIsNotRequiredIfNoResourceRequiresIt() $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->reservationDetailsBinder = new ReservationDetailsBinder( $this->reservationAuthorization, @@ -812,7 +814,7 @@ public function testCheckInIsNotRequiredIfTooEarly() $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->reservationDetailsBinder = new ReservationDetailsBinder( $this->reservationAuthorization, @@ -841,11 +843,11 @@ public function testCheckOutRequiredIfAtLeastOneResourceRequiresIt_AndTheReserva $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->reservationAuthorization->expects($this->once()) ->method('CanEdit') - ->will($this->returnValue(true)); + ->willReturn(true); $this->reservationDetailsBinder = new ReservationDetailsBinder( $this->reservationAuthorization, @@ -872,7 +874,7 @@ public function testCheckOutIsNotRequiredIfNoResourceRequiresIt() $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->reservationDetailsBinder = new ReservationDetailsBinder( $this->reservationAuthorization, @@ -899,7 +901,7 @@ public function testCheckOutIsNotRequiredIfAlreadyCheckedOut() $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->reservationDetailsBinder = new ReservationDetailsBinder( $this->reservationAuthorization, @@ -927,7 +929,7 @@ public function testCheckOutIsNotRequiredIfNotCheckedIn() $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->reservationDetailsBinder = new ReservationDetailsBinder( $this->reservationAuthorization, @@ -954,7 +956,7 @@ public function testCheckOutIsNotRequiredIfNotStarted() $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->reservationDetailsBinder = new ReservationDetailsBinder( $this->reservationAuthorization, @@ -981,11 +983,11 @@ public function testAutoReleaseMinutesIsSetToMinimumAutoReleaseMinutes_IfNotChec $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->reservationAuthorization->expects($this->once()) ->method('CanEdit') - ->will($this->returnValue(true)); + ->willReturn(true); $this->reservationDetailsBinder = new ReservationDetailsBinder( $this->reservationAuthorization, @@ -1012,7 +1014,7 @@ public function testAutoReleaseMinutesNotSetIfCheckedIn() $this->initializer->expects($this->any()) ->method('CurrentUser') - ->will($this->returnValue($this->fakeUser)); + ->willReturn($this->fakeUser); $this->reservationDetailsBinder = new ReservationDetailsBinder( $this->reservationAuthorization, diff --git a/tests/Application/Reservation/ReservationConflictResolutionTest.php b/tests/Application/Reservation/ReservationConflictResolutionTest.php index e1bb4f5e5..189518de9 100644 --- a/tests/Application/Reservation/ReservationConflictResolutionTest.php +++ b/tests/Application/Reservation/ReservationConflictResolutionTest.php @@ -25,7 +25,7 @@ public function testDeletesReservation() $repo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($id)) - ->will($this->returnValue($reservation)); + ->willReturn($reservation); $repo->expects($this->once()) ->method('Delete') diff --git a/tests/Application/Reservation/ReservationNotificationFactoryTest.php b/tests/Application/Reservation/ReservationNotificationFactoryTest.php index 4c4cd491f..fb546ffd3 100644 --- a/tests/Application/Reservation/ReservationNotificationFactoryTest.php +++ b/tests/Application/Reservation/ReservationNotificationFactoryTest.php @@ -31,7 +31,7 @@ public function testLoadsAddFromPlugins() $this->plugin->expects($this->once()) ->method('CreatePostAddService') ->with($this->fakeUser) - ->will($this->returnValue($this->service)); + ->willReturn($this->service); $reservationValidationFactory = new ReservationNotificationFactory(); $actual = $reservationValidationFactory->Create(ReservationAction::Create, $this->fakeUser); @@ -44,7 +44,7 @@ public function testLoadsUpdateRulesFromPlugins() $this->plugin->expects($this->once()) ->method('CreatePostUpdateService') ->with($this->fakeUser) - ->will($this->returnValue($this->service)); + ->willReturn($this->service); $reservationValidationFactory = new ReservationNotificationFactory(); $actual = $reservationValidationFactory->Create(ReservationAction::Update, $this->fakeUser); @@ -57,7 +57,7 @@ public function testLoadsDeleteRulesFromPlugins() $this->plugin->expects($this->once()) ->method('CreatePostDeleteService') ->with($this->fakeUser) - ->will($this->returnValue($this->service)); + ->willReturn($this->service); $reservationValidationFactory = new ReservationNotificationFactory(); $actual = $reservationValidationFactory->Create(ReservationAction::Delete, $this->fakeUser); @@ -71,7 +71,7 @@ public function testLoadsApproveRulesFromPlugins() $this->plugin->expects($this->once()) ->method('CreatePostApproveService') ->with($this->fakeUser) - ->will($this->returnValue($this->service)); + ->willReturn($this->service); $reservationValidationFactory = new ReservationNotificationFactory(); $actual = $reservationValidationFactory->Create(ReservationAction::Approve, $this->fakeUser); diff --git a/tests/Application/Reservation/ReservationStartTimeRuleTest.php b/tests/Application/Reservation/ReservationStartTimeRuleTest.php index 166a6aa5c..215c9aae1 100644 --- a/tests/Application/Reservation/ReservationStartTimeRuleTest.php +++ b/tests/Application/Reservation/ReservationStartTimeRuleTest.php @@ -108,13 +108,13 @@ public function testWhenAllowedToWorkWithCurrentSlot() $this->scheduleRepository->expects($this->once()) ->method('GetLayout') ->with($this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory('UTC'))) - ->will($this->returnValue($this->layout)); + ->willReturn($this->layout); $period = new SchedulePeriod($periodStart, $periodEnd); $this->layout->expects($this->once()) ->method('GetPeriod') ->with($this->equalTo($end)) - ->will($this->returnValue($period)); + ->willReturn($period); $rule = new ReservationStartTimeRule($this->scheduleRepository); @@ -144,13 +144,13 @@ public function testWhenPeriodStartTimeIsInPast() $this->scheduleRepository->expects($this->once()) ->method('GetLayout') ->with($this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory('UTC'))) - ->will($this->returnValue($this->layout)); + ->willReturn($this->layout); $period = new SchedulePeriod($periodStart, $periodEnd); $this->layout->expects($this->once()) ->method('GetPeriod') ->with($this->equalTo($end)) - ->will($this->returnValue($period)); + ->willReturn($period); $rule = new ReservationStartTimeRule($this->scheduleRepository); diff --git a/tests/Application/Reservation/ReservationValidationFactoryTest.php b/tests/Application/Reservation/ReservationValidationFactoryTest.php index 650144fdb..d4aca44b2 100644 --- a/tests/Application/Reservation/ReservationValidationFactoryTest.php +++ b/tests/Application/Reservation/ReservationValidationFactoryTest.php @@ -16,7 +16,7 @@ public function testLoadsAddRulesFromPlugins() $preResPlugin->expects($this->once()) ->method('CreatePreAddService') ->with($this->fakeUser) - ->will($this->returnValue($validationService)); + ->willReturn($validationService); $reservationValidationFactory = new ReservationValidationFactory(); $actual = $reservationValidationFactory->Create(ReservationAction::Create, $this->fakeUser); @@ -36,7 +36,7 @@ public function testLoadsUpdateRulesFromPlugins() $preResPlugin->expects($this->once()) ->method('CreatePreUpdateService') ->with($this->fakeUser) - ->will($this->returnValue($validationService)); + ->willReturn($validationService); $reservationValidationFactory = new ReservationValidationFactory(); $actual = $reservationValidationFactory->Create(ReservationAction::Update, $this->fakeUser); @@ -56,7 +56,7 @@ public function testLoadsDeleteRulesFromPlugins() $preResPlugin->expects($this->once()) ->method('CreatePreDeleteService') ->with($this->fakeUser) - ->will($this->returnValue($validationService)); + ->willReturn($validationService); $reservationValidationFactory = new ReservationValidationFactory(); $actual = $reservationValidationFactory->Create(ReservationAction::Delete, $this->fakeUser); diff --git a/tests/Application/Reservation/ReservationValidationRuleProcessorTest.php b/tests/Application/Reservation/ReservationValidationRuleProcessorTest.php index a7b177791..98364af43 100644 --- a/tests/Application/Reservation/ReservationValidationRuleProcessorTest.php +++ b/tests/Application/Reservation/ReservationValidationRuleProcessorTest.php @@ -26,17 +26,17 @@ public function testValidatesAgainstAllRules() $rule1->expects($this->once()) ->method('Validate') ->with($this->equalTo($reservation)) - ->will($this->returnValue($validResult)); + ->willReturn($validResult); $rule2->expects($this->once()) ->method('Validate') ->with($this->equalTo($reservation)) - ->will($this->returnValue($validResult)); + ->willReturn($validResult); $rule3->expects($this->once()) ->method('Validate') ->with($this->equalTo($reservation)) - ->will($this->returnValue($validResult)); + ->willReturn($validResult); $rules = [$rule1, $rule2, $rule3]; @@ -61,7 +61,7 @@ public function testValidatesStopsAfterFirstBrokenRule() $rule1->expects($this->once()) ->method('Validate') ->with($this->equalTo($reservation)) - ->will($this->returnValue(new ReservationRuleResult())); + ->willReturn(new ReservationRuleResult()); $error = 'something went wrong'; $retryMessage = 'retry message'; @@ -70,7 +70,7 @@ public function testValidatesStopsAfterFirstBrokenRule() $rule2->expects($this->once()) ->method('Validate') ->with($this->equalTo($reservation)) - ->will($this->returnValue(new ReservationRuleResult(false, $error, true, $retryMessage, $retryParams))); + ->willReturn(new ReservationRuleResult(false, $error, true, $retryMessage, $retryParams)); $vs = new ReservationValidationRuleProcessor($rules); diff --git a/tests/Application/Reservation/ResourceAvailabilityRuleTest.php b/tests/Application/Reservation/ResourceAvailabilityRuleTest.php index 60266ef80..625bc9a7a 100644 --- a/tests/Application/Reservation/ResourceAvailabilityRuleTest.php +++ b/tests/Application/Reservation/ResourceAvailabilityRuleTest.php @@ -42,7 +42,7 @@ public function testRuleIsValidIfNoConflictsForTheReservationResources() $strategy->expects($this->once()) ->method('GetItemsBetween') ->with($this->equalTo($startDate), $this->equalTo($endDate)) - ->will($this->returnValue([$scheduleReservation])); + ->willReturn([$scheduleReservation]); $rule = new ResourceAvailabilityRule(new ReservationConflictIdentifier($strategy), 'UTC'); $result = $rule->Validate($reservation, null); @@ -85,7 +85,7 @@ public function testGetsConflictingReservationTimesForSingleDateSingleResource() $strategy->expects($this->once()) ->method('GetItemsBetween') ->with($this->equalTo($startDate), $this->equalTo($endDate)) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $rule = new ResourceAvailabilityRule(new ReservationConflictIdentifier($strategy), 'UTC'); $result = $rule->Validate($reservation, null); @@ -122,7 +122,7 @@ public function testGetsConflictingReservationTimesForSingleDateMultipleResource $strategy->expects($this->once()) ->method('GetItemsBetween') ->with($this->equalTo($startDate), $this->equalTo($endDate)) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $rule = new ResourceAvailabilityRule(new ReservationConflictIdentifier($strategy), 'UTC'); $result = $rule->Validate($reservation, null); @@ -191,7 +191,7 @@ public function testRuleIsValidIfNoConflictsForTheReservationResourcesWithBuffer $strategy->expects($this->once()) ->method('GetItemsBetween') ->with($this->equalTo($startDate->AddMinutes(-60)), $this->equalTo($endDate->AddMinutes(60))) - ->will($this->returnValue([$scheduleReservation1, $scheduleReservation2, $scheduleReservation3, $scheduleReservation4, $scheduleReservation5])); + ->willReturn([$scheduleReservation1, $scheduleReservation2, $scheduleReservation3, $scheduleReservation4, $scheduleReservation5]); $rule = new ResourceAvailabilityRule(new ReservationConflictIdentifier($strategy), 'UTC'); $result = $rule->Validate($reservation, null); @@ -259,7 +259,7 @@ public function testGetsConflictingReservationTimesForSingleDateSingleResourceWi $strategy->expects($this->once()) ->method('GetItemsBetween') ->with($this->equalTo($startDate->AddMinutes(-60)), $this->equalTo($endDate->AddMinutes(60))) - ->will($this->returnValue([$conflict1, $conflict2, $nonConflict1, $nonConflict2, $nonConflict3])); + ->willReturn([$conflict1, $conflict2, $nonConflict1, $nonConflict2, $nonConflict3]); $rule = new ResourceAvailabilityRule(new ReservationConflictIdentifier($strategy), 'UTC'); @@ -297,7 +297,7 @@ public function testApplicationAdminsAreExcludedFromBufferConstraints() $strategy->expects($this->once()) ->method('GetItemsBetween') ->with($this->equalTo($startDate), $this->equalTo($endDate)) - ->will($this->returnValue([$conflict1])); + ->willReturn([$conflict1]); $rule = new ResourceAvailabilityRule(new ReservationConflictIdentifier($strategy), "UTC"); @@ -325,7 +325,7 @@ public function testValidatesEachDateThatAReservationRepeatsOn() $strategy->expects($this->exactly(1 + count($repeatDates))) ->method('GetItemsBetween') ->with($this->anything(), $this->anything()) - ->will($this->returnValue([])); + ->willReturn([]); $rule = new ResourceAvailabilityRule(new ReservationConflictIdentifier($strategy), 'UTC'); $result = $rule->Validate($reservation, null); @@ -347,13 +347,13 @@ public function testReservationStrategyChecksReservations() $repository->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($startDate), $this->equalTo($endDate), $this->isNull(), $this->isNull(), $this->isNull(), $this->equalTo($resourceIds)) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $blackouts = ['blackout']; $repository->expects($this->once()) ->method('GetBlackoutsWithin') ->with($this->equalTo(new DateRange($startDate, $endDate))) - ->will($this->returnValue($blackouts)); + ->willReturn($blackouts); $items = $strategy->GetItemsBetween($startDate, $endDate, $resourceIds); @@ -380,15 +380,18 @@ public function testCanRetryIfThereAreConflictsThatCanBeSkipped() $strategy = $this->createMock('IResourceAvailabilityStrategy'); - $strategy->expects($this->at(0)) + $strategy->expects($this->exactly(2)) ->method('GetItemsBetween') - ->with($this->equalTo($startDate), $this->equalTo($endDate)) - ->will($this->returnValue($reservations)); + ->willReturnCallback(function(Date $start, Date $end) use ($startDate, $endDate, $reservations, $instance) + { + if ($start->Equals($startDate) && $end->Equals($endDate)) + return $reservations; - $strategy->expects($this->at(1)) - ->method('GetItemsBetween') - ->with($this->equalTo($instance->GetBegin()), $this->equalTo($instance->GetEnd())) - ->will($this->returnValue([])); + if ($start->Equals($instance->GetBegin()) && $end->Equals($instance->GetEnd())) + return []; + + throw new Exception("Unexpected arguments"); + }); $rule = new ResourceAvailabilityRule(new ReservationConflictIdentifier($strategy), 'UTC'); $result = $rule->Validate($reservation, null); @@ -420,15 +423,18 @@ public function testSkipsConflictsIfRequested() $strategy = $this->createMock('IResourceAvailabilityStrategy'); - $strategy->expects($this->at(0)) + $strategy->expects($this->exactly(2)) ->method('GetItemsBetween') - ->with($this->equalTo($startDate), $this->equalTo($endDate)) - ->will($this->returnValue([])); + ->willReturnCallback(function(Date $start, Date $end) use ($startDate, $endDate, $reservations, $instance) + { + if ($start->Equals($startDate) && $end->Equals($endDate)) + return []; - $strategy->expects($this->at(1)) - ->method('GetItemsBetween') - ->with($this->equalTo($instance->GetBegin()), $this->equalTo($instance->GetEnd())) - ->will($this->returnValue($reservations)); + if ($start->Equals($instance->GetBegin()) && $end->Equals($instance->GetEnd())) + return $reservations; + + throw new Exception("Unexpected arguments"); + }); $rule = new ResourceAvailabilityRule(new ReservationConflictIdentifier($strategy), 'UTC'); $result = $rule->Validate($reservation, [new ReservationRetryParameter(ReservationRetryParameter::$SKIP_CONFLICTS, true)]); @@ -464,7 +470,7 @@ public function testSkipsCorrectDatesWhenUpdatingExisting() $strategy->expects($this->atLeastOnce()) ->method('GetItemsBetween') - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $rule = new ResourceAvailabilityRule(new ReservationConflictIdentifier($strategy, $this->scheduleRepository), 'UTC'); $result = $rule->Validate($reservation, [new ReservationRetryParameter(ReservationRetryParameter::$SKIP_CONFLICTS, true)]); diff --git a/tests/Application/Reservation/ResourceCrossDayRuleTest.php b/tests/Application/Reservation/ResourceCrossDayRuleTest.php index 67eedfe83..55f0764b7 100644 --- a/tests/Application/Reservation/ResourceCrossDayRuleTest.php +++ b/tests/Application/Reservation/ResourceCrossDayRuleTest.php @@ -43,7 +43,7 @@ public function testRuleIsValidIfBeginsAndEndsOnSameDayInScheduleTimezone() $this->scheduleRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($reservation->ScheduleId())) - ->will($this->returnValue($this->schedule)); + ->willReturn($this->schedule); $rule = new ResourceCrossDayRule($this->scheduleRepository); $result = $rule->Validate($reservation, null); @@ -92,7 +92,7 @@ public function testRuleIsInValidIfReservationCrossesDayInScheduleTimezone() $this->scheduleRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($reservation->ScheduleId())) - ->will($this->returnValue($this->schedule)); + ->willReturn($this->schedule); $rule = new ResourceCrossDayRule($this->scheduleRepository); $result = $rule->Validate($reservation, null); diff --git a/tests/Application/Reservation/SchedulePeriodRuleTest.php b/tests/Application/Reservation/SchedulePeriodRuleTest.php index 31e945a6c..532e7e62a 100644 --- a/tests/Application/Reservation/SchedulePeriodRuleTest.php +++ b/tests/Application/Reservation/SchedulePeriodRuleTest.php @@ -47,13 +47,13 @@ public function testFailsWhenStartTimeDoesNotMatchPeriod() $this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory($this->fakeUser->Timezone)) ) - ->will($this->returnValue($this->layout)); + ->willReturn($this->layout); $this->layout - ->expects($this->at(0)) + ->expects($this->atLeastOnce()) ->method('GetPeriod') ->with($this->equalTo($series->CurrentInstance()->StartDate())) - ->will($this->returnValue(new SchedulePeriod($date, $date->AddMinutes(1)))); + ->willReturn(new SchedulePeriod($date->AddMinutes(1), $date)); $result = $this->rule->Validate($series, null); @@ -77,19 +77,26 @@ public function testFailsWhenEndTimeDoesNotMatchPeriod() $this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory($this->fakeUser->Timezone)) ) - ->will($this->returnValue($this->layout)); + ->willReturn($this->layout); + $matcher = $this->exactly(2); $this->layout - ->expects($this->at(0)) + ->expects($matcher) ->method('GetPeriod') - ->with($this->equalTo($series->CurrentInstance()->StartDate())) - ->will($this->returnValue(new SchedulePeriod($date, $date))); - - $this->layout - ->expects($this->at(1)) - ->method('GetPeriod') - ->with($this->equalTo($series->CurrentInstance()->EndDate())) - ->will($this->returnValue(new SchedulePeriod($date->AddMinutes(1), $date))); + ->willReturnCallback(function (Date $d) use ($matcher, $series, $date) + { + match ($matcher->numberOfInvocations()) + { + 1 => $this->assertEquals($d, $series->CurrentInstance()->StartDate()), + 2 => $this->assertEquals($d, $series->CurrentInstance()->EndDate()) + }; + + return match ($matcher->numberOfInvocations()) + { + 1 => new SchedulePeriod($date, $date), + 2 => new SchedulePeriod($date->AddMinutes(1), $date->AddMinutes(1)) + }; + }); $result = $this->rule->Validate($series, null); @@ -113,20 +120,13 @@ public function testSucceedsWhenStartAndEndTimeMatchPeriods() $this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory($this->fakeUser->Timezone)) ) - ->will($this->returnValue($this->layout)); + ->willReturn($this->layout); $period = new SchedulePeriod($date, $date); $this->layout - ->expects($this->at(0)) - ->method('GetPeriod') - ->with($this->equalTo($series->CurrentInstance()->StartDate())) - ->will($this->returnValue($period)); - - $this->layout - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('GetPeriod') - ->with($this->equalTo($series->CurrentInstance()->EndDate())) - ->will($this->returnValue($period)); + ->willReturn($period); $result = $this->rule->Validate($series, null); diff --git a/tests/Application/Schedule/CalendarSubscriptionServiceTest.php b/tests/Application/Schedule/CalendarSubscriptionServiceTest.php index 0a19a47c4..f9694230b 100644 --- a/tests/Application/Schedule/CalendarSubscriptionServiceTest.php +++ b/tests/Application/Schedule/CalendarSubscriptionServiceTest.php @@ -43,7 +43,7 @@ public function testGetsUserByPublicId() $this->userRepo->expects($this->once()) ->method('LoadByPublicId') ->with($this->equalTo($publicId)) - ->will($this->returnValue($expected)); + ->willReturn($expected); $actual = $this->service->GetUser($publicId); @@ -58,7 +58,7 @@ public function testGetsResourceByPublicId() $this->resourceRepo->expects($this->once()) ->method('LoadByPublicId') ->with($this->equalTo($publicId)) - ->will($this->returnValue($expected)); + ->willReturn($expected); $actual = $this->service->GetResource($publicId); @@ -73,7 +73,7 @@ public function testGetsScheduleByPublicId() $this->scheduleRepo->expects($this->once()) ->method('LoadByPublicId') ->with($this->equalTo($publicId)) - ->will($this->returnValue($expected)); + ->willReturn($expected); $actual = $this->service->GetSchedule($publicId); diff --git a/tests/Application/Schedule/DailyLayoutTest.php b/tests/Application/Schedule/DailyLayoutTest.php index ade6709df..140b99ca7 100644 --- a/tests/Application/Schedule/DailyLayoutTest.php +++ b/tests/Application/Schedule/DailyLayoutTest.php @@ -33,7 +33,7 @@ public function testGetLayoutReturnsBuiltSlotsFromScheduleReservationList() $listing->expects($this->once()) ->method('OnDateForResource') ->with($this->equalTo($date), $this->equalTo($resourceId)) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $layout = new DailyLayout($listing, $scheduleLayout); $layoutSlots = $layout->GetLayout($date, $resourceId); @@ -57,7 +57,7 @@ public function testCanGetDisplayLabelsForDate() $scheduleLayout->expects($this->once()) ->method('GetLayout') ->with($this->equalTo($displayDate)) - ->will($this->returnValue($periods)); + ->willReturn($periods); $layout = new DailyLayout(new ReservationListing("America/Chicago"), $scheduleLayout); $labels = $layout->GetLabels($displayDate); @@ -91,11 +91,11 @@ public function testGetsLayoutWithHourIndications() $scheduleLayout->expects($this->once()) ->method('GetLayout') ->with($this->equalTo($displayDate)) - ->will($this->returnValue($periods)); + ->willReturn($periods); $scheduleLayout->expects($this->once()) ->method('FitsToHours') - ->will($this->returnValue(true)); + ->willReturn(true); $layout = new DailyLayout(new ReservationListing("America/Chicago"), $scheduleLayout); $labels = $layout->GetPeriods($displayDate, true); @@ -152,7 +152,7 @@ public function testGetsDailySummaryForResource() $listing->expects($this->once()) ->method('OnDateForResource') ->with($this->equalTo($date), $this->equalTo($resourceId)) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $layout = new DailyLayout($listing, $scheduleLayout); $summary = $layout->GetSummary($date, $resourceId); diff --git a/tests/Application/Schedule/ResourcePermissionStoreTest.php b/tests/Application/Schedule/ResourcePermissionStoreTest.php index 95b17ced1..896f3c91c 100644 --- a/tests/Application/Schedule/ResourcePermissionStoreTest.php +++ b/tests/Application/Schedule/ResourcePermissionStoreTest.php @@ -27,14 +27,14 @@ public function testRepositoryIsAccessedForUserPermissionInformation() $user->expects($this->once()) ->method('GetAllResources') - ->will($this->returnValue([$r1, $r2, $r3, $r4])); + ->willReturn([$r1, $r2, $r3, $r4]); $userRepository = $this->createMock('IScheduleUserRepository'); $userRepository->expects($this->once()) ->method('GetUser') ->with($this->equalTo($userId)) - ->will($this->returnValue($user)); + ->willReturn($user); $rps = new ResourcePermissionStore($userRepository); @@ -65,7 +65,7 @@ public function testGetsFullPermissions() $userRepository = $this->createMock('IScheduleUserRepository'); $userRepository->expects($this->any()) ->method('GetUser') - ->will($this->returnValue($user)); + ->willReturn($user); $rps = new ResourcePermissionStore($userRepository); diff --git a/tests/Application/Schedule/ResourceServiceTest.php b/tests/Application/Schedule/ResourceServiceTest.php index 261e823c8..a783aa21a 100644 --- a/tests/Application/Schedule/ResourceServiceTest.php +++ b/tests/Application/Schedule/ResourceServiceTest.php @@ -68,70 +68,28 @@ public function testResourceServiceChecksPermissionForEachResource() ->expects($this->once()) ->method('GetScheduleResources') ->with($this->equalTo($scheduleId)) - ->will($this->returnValue($resources)); + ->willReturn($resources); + $matcher = $this->exactly(4); $this->permissionService - ->expects($this->at(0)) + ->expects($matcher) ->method('CanAccessResource') - ->with( - $this->equalTo($resource1), - $this->equalTo($user) - ) - ->will($this->returnValue(true)); - - $this->permissionService - ->expects($this->at(1)) - ->method('CanBookResource') - ->with( - $this->equalTo($resource1), - $this->equalTo($user) - ) - ->will($this->returnValue(true)); - - $this->permissionService - ->expects($this->at(2)) - ->method('CanAccessResource') - ->with( - $this->equalTo($resource2), - $this->equalTo($user) - ) - ->will($this->returnValue(true)); - - $this->permissionService - ->expects($this->at(3)) - ->method('CanBookResource') - ->with( - $this->equalTo($resource2), - $this->equalTo($user) - ) - ->will($this->returnValue(true)); - - $this->permissionService - ->expects($this->at(4)) - ->method('CanAccessResource') - ->with( - $this->equalTo($resource3), - $this->equalTo($user) - ) - ->will($this->returnValue(true)); + ->willReturnCallback(function ($res, $u) use ($matcher, $resource1, $resource2, $resource3, $resource4, $user) { + $this->assertEquals($u, $user); + match ($matcher->numberOfInvocations()) + { + 1 => $this->assertEquals($res, $resource1), + 2 => $this->assertEquals($res, $resource2), + 3 => $this->assertEquals($res, $resource3), + 4 => $this->assertEquals($res, $resource4) + }; + return $matcher->numberOfInvocations() == 4 ? false : true; + }); $this->permissionService - ->expects($this->at(5)) + ->expects($this->exactly(3)) ->method('CanBookResource') - ->with( - $this->equalTo($resource3), - $this->equalTo($user) - ) - ->will($this->returnValue(true)); - - $this->permissionService - ->expects($this->at(6)) - ->method('CanAccessResource') - ->with( - $this->equalTo($resource4), - $this->equalTo($user) - ) - ->will($this->returnValue(false)); + ->willReturn(true); $resourceDto1 = new ResourceDto( 1, @@ -226,39 +184,37 @@ public function testGetAllChecksPermissionForEachResource() $this->resourceRepository ->expects($this->once()) ->method('GetResourceList') - ->will($this->returnValue($resources)); - - $this->permissionService - ->expects($this->at(0)) - ->method('CanAccessResource') - ->with( - $this->equalTo($resource1), - $this->equalTo($session) - ) - ->will($this->returnValue(false)); + ->willReturn($resources); + $matcher = $this->exactly(2); $this->permissionService - ->expects($this->at(1)) + ->expects($matcher) ->method('CanAccessResource') - ->with( - $this->equalTo($resource2), - $this->equalTo($session) - ) - ->will($this->returnValue(true)); + ->willReturnCallback(function($res, $ses) use ($resource1, $resource2, $session, $matcher) + { + $this->assertEquals($ses, $session); + match ($matcher->numberOfInvocations()) + { + 1 => $this->assertEquals($res, $resource1), + 2 => $this->assertEquals($res, $resource2), + }; + return $matcher->numberOfInvocations() == 2; + }); $this->permissionService - ->expects($this->at(2)) + ->expects($this->once()) ->method('CanBookResource') ->with( $this->equalTo($resource2), $this->equalTo($session) ) - ->will($this->returnValue(true)); + ->willReturn(true); + $this->userRepository->expects($this->any()) ->method('LoadById') ->with($this->equalTo($session->UserId)) - ->will($this->returnValue($user)); + ->willReturn($user); $resourceDto1 = new ResourceDto( 1, @@ -320,21 +276,21 @@ public function testChecksStatusOfEachResourceWhenGettingAll() ->expects($this->any()) ->method('GetScheduleResources') ->with($this->equalTo($scheduleId)) - ->will($this->returnValue($resources)); + ->willReturn($resources); $this->permissionService - ->expects($this->at(0)) + ->expects($this->any()) ->method('CanAccessResource') ->with( $this->equalTo($resource1), $this->equalTo($session) ) - ->will($this->returnValue(true)); + ->willReturn(true); $this->userRepository->expects($this->any()) ->method('LoadById') ->with($this->equalTo($session->UserId)) - ->will($this->returnValue($user)); + ->willReturn($user); $resourceDto1 = new ResourceDto( 1, @@ -376,13 +332,13 @@ public function testResourcesAreNotReturnedIfNotIncludingInaccessibleResources() ->expects($this->once()) ->method('GetScheduleResources') ->with($this->equalTo($scheduleId)) - ->will($this->returnValue([$resource1])); + ->willReturn([$resource1]); $this->permissionService - ->expects($this->at(0)) + ->expects($this->once()) ->method('CanAccessResource') ->with($this->equalTo($resource1)) - ->will($this->returnValue(false)); + ->willReturn(false); $includeInaccessibleResources = false; $actual = $this->resourceService->GetScheduleResources($scheduleId, $includeInaccessibleResources, $user); @@ -397,7 +353,7 @@ public function testGetsAccessoriesFromRepository() $this->accessoryRepository ->expects($this->once()) ->method('LoadAll') - ->will($this->returnValue($accessories)); + ->willReturn($accessories); $actualAccessories = $this->resourceService->GetAccessories(); @@ -419,20 +375,20 @@ public function testFiltersResources() ->expects($this->once()) ->method('GetScheduleResources') ->with($this->equalTo($scheduleId)) - ->will($this->returnValue($resources)); + ->willReturn($resources); $this->permissionService ->expects($this->any()) ->method('CanAccessResource') ->with($this->anything(), $this->anything()) - ->will($this->returnValue(true)); + ->willReturn(true); $filter = $this->createMock('IScheduleResourceFilter'); $filter->expects($this->once()) ->method('FilterResources') ->with($this->equalTo($resources), $this->equalTo($this->resourceRepository)) - ->will($this->returnValue([$resourceId])); + ->willReturn([$resourceId]); $resources = $this->resourceService->GetScheduleResources($scheduleId, true, $this->fakeUser, $filter); @@ -447,7 +403,7 @@ public function testGetsResourceCustomAttributes() $this->attributeService->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo(CustomAttributeCategory::RESOURCE)) - ->will($this->returnValue($customAttributes)); + ->willReturn($customAttributes); $attributes = $this->resourceService->GetResourceAttributes(); @@ -462,7 +418,7 @@ public function testGetsResourceTypeCustomAttributes() $this->attributeService->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo(CustomAttributeCategory::RESOURCE_TYPE)) - ->will($this->returnValue($customAttributes)); + ->willReturn($customAttributes); $attributes = $this->resourceService->GetResourceTypeAttributes(); @@ -479,7 +435,7 @@ public function testFiltersResourcesWhenGettingResourceGroups() $this->resourceRepository->expects($this->once()) ->method('GetResourceGroups') ->with($this->equalTo($scheduleId), $this->anything()) - ->will($this->returnValue($expectedGroups)); + ->willReturn($expectedGroups); $groups = $this->resourceService->GetResourceGroups($scheduleId, $this->fakeUser); diff --git a/tests/Application/Schedule/ScheduleReservationListTest.php b/tests/Application/Schedule/ScheduleReservationListTest.php index 9092d8cbb..acbadb8d3 100644 --- a/tests/Application/Schedule/ScheduleReservationListTest.php +++ b/tests/Application/Schedule/ScheduleReservationListTest.php @@ -73,12 +73,12 @@ public function testLayoutIsConvertedToUserTimezoneBeforeSlotsAreCreated() $layout = $this->createMock('IScheduleLayout'); $layout->expects($this->once()) ->method('Timezone') - ->will($this->returnValue($userTz)); + ->willReturn($userTz); $layout->expects($this->once()) ->method('GetLayout') ->with($this->equalTo($date), $this->equalTo($hideBlocked)) - ->will($this->returnValue($layoutPeriods)); + ->willReturn($layoutPeriods); $scheduleList = new ScheduleReservationList([$r1], $layout, $date, $hideBlocked); $slots = $scheduleList->BuildSlots(); diff --git a/tests/Application/Schedule/ScheduleResourceFilterTest.php b/tests/Application/Schedule/ScheduleResourceFilterTest.php index 0b13cac5b..3cde707bb 100644 --- a/tests/Application/Schedule/ScheduleResourceFilterTest.php +++ b/tests/Application/Schedule/ScheduleResourceFilterTest.php @@ -123,7 +123,7 @@ public function testFiltersResourceCustomAttributes() $this->attributeService->expects($this->once()) ->method('GetAttributes') ->with($this->equalTo(CustomAttributeCategory::RESOURCE), $this->isNull()) - ->will($this->returnValue($attributeList)); + ->willReturn($attributeList); $filter = new ScheduleResourceFilter(); $filter->ResourceAttributes = [ @@ -163,7 +163,7 @@ public function testFiltersResourceTypeCustomAttributes() $this->attributeService->expects($this->once()) ->method('GetAttributes') ->with($this->equalTo(CustomAttributeCategory::RESOURCE_TYPE), $this->isNull()) - ->will($this->returnValue($attributeList)); + ->willReturn($attributeList); $filter = new ScheduleResourceFilter(); $filter->ResourceTypeAttributes = [ diff --git a/tests/Application/Schedule/SlotLabelFactoryTest.php b/tests/Application/Schedule/SlotLabelFactoryTest.php index 03eb89ffe..ffb1ed611 100644 --- a/tests/Application/Schedule/SlotLabelFactoryTest.php +++ b/tests/Application/Schedule/SlotLabelFactoryTest.php @@ -19,6 +19,8 @@ public function setUp(): void $this->reservation->LastName = 'last'; $this->reservation->StartDate = Date::Now(); $this->reservation->EndDate = Date::Now(); + $this->reservation->UserId = 1; + $this->reservation->UserLevelId = ReservationUserLevel::OWNER; } public function testGetsNone() diff --git a/tests/Application/User/ManageUsersServiceTest.php b/tests/Application/User/ManageUsersServiceTest.php index d1f062510..fd53319e7 100644 --- a/tests/Application/User/ManageUsersServiceTest.php +++ b/tests/Application/User/ManageUsersServiceTest.php @@ -89,7 +89,7 @@ public function testAddsUser() $this->equalTo($extraAttributes), $this->equalTo($customAttributes) ) - ->will($this->returnValue($user)); + ->willReturn($user); $actualUser = $this->service->AddUser( $username, @@ -138,12 +138,12 @@ public function testDeleteDelegatesToRepositoryAndSendsEmails() $this->userViewRepo->expects($this->once()) ->method('GetApplicationAdmins') - ->will($this->returnValue($appAdmins)); + ->willReturn($appAdmins); $this->userViewRepo->expects($this->once()) ->method('GetGroupAdmins') ->with($this->equalTo($userId)) - ->will($this->returnValue($groupAdmins)); + ->willReturn($groupAdmins); $this->service->DeleteUser($userId); @@ -203,20 +203,13 @@ public function testAddsAndRemovesUserFromGroups() $group4 = new FakeGroup(4); $group4->WithUser($userId); - $this->groupRepo->expects($this->at(0)) + $this->groupRepo->expects($this->exactly(3)) ->method('LoadById') - ->with($this->equalTo(2)) - ->will($this->returnValue($group2)); - - $this->groupRepo->expects($this->at(2)) - ->method('LoadById') - ->with($this->equalTo(3)) - ->will($this->returnValue($group3)); - - $this->groupRepo->expects($this->at(4)) - ->method('LoadById') - ->with($this->equalTo(4)) - ->will($this->returnValue($group4)); + ->willReturnMap([ + [2, $group2], + [3, $group3], + [4, $group4] + ]); $this->service->ChangeGroups($user, $groupids); diff --git a/tests/Domain/Reservation/QuotaTest.php b/tests/Domain/Reservation/QuotaTest.php index e63cfcdfc..697fc94fc 100644 --- a/tests/Domain/Reservation/QuotaTest.php +++ b/tests/Domain/Reservation/QuotaTest.php @@ -940,7 +940,7 @@ public function testTwoFullDayReservationWith24HoursPerDayLimitBackToBack() $this->reservationViewRepository->expects($this->any()) ->method('GetReservations') - ->will($this->returnValue([$res1])); + ->willReturn([$res1]); $exceeds = $quota->ExceedsQuota($series, $this->user, $this->schedule, $this->reservationViewRepository); @@ -955,7 +955,7 @@ public function testTwoDayReservationWith24HoursPerDayLimit() $this->reservationViewRepository->expects($this->any()) ->method('GetReservations') - ->will($this->returnValue([])); + ->willReturn([]); $exceeds = $quota->ExceedsQuota($series, $this->user, $this->schedule, $this->reservationViewRepository); @@ -971,7 +971,7 @@ public function testBugOvernightBookingCausingNewReservationsToExceedQuota() $this->reservationViewRepository->expects($this->any()) ->method('GetReservations') - ->will($this->returnValue([$overnightReservation])); + ->willReturn([$overnightReservation]); $exceeds = $quota->ExceedsQuota($series, $this->user, $this->schedule, $this->reservationViewRepository); @@ -1018,7 +1018,7 @@ private function ShouldSearchBy($startSearch, $endSearch, $series, $reservations $this->equalTo($series->UserId()), $this->equalTo(ReservationUserLevel::OWNER) ) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); } private function SearchReturns($reservations) @@ -1026,6 +1026,6 @@ private function SearchReturns($reservations) $this->reservationViewRepository->expects($this->once()) ->method('GetReservations') ->with($this->anything(), $this->anything(), $this->anything(), $this->anything()) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); } } diff --git a/tests/Domain/Reservation/QuotaWhenModifyingTest.php b/tests/Domain/Reservation/QuotaWhenModifyingTest.php index f7530107a..559156418 100644 --- a/tests/Domain/Reservation/QuotaWhenModifyingTest.php +++ b/tests/Domain/Reservation/QuotaWhenModifyingTest.php @@ -187,6 +187,6 @@ private function SearchReturns($reservations) $this->reservationViewRepository->expects($this->once()) ->method('GetReservations') ->with($this->anything(), $this->anything(), $this->anything(), $this->anything()) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); } } diff --git a/tests/Domain/Reservation/ReservationRepositoryTest.php b/tests/Domain/Reservation/ReservationRepositoryTest.php index 984a98f32..57363f703 100644 --- a/tests/Domain/Reservation/ReservationRepositoryTest.php +++ b/tests/Domain/Reservation/ReservationRepositoryTest.php @@ -184,7 +184,7 @@ public function testRepeatedDatesAreSaved() $repeats->expects($this->once()) ->method('GetDates') ->with($this->anything()) - ->will($this->returnValue($dates)); + ->willReturn($dates); $userSession = new FakeUserSession(); diff --git a/tests/Domain/Reservation/ReservationServiceTest.php b/tests/Domain/Reservation/ReservationServiceTest.php index 9db7cc007..6967494dd 100644 --- a/tests/Domain/Reservation/ReservationServiceTest.php +++ b/tests/Domain/Reservation/ReservationServiceTest.php @@ -42,19 +42,19 @@ public function testGetReservationsPullsReservationFromTheRepositoryAndAddsThemT ->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($startDate), $this->equalTo($endDate), $this->isNull(), $this->isNull(), $this->equalTo($scheduleId), $this->isNull()) - ->will($this->returnValue([$res1, $res2, $res3])); + ->willReturn([$res1, $res2, $res3]); $repository ->expects($this->once()) ->method('GetBlackoutsWithin') ->with($this->equalTo(new DateRange($startDate, $endDate)), $this->equalTo($scheduleId)) - ->will($this->returnValue([$blackout1, $blackout2, $blackout3])); + ->willReturn([$blackout1, $blackout2, $blackout3]); $listingFactory ->expects($this->once()) ->method('CreateReservationListing') ->with($this->equalTo($timezone)) - ->will($this->returnValue($reservationListing)); + ->willReturn($reservationListing); $service = new ReservationService($repository, $listingFactory); diff --git a/tests/Domain/Reservation/ReservationTest.php b/tests/Domain/Reservation/ReservationTest.php index 72a32747d..32220b6e7 100644 --- a/tests/Domain/Reservation/ReservationTest.php +++ b/tests/Domain/Reservation/ReservationTest.php @@ -39,7 +39,7 @@ public function testCreatingNewSeriesSetsAllSharedDataAndCreatesInstances() $repeatOptions->expects($this->once()) ->method('GetDates') ->with($this->equalTo($dateRange->ToTimezone($userSession->Timezone))) - ->will($this->returnValue($repeatDates)); + ->willReturn($repeatDates); $resource = new FakeBookableResource($resourceId); $series = ReservationSeries::Create( diff --git a/tests/Domain/Resource/PermissionServiceTest.php b/tests/Domain/Resource/PermissionServiceTest.php index d52cd3540..872b6487e 100644 --- a/tests/Domain/Resource/PermissionServiceTest.php +++ b/tests/Domain/Resource/PermissionServiceTest.php @@ -19,7 +19,7 @@ public function testAsksStoreForAllowedResourcesAndReturnsTrueIfItExists() $store->expects($this->once()) ->method('GetAllResources') ->with($this->equalTo($userId)) - ->will($this->returnValue($resourceIdList)); + ->willReturn($resourceIdList); $canAccess = $ps->CanAccessResource($resource, $user); @@ -41,7 +41,7 @@ public function testCachesPermissionsPerUserForThisInstance() $store->expects($this->once()) ->method('GetAllResources') ->with($this->equalTo($userId)) - ->will($this->returnValue($resourceIdList)); + ->willReturn($resourceIdList); $canAccess1 = $ps->CanAccessResource($resource, $user); $canAccess2 = $ps->CanAccessResource($resource, $user); diff --git a/tests/Domain/Resource/ResourceRepositoryTest.php b/tests/Domain/Resource/ResourceRepositoryTest.php index 5e74ce773..df0caa15a 100644 --- a/tests/Domain/Resource/ResourceRepositoryTest.php +++ b/tests/Domain/Resource/ResourceRepositoryTest.php @@ -29,7 +29,7 @@ public function testCanGetAllResourcesForASchedule() $scheduleId = 10; $ra = new FakeResourceAccess(); - $rows = $ra->GetRows(); + $rows = $ra->Rows(); $this->db->SetRow(0, $rows); foreach ($rows as $row) { @@ -238,7 +238,7 @@ public function testLoadsResourceByPublicId() $publicId = uniqid(); $fr = new FakeResourceAccess(); - $rows = $fr->GetRows(); + $rows = $fr->Rows(); $this->db->SetRow(0, $rows); $car = new CustomAttributeValueRow(); @@ -263,7 +263,7 @@ public function testLoadsResourceById() $id = 1; $fr = new FakeResourceAccess(); - $rows = $fr->GetRows(); + $rows = $fr->Rows(); $this->db->SetRow(0, $rows); $car = new CustomAttributeValueRow(); diff --git a/tests/Domain/Schedule/ScheduleRepositoryTest.php b/tests/Domain/Schedule/ScheduleRepositoryTest.php index 70fb33a64..2ce188845 100644 --- a/tests/Domain/Schedule/ScheduleRepositoryTest.php +++ b/tests/Domain/Schedule/ScheduleRepositoryTest.php @@ -95,7 +95,7 @@ public function testCanGetLayoutForSchedule() $layoutFactory->expects($this->once()) ->method('CreateLayout') - ->will($this->returnValue($expectedLayout)); + ->willReturn($expectedLayout); $layout = $this->scheduleRepository->GetLayout($scheduleId, $layoutFactory); @@ -162,7 +162,7 @@ public function testCanGetLayoutForScheduleWhenDaily() $layoutFactory->expects($this->once()) ->method('CreateLayout') - ->will($this->returnValue($expectedLayout)); + ->willReturn($expectedLayout); $layout = $this->scheduleRepository->GetLayout($scheduleId, $layoutFactory); @@ -198,7 +198,7 @@ public function testLoadsPeakTimesWithLayout() $layoutFactory->expects($this->once()) ->method('CreateLayout') - ->will($this->returnValue($expectedLayout)); + ->willReturn($expectedLayout); $layoutRows = [ ColumnNames::BLOCK_START => '02:00:00', @@ -375,20 +375,20 @@ public function testCanChangeLayout() $layout->expects($this->once()) ->method('UsesDailyLayouts') - ->will($this->returnValue(false)); + ->willReturn(false); $layout->expects($this->any()) ->method('GetType') - ->will($this->returnValue(ScheduleLayout::Standard)); + ->willReturn(ScheduleLayout::Standard); $layout->expects($this->once()) ->method('Timezone') - ->will($this->returnValue($timezone)); + ->willReturn($timezone); $layout->expects($this->once()) ->method('GetSlots') ->with($this->isNull()) - ->will($this->returnValue($slots)); + ->willReturn($slots); $this->db->_ExpectedInsertId = $layoutId; @@ -434,22 +434,19 @@ public function testCanChangeLayoutWithDailySlots() $layout->expects($this->once()) ->method('UsesDailyLayouts') - ->will($this->returnValue(true)); + ->willReturn(true); $layout->expects($this->any()) ->method('GetType') - ->will($this->returnValue(ScheduleLayout::Standard)); + ->willReturn(ScheduleLayout::Standard); $layout->expects($this->once()) ->method('Timezone') - ->will($this->returnValue($timezone)); + ->willReturn($timezone); - foreach (DayOfWeek::Days() as $day) { - $layout->expects($this->at($day + 3)) - ->method('GetSlots') - ->with($this->equalTo($day)) - ->will($this->returnValue($slots)); - } + $layout->expects($this->exactly(count(DayOfWeek::Days()))) + ->method('GetSlots') + ->willReturn($slots); $this->db->_ExpectedInsertId = $layoutId; diff --git a/tests/Presenters/ActivationPresenterTest.php b/tests/Presenters/ActivationPresenterTest.php index b78eec386..6eb199874 100644 --- a/tests/Presenters/ActivationPresenterTest.php +++ b/tests/Presenters/ActivationPresenterTest.php @@ -45,7 +45,7 @@ public function testActivatesAccount() $this->page->expects($this->once()) ->method('GetActivationCode') - ->will($this->returnValue($activationCode)); + ->willReturn($activationCode); $this->page->expects($this->once()) ->method('Redirect') @@ -67,7 +67,7 @@ public function testWhenAccountCannotBeActivated() $this->page->expects($this->once()) ->method('GetActivationCode') - ->will($this->returnValue($activationCode)); + ->willReturn($activationCode); $this->page->expects($this->once()) ->method('ShowError'); diff --git a/tests/Presenters/Admin/ManageAccessoriesPresenterTest.php b/tests/Presenters/Admin/ManageAccessoriesPresenterTest.php index c951d9b17..a6ba78631 100644 --- a/tests/Presenters/Admin/ManageAccessoriesPresenterTest.php +++ b/tests/Presenters/Admin/ManageAccessoriesPresenterTest.php @@ -51,11 +51,11 @@ public function testWhenInitializing() $this->resourceRepository->expects($this->once()) ->method('GetAccessoryList') - ->will($this->returnValue($accessories)); + ->willReturn($accessories); $this->resourceRepository->expects($this->once()) ->method('GetResourceList') - ->will($this->returnValue($resources)); + ->willReturn($resources); $this->page->expects($this->once()) ->method('BindAccessories') @@ -77,11 +77,11 @@ public function testWhenAdding() $this->page->expects($this->once()) ->method('GetAccessoryName') - ->will($this->returnValue($name)); + ->willReturn($name); $this->page->expects($this->once()) ->method('GetQuantityAvailable') - ->will($this->returnValue($quantity)); + ->willReturn($quantity); $this->accessoryRepository->expects($this->once()) ->method('Add') @@ -101,20 +101,20 @@ public function testWhenEditing() $this->page->expects($this->once()) ->method('GetAccessoryId') - ->will($this->returnValue($id)); + ->willReturn($id); $this->page->expects($this->once()) ->method('GetAccessoryName') - ->will($this->returnValue($name)); + ->willReturn($name); $this->page->expects($this->once()) ->method('GetQuantityAvailable') - ->will($this->returnValue($quantity)); + ->willReturn($quantity); $this->accessoryRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($id)) - ->will($this->returnValue($currentAccessory)); + ->willReturn($currentAccessory); $this->accessoryRepository->expects($this->once()) ->method('Update') @@ -129,7 +129,7 @@ public function testWhenDeleting() $this->page->expects($this->once()) ->method('GetAccessoryId') - ->will($this->returnValue($id)); + ->willReturn($id); $this->accessoryRepository->expects($this->once()) ->method('Delete') diff --git a/tests/Presenters/Admin/ManageAttributesPresenterTest.php b/tests/Presenters/Admin/ManageAttributesPresenterTest.php index 0a194a0a3..b5122d84d 100644 --- a/tests/Presenters/Admin/ManageAttributesPresenterTest.php +++ b/tests/Presenters/Admin/ManageAttributesPresenterTest.php @@ -40,7 +40,7 @@ public function testBindsAttributesForRequestedCategory() $this->attributeRepository->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo($categoryId)) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $this->presenter->HandleDataRequest(''); @@ -79,7 +79,7 @@ public function testAddsNewAttribute() $this->attributeRepository->expects($this->once()) ->method('Add') ->with($this->equalTo($expectedAttribute)) - ->will($this->returnValue(1)); + ->willReturn(1); $this->presenter->AddAttribute(); } @@ -115,7 +115,7 @@ public function testUpdatesAttribute() $this->attributeRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($attributeId)) - ->will($this->returnValue($expectedAttribute)); + ->willReturn($expectedAttribute); $this->attributeRepository->expects($this->once()) ->method('Update') diff --git a/tests/Presenters/Admin/ManageBlackoutsPresenterTest.php b/tests/Presenters/Admin/ManageBlackoutsPresenterTest.php index ce68fe224..4d6bfa22e 100644 --- a/tests/Presenters/Admin/ManageBlackoutsPresenterTest.php +++ b/tests/Presenters/Admin/ManageBlackoutsPresenterTest.php @@ -56,26 +56,26 @@ public function testUsesTwoWeekSpanWhenNoDateFilterProvided() $this->page->expects($this->atLeastOnce()) ->method('GetStartDate') - ->will($this->returnValue(null)); + ->willReturn(null); $this->page->expects($this->atLeastOnce()) ->method('GetEndDate') - ->will($this->returnValue(null)); + ->willReturn(null); $this->page->expects($this->once()) ->method('GetScheduleId') - ->will($this->returnValue($searchedScheduleId)); + ->willReturn($searchedScheduleId); $this->page->expects($this->once()) ->method('GetResourceId') - ->will($this->returnValue($searchedResourceId)); + ->willReturn($searchedResourceId); $filter = $this->GetExpectedFilter($defaultStart, $defaultEnd, $searchedScheduleId, $searchedResourceId); $data = new PageableData(); $this->blackoutsService->expects($this->once()) ->method('LoadFiltered') ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->equalTo($filter), $this->equalTo($this->fakeUser)) - ->will($this->returnValue($data)); + ->willReturn($data); $this->page->expects($this->once()) ->method('SetStartDate') @@ -123,11 +123,11 @@ public function testAddsNewBlackoutTimeForSingleResource() $resourceId = 123; $this->page->expects($this->once()) ->method('GetBlackoutResourceId') - ->will($this->returnValue($resourceId)); + ->willReturn($resourceId); $this->page->expects($this->once()) ->method('GetApplyBlackoutToAllResources') - ->will($this->returnValue(false)); + ->willReturn(false); $result = $this->createMock('IBlackoutValidationResult'); $this->blackoutsService->expects($this->once()) @@ -139,7 +139,7 @@ public function testAddsNewBlackoutTimeForSingleResource() $this->equalTo($conflictResolution), $this->equalTo($repeatOptions) ) - ->will($this->returnValue($result)); + ->willReturn($result); $this->presenter->AddBlackout(); } @@ -172,17 +172,17 @@ public function testAddsNewBlackoutTimeForSchedule() $scheduleId = 123; $this->page->expects($this->once()) ->method('GetBlackoutScheduleId') - ->will($this->returnValue($scheduleId)); + ->willReturn($scheduleId); $this->page->expects($this->once()) ->method('GetApplyBlackoutToAllResources') - ->will($this->returnValue(true)); + ->willReturn(true); $resources = [new FakeBookableResource(1), new FakeBookableResource(2), new FakeBookableResource(3)]; $this->resourceRepository->expects($this->once()) ->method('GetScheduleResources') ->with($this->equalTo($scheduleId)) - ->will($this->returnValue($resources)); + ->willReturn($resources); $result = $this->createMock('IBlackoutValidationResult'); $this->blackoutsService->expects($this->once()) @@ -194,7 +194,7 @@ public function testAddsNewBlackoutTimeForSchedule() $this->equalTo($conflictResolution), $this->equalTo($repeatOptions) ) - ->will($this->returnValue($result)); + ->willReturn($result); $this->presenter->AddBlackout(); } @@ -206,11 +206,11 @@ public function testDeletesBlackoutById() $this->page->expects($this->once()) ->method('GetBlackoutId') - ->will($this->returnValue($id)); + ->willReturn($id); $this->page->expects($this->once()) ->method('GetSeriesUpdateScope') - ->will($this->returnValue(SeriesUpdateScope::ThisInstance)); + ->willReturn(SeriesUpdateScope::ThisInstance); $this->blackoutsService->expects($this->once()) ->method('Delete') @@ -234,7 +234,7 @@ public function testLoadsBlackoutSeriesByBlackoutId() $this->page->expects($this->once()) ->method('GetBlackoutId') - ->will($this->returnValue($id)); + ->willReturn($id); $this->page->expects($this->once()) ->method('SetBlackoutResources') @@ -290,7 +290,7 @@ public function testLoadsBlackoutSeriesByBlackoutId() $this->blackoutsService->expects($this->once()) ->method('LoadBlackout') ->with($this->equalTo($id), $this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($series)); + ->willReturn($series); $this->presenter->LoadBlackout(); } @@ -324,15 +324,15 @@ public function testUpdatesBlackout() $resourceIds = [123, 456]; $this->page->expects($this->once()) ->method('GetBlackoutResourceIds') - ->will($this->returnValue($resourceIds)); + ->willReturn($resourceIds); $this->page->expects($this->once()) ->method('GetUpdateBlackoutId') - ->will($this->returnValue($blackoutInstanceId)); + ->willReturn($blackoutInstanceId); $this->page->expects($this->once()) ->method('GetSeriesUpdateScope') - ->will($this->returnValue($scope)); + ->willReturn($scope); $result = $this->createMock('IBlackoutValidationResult'); @@ -347,7 +347,7 @@ public function testUpdatesBlackout() $this->equalTo($repeatOptions), $this->equalTo($scope) ) - ->will($this->returnValue($result)); + ->willReturn($result); $this->presenter->UpdateBlackout(); } @@ -368,53 +368,53 @@ private function ExpectPageToReturnCommonBlackoutInfo($startDate, $startTime, $e { $this->page->expects($this->once()) ->method('GetBlackoutStartDate') - ->will($this->returnValue($startDate)); + ->willReturn($startDate); $this->page->expects($this->once()) ->method('GetBlackoutStartTime') - ->will($this->returnValue($startTime)); + ->willReturn($startTime); $this->page->expects($this->once()) ->method('GetBlackoutEndDate') - ->will($this->returnValue($endDate)); + ->willReturn($endDate); $this->page->expects($this->once()) ->method('GetBlackoutEndTime') - ->will($this->returnValue($endTime)); + ->willReturn($endTime); $this->page->expects($this->once()) ->method('GetBlackoutTitle') - ->will($this->returnValue($title)); + ->willReturn($title); $this->page->expects($this->once()) ->method('GetBlackoutConflictAction') - ->will($this->returnValue($conflictAction)); + ->willReturn($conflictAction); } private function ExpectPageToReturnRepeatInfo($repeatType = RepeatType::None, $repeatInterval = null, $endDateString = null, $repeatDays = null, $repeatMonthlyType = null) { $this->page->expects($this->any()) ->method('GetRepeatType') - ->will($this->returnValue($repeatType)); + ->willReturn($repeatType); $this->page->expects($this->any()) ->method('GetRepeatInterval') - ->will($this->returnValue($repeatInterval)); + ->willReturn($repeatInterval); $this->page->expects($this->any()) ->method('GetRepeatTerminationDate') - ->will($this->returnValue($endDateString)); + ->willReturn($endDateString); $this->page->expects($this->any()) ->method('GetRepeatWeekdays') - ->will($this->returnValue($repeatDays)); + ->willReturn($repeatDays); $this->page->expects($this->any()) ->method('GetRepeatMonthlyType') - ->will($this->returnValue($repeatMonthlyType)); + ->willReturn($repeatMonthlyType); $this->page->expects($this->once()) ->method('GetRepeatCustomDates') - ->will($this->returnValue([])); + ->willReturn([]); } } diff --git a/tests/Presenters/Admin/ManageConfigurationPresenterTest.php b/tests/Presenters/Admin/ManageConfigurationPresenterTest.php index 59ad8e6e7..a6a56a255 100644 --- a/tests/Presenters/Admin/ManageConfigurationPresenterTest.php +++ b/tests/Presenters/Admin/ManageConfigurationPresenterTest.php @@ -51,7 +51,7 @@ public function testDoesNothingIfCannotOverwriteFile() $this->configSettings->expects($this->once()) ->method('CanOverwriteFile') ->with($this->equalTo($this->configFilePath)) - ->will($this->returnValue(false)); + ->willReturn(false); $this->presenter->PageLoad(); @@ -63,14 +63,14 @@ public function testPopulatesPageFromExistingValues() $this->configSettings->expects($this->once()) ->method('CanOverwriteFile') ->with($this->equalTo($this->configFilePath)) - ->will($this->returnValue(true)); + ->willReturn(true); $configValues = $this->getDefaultConfigValues(); $this->configSettings->expects($this->once()) ->method('GetSettings') ->with($this->equalTo($this->configFilePath)) - ->will($this->returnValue($configValues)); + ->willReturn($configValues); $this->presenter->PageLoad(); @@ -115,7 +115,7 @@ public function testUpdatesConfigFileWithSettings() $this->configSettings->expects($this->once()) ->method('GetSettings') ->with($this->equalTo($this->configFilePath)) - ->will($this->returnValue($existingValues)); + ->willReturn($existingValues); $this->configSettings->expects($this->once()) ->method('WriteSettings') diff --git a/tests/Presenters/Admin/ManagePaymentsPresenterTest.php b/tests/Presenters/Admin/ManagePaymentsPresenterTest.php index df0825e8e..94dda26c7 100644 --- a/tests/Presenters/Admin/ManagePaymentsPresenterTest.php +++ b/tests/Presenters/Admin/ManagePaymentsPresenterTest.php @@ -33,8 +33,8 @@ public function testPageLoadSetsCurrentCreditValues() $this->presenter->PageLoad(); - $this->assertEquals($creditCost->Cost(), $this->page->_CreditCost); - $this->assertEquals($creditCost->Currency(), $this->page->_CreditCurrency); + $this->assertEquals($creditCost->Cost(), $this->page->_CreditCost->Cost()); + $this->assertEquals($creditCost->Currency(), $this->page->_CreditCost->Currency()); } public function testPageLoadSetsGatewayValues() @@ -64,7 +64,7 @@ public function testSettingCreditCost() $this->presenter->UpdateCreditCost(); - $this->assertEquals(new CreditCost($this->page->_CreditCost, $this->page->_CreditCurrency), $this->paymentRepository->_LastCost); + $this->assertEquals(new CreditCost(1, $this->page->_CreditCost, $this->page->_CreditCurrency), $this->paymentRepository->_LastCost); } public function testUpdatesPaymentGateways() @@ -170,7 +170,6 @@ private function GetTransactionLogView($amount = 10.6, $fee = .33, $gateway = 'P class FakeManagePaymentsPage extends ManagePaymentsPage { - public $_CreditCount; public $_CreditCost; public $_CreditCurrency; public $_PayPalEnabled; @@ -204,11 +203,9 @@ public function GetCreditCurrency() return $this->_CreditCurrency; } - public function SetCreditCost($count, $cost, $currency) + public function SetCreditCosts($cost) { - $this->_CreditCount = $count; $this->_CreditCost = $cost; - $this->_CreditCurrency = $currency; } public function GetPayPalIsEnabled() diff --git a/tests/Presenters/Admin/ManageQuotasPresenterTest.php b/tests/Presenters/Admin/ManageQuotasPresenterTest.php index b31773027..be4a10ac2 100644 --- a/tests/Presenters/Admin/ManageQuotasPresenterTest.php +++ b/tests/Presenters/Admin/ManageQuotasPresenterTest.php @@ -70,7 +70,7 @@ public function testWhenInitializing() $this->resourceRepository->expects($this->once()) ->method('GetResourceList') - ->will($this->returnValue($bookableResources)); + ->willReturn($bookableResources); $this->page->expects($this->once()) ->method('BindResources') @@ -78,7 +78,7 @@ public function testWhenInitializing() $this->groupRepository->expects($this->once()) ->method('GetList') - ->will($this->returnValue($groupResult)); + ->willReturn($groupResult); $this->page->expects($this->once()) ->method('BindGroups') @@ -86,7 +86,7 @@ public function testWhenInitializing() $this->scheduleRepository->expects($this->once()) ->method('GetAll') - ->will($this->returnValue($schedules)); + ->willReturn($schedules); $this->page->expects($this->once()) ->method('BindSchedules') @@ -94,7 +94,7 @@ public function testWhenInitializing() $this->quotaRepository->expects($this->once()) ->method('GetAll') - ->will($this->returnValue($quotaList)); + ->willReturn($quotaList); $this->presenter->PageLoad(); } @@ -114,51 +114,51 @@ public function testWhenAdding() $this->page->expects($this->atLeastOnce()) ->method('GetDuration') - ->will($this->returnValue($duration)); + ->willReturn($duration); $this->page->expects($this->atLeastOnce()) ->method('GetLimit') - ->will($this->returnValue($limit)); + ->willReturn($limit); $this->page->expects($this->atLeastOnce()) ->method('GetUnit') - ->will($this->returnValue($unit)); + ->willReturn($unit); $this->page->expects($this->atLeastOnce()) ->method('GetResourceId') - ->will($this->returnValue($resourceId)); + ->willReturn($resourceId); $this->page->expects($this->atLeastOnce()) ->method('GetGroupId') - ->will($this->returnValue($groupId)); + ->willReturn($groupId); $this->page->expects($this->atLeastOnce()) ->method('GetScheduleId') - ->will($this->returnValue($scheduleId)); + ->willReturn($scheduleId); $this->page->expects($this->atLeastOnce()) ->method('GetEnforcedAllDay') - ->will($this->returnValue(false)); + ->willReturn(false); $this->page->expects($this->atLeastOnce()) ->method('GetEnforcedStartTime') - ->will($this->returnValue($enforcedStartTime)); + ->willReturn($enforcedStartTime); $this->page->expects($this->atLeastOnce()) ->method('GetEnforcedEndTime') - ->will($this->returnValue($enforcedEndTime)); + ->willReturn($enforcedEndTime); $this->page->expects($this->atLeastOnce()) ->method('GetEnforcedEveryDay') - ->will($this->returnValue(false)); + ->willReturn(false); $this->page->expects($this->atLeastOnce()) ->method('GetEnforcedDays') - ->will($this->returnValue($enforcedDays)); + ->willReturn($enforcedDays); $this->page->expects($this->atLeastOnce()) ->method('GetScope') - ->will($this->returnValue($scope)); + ->willReturn($scope); $expectedQuota = Quota::Create($duration, $limit, $unit, $resourceId, $groupId, $scheduleId, $enforcedStartTime, $enforcedEndTime, $enforcedDays, $scope); diff --git a/tests/Presenters/Admin/ManageReservationsPresenterTest.php b/tests/Presenters/Admin/ManageReservationsPresenterTest.php index 28fe5f328..f3b39f9dd 100644 --- a/tests/Presenters/Admin/ManageReservationsPresenterTest.php +++ b/tests/Presenters/Admin/ManageReservationsPresenterTest.php @@ -69,7 +69,7 @@ public function setUp(): void $this->userRepository->expects($this->any()) ->method('LoadById') ->with($this->anything()) - ->will($this->returnValue(new FakeUser())); + ->willReturn(new FakeUser()); } public function testUsesTwoWeekSpanWhenNoDateFilterProvided() @@ -92,55 +92,55 @@ public function testUsesTwoWeekSpanWhenNoDateFilterProvided() $this->resourceRepository->expects($this->once()) ->method('GetStatusReasons') - ->will($this->returnValue([])); + ->willReturn([]); $this->page->expects($this->any()) ->method('FilterButtonPressed') - ->will($this->returnValue(true)); + ->willReturn(true); $this->page->expects($this->atLeastOnce()) ->method('GetStartDate') - ->will($this->returnValue(null)); + ->willReturn(null); $this->page->expects($this->atLeastOnce()) ->method('GetEndDate') - ->will($this->returnValue(null)); + ->willReturn(null); $this->page->expects($this->atLeastOnce()) ->method('GetScheduleId') - ->will($this->returnValue($searchedScheduleId)); + ->willReturn($searchedScheduleId); $this->page->expects($this->atLeastOnce()) ->method('GetResourceId') - ->will($this->returnValue($searchedResourceId)); + ->willReturn($searchedResourceId); $this->page->expects($this->atLeastOnce()) ->method('GetReservationStatusId') - ->will($this->returnValue($searchedStatusId)); + ->willReturn($searchedStatusId); $this->page->expects($this->atLeastOnce()) ->method('GetUserId') - ->will($this->returnValue($searchedUserId)); + ->willReturn($searchedUserId); $this->page->expects($this->atLeastOnce()) ->method('GetUserName') - ->will($this->returnValue($searchedUserName)); + ->willReturn($searchedUserName); $this->page->expects($this->atLeastOnce()) ->method('GetReferenceNumber') - ->will($this->returnValue($searchedReferenceNumber)); + ->willReturn($searchedReferenceNumber); $this->page->expects($this->atLeastOnce()) ->method('GetResourceStatusFilterId') - ->will($this->returnValue($searchedResourceStatusId)); + ->willReturn($searchedResourceStatusId); $this->page->expects($this->atLeastOnce()) ->method('GetResourceStatusReasonFilterId') - ->will($this->returnValue($searchedResourceStatusReasonId)); + ->willReturn($searchedResourceStatusReasonId); $this->page->expects($this->atLeastOnce()) ->method('GetAttributeFilters') - ->will($this->returnValue([new AttributeFormElement($customAttributes[0]->Id(), 'value')])); + ->willReturn([new AttributeFormElement($customAttributes[0]->Id(), 'value')]); $filter = $this->GetExpectedFilter( $defaultStart, @@ -166,12 +166,12 @@ public function testUsesTwoWeekSpanWhenNoDateFilterProvided() $this->equalTo($filter), $this->equalTo($this->fakeUser) ) - ->will($this->returnValue($data)); + ->willReturn($data); $this->attributeService->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo(CustomAttributeCategory::RESERVATION)) - ->will($this->returnValue($customAttributes)); + ->willReturn($customAttributes); $this->page->expects($this->once()) ->method('SetAttributeFilters') @@ -236,32 +236,32 @@ public function testUpdatesSingleResourceStatus() $this->page->expects($this->once()) ->method('CanUpdateResourceStatuses') - ->will($this->returnValue(true)); + ->willReturn(true); $this->page->expects($this->once()) ->method('GetResourceStatus') - ->will($this->returnValue($resourceStatusId)); + ->willReturn($resourceStatusId); $this->page->expects($this->once()) ->method('GetUpdateScope') - ->will($this->returnValue('')); + ->willReturn(''); $this->page->expects($this->once()) ->method('GetResourceStatusReason') - ->will($this->returnValue($resourceStatusReasonId)); + ->willReturn($resourceStatusReasonId); $this->page->expects($this->once()) ->method('GetUpdateResourceId') - ->will($this->returnValue($resourceId)); + ->willReturn($resourceId); $this->page->expects($this->once()) ->method('GetResourceStatusReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->resourceRepository->expects($this->once()) ->method('LoadById') ->with($resourceId) - ->will($this->returnValue($resource)); + ->willReturn($resource); $this->resourceRepository->expects($this->once()) ->method('Update') @@ -290,23 +290,23 @@ public function testUpdatesReservationResourceStatuses() $this->page->expects($this->once()) ->method('CanUpdateResourceStatuses') - ->will($this->returnValue(true)); + ->willReturn(true); $this->page->expects($this->once()) ->method('GetResourceStatus') - ->will($this->returnValue($resourceStatusId)); + ->willReturn($resourceStatusId); $this->page->expects($this->once()) ->method('GetUpdateScope') - ->will($this->returnValue('all')); + ->willReturn('all'); $this->page->expects($this->once()) ->method('GetResourceStatusReason') - ->will($this->returnValue($resourceStatusReasonId)); + ->willReturn($resourceStatusReasonId); $this->page->expects($this->once()) ->method('GetResourceStatusReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->reservationsService->expects($this->once()) ->method('LoadFiltered') @@ -318,23 +318,17 @@ public function testUpdatesReservationResourceStatuses() $this->equalTo(new ReservationFilter(null, null, $referenceNumber, null, null, null, null, null)), $this->equalTo($this->fakeUser) ) - ->will($this->returnValue($pageableReservations)); + ->willReturn($pageableReservations); - $this->resourceRepository->expects($this->at(0)) + $this->resourceRepository->expects($this->exactly(2)) ->method('LoadById') - ->with(1) - ->will($this->returnValue($resource1)); + ->willReturnMap( + [ + [1, $resource1], + [2, $resource2] + ]); - $this->resourceRepository->expects($this->at(2)) - ->method('LoadById') - ->with(2) - ->will($this->returnValue($resource2)); - - $this->resourceRepository->expects($this->at(1)) - ->method('Update') - ->with($this->anything()); - - $this->resourceRepository->expects($this->at(3)) + $this->resourceRepository->expects($this->exactly(2)) ->method('Update') ->with($this->anything()); @@ -352,12 +346,12 @@ public function testLoadsReservation() $this->page->expects($this->once()) ->method('GetReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->reservationsService->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber), $this->equalTo($this->fakeUser)) - ->will($this->returnValue($reservationView)); + ->willReturn($reservationView); $this->page->expects($this->once()) ->method('SetReservationJson') @@ -374,20 +368,20 @@ public function testUpdatesReservationAttribute() $this->page->expects($this->once()) ->method('GetReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->page->expects($this->once()) ->method('GetName') - ->will($this->returnValue($attrId)); + ->willReturn($attrId); $this->page->expects($this->once()) ->method('GetValue') - ->will($this->returnValue($attrValue)); + ->willReturn($attrValue); $this->reservationsService->expects($this->once()) ->method('UpdateAttribute') ->with($this->equalTo($referenceNumber), $this->equalTo($attrId), $this->equalTo($attrValue), $this->equalTo($this->fakeUser)) - ->will($this->returnValue([])); + ->willReturn([]); $this->presenter->UpdateAttribute(); } @@ -420,28 +414,32 @@ public function testImportsReservations() $this->page->expects($this->once()) ->method('GetImportFile') - ->will($this->returnValue($importFile)); + ->willReturn($importFile); $this->attributeService->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo(CustomAttributeCategory::RESERVATION)) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $this->resourceRepository->expects($this->once()) ->method('GetResourceList') - ->will($this->returnValue($resources)); + ->willReturn($resources); $this->userRepository->expects($this->once()) ->method('GetAll') - ->will($this->returnValue($users)); + ->willReturn($users); - $this->reservationsService->expects($this->at(0)) + $matcher = $this->exactly(2); + $this->reservationsService->expects($matcher) ->method('UnsafeAdd') - ->with($this->equalTo($res1)); - - $this->reservationsService->expects($this->at(1)) - ->method('UnsafeAdd') - ->with($this->equalTo($res2)); + ->willReturnCallback(function ($res) use ($matcher, $res1, $res2) + { + match ($matcher->numberOfInvocations()) + { + 1 => $this->assertEquals($res, $res1), + 2 => $this->assertEquals($res, $res2) + }; + }); $this->page->expects($this->once()) ->method('SetImportResult') @@ -456,15 +454,20 @@ public function testDeletesMultiple() $this->page->expects($this->once()) ->method('GetDeletedReservationIds') - ->will($this->returnValue($ids)); - - $this->reservationsService->expects($this->at(0)) - ->method('UnsafeDelete') - ->with($this->equalTo(1), $this->equalTo($this->fakeUser)); + ->willReturn($ids); - $this->reservationsService->expects($this->at(1)) + $matcher = $this->exactly(2); + $this->reservationsService->expects($matcher) ->method('UnsafeDelete') - ->with($this->equalTo(2), $this->equalTo($this->fakeUser)); + ->willReturnCallback(function(int $id, UserSession $session) use ($matcher) + { + $this->assertEquals($this->fakeUser, $session); + match ($matcher->numberOfInvocations()) + { + 1 => $this->assertEquals(1, $id), + 2 => $this->assertEquals(2, $id) + }; + }); $this->presenter->DeleteMultiple(); } diff --git a/tests/Presenters/Admin/ManageResourceGroupsPresenterTest.php b/tests/Presenters/Admin/ManageResourceGroupsPresenterTest.php index 12f9fcd68..e8aed1650 100644 --- a/tests/Presenters/Admin/ManageResourceGroupsPresenterTest.php +++ b/tests/Presenters/Admin/ManageResourceGroupsPresenterTest.php @@ -38,12 +38,12 @@ public function testBindsResourcesAndGroupsOnLoad() $this->resourceRepository ->expects($this->once()) ->method('GetResourceGroups') - ->will($this->returnValue($groupTree)); + ->willReturn($groupTree); $this->resourceRepository ->expects($this->once()) ->method('GetResourceList') - ->will($this->returnValue($resources)); + ->willReturn($resources); $this->page ->expects($this->atLeastOnce()) @@ -66,12 +66,12 @@ public function testAddsResourceToGroup() $this->page ->expects($this->atLeastOnce()) ->method('GetResourceId') - ->will($this->returnValue($resourceId)); + ->willReturn($resourceId); $this->page ->expects($this->atLeastOnce()) ->method('GetGroupId') - ->will($this->returnValue($groupId)); + ->willReturn($groupId); $this->resourceRepository ->expects($this->once()) @@ -89,12 +89,12 @@ public function testRemovesResourceFromGroup() $this->page ->expects($this->atLeastOnce()) ->method('GetResourceId') - ->will($this->returnValue($resourceId)); + ->willReturn($resourceId); $this->page ->expects($this->atLeastOnce()) ->method('GetGroupId') - ->will($this->returnValue($groupId)); + ->willReturn($groupId); $this->resourceRepository ->expects($this->once()) @@ -117,28 +117,28 @@ public function testMovesGroupNode() $this->page ->expects($this->atLeastOnce()) ->method('GetNodeId') - ->will($this->returnValue($nodeId)); + ->willReturn($nodeId); $this->page ->expects($this->atLeastOnce()) ->method('GetTargetNodeId') - ->will($this->returnValue($targetId)); + ->willReturn($targetId); $this->page ->expects($this->atLeastOnce()) ->method('GetNodeType') - ->will($this->returnValue($nodeType)); + ->willReturn($nodeType); $this->page ->expects($this->atLeastOnce()) ->method('GetPreviousNodeId') - ->will($this->returnValue($previousNodeId)); + ->willReturn($previousNodeId); $this->resourceRepository ->expects($this->once()) ->method('LoadResourceGroup') ->with($this->equalTo($nodeId)) - ->will($this->returnValue($group)); + ->willReturn($group); $this->resourceRepository ->expects($this->once()) diff --git a/tests/Presenters/Admin/ManageResourceTypesPresenterTest.php b/tests/Presenters/Admin/ManageResourceTypesPresenterTest.php index 881a0f0c7..79e07b4ce 100644 --- a/tests/Presenters/Admin/ManageResourceTypesPresenterTest.php +++ b/tests/Presenters/Admin/ManageResourceTypesPresenterTest.php @@ -44,13 +44,13 @@ public function testBindsResourceTypes() $this->resourceRepository ->expects($this->once()) ->method('GetResourceTypes') - ->will($this->returnValue($types)); + ->willReturn($types); $this->attributeService ->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo(CustomAttributeCategory::RESOURCE_TYPE)) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $this->page ->expects($this->once()) @@ -71,11 +71,11 @@ public function testAddsNewResourceType() $description = 'description'; $this->page->expects($this->once()) ->method('GetResourceTypeName') - ->will($this->returnValue($name)); + ->willReturn($name); $this->page->expects($this->once()) ->method('GetDescription') - ->will($this->returnValue($description)); + ->willReturn($description); $type = ResourceType::CreateNew($name, $description); @@ -98,23 +98,23 @@ public function testUpdatesResourceType() $this->page ->expects($this->once()) ->method('GetId') - ->will($this->returnValue($id)); + ->willReturn($id); $this->page ->expects($this->once()) ->method('GetResourceTypeName') - ->will($this->returnValue($id)); + ->willReturn($id); $this->page ->expects($this->once()) ->method('GetDescription') - ->will($this->returnValue($id)); + ->willReturn($id); $this->resourceRepository ->expects($this->once()) ->method('LoadResourceType') ->with($this->equalTo($id)) - ->will($this->returnValue($resourceType)); + ->willReturn($resourceType); $this->resourceRepository ->expects($this->once()) @@ -131,7 +131,7 @@ public function testDeletesResourceType() $this->page ->expects($this->once()) ->method('GetId') - ->will($this->returnValue($id)); + ->willReturn($id); $this->resourceRepository ->expects($this->once()) diff --git a/tests/Presenters/Admin/ManageSchedulesPresenterTest.php b/tests/Presenters/Admin/ManageSchedulesPresenterTest.php index 8276b0cea..c1c490715 100644 --- a/tests/Presenters/Admin/ManageSchedulesPresenterTest.php +++ b/tests/Presenters/Admin/ManageSchedulesPresenterTest.php @@ -58,23 +58,23 @@ public function testLayoutIsParsedFromPage() $this->page->expects($this->once()) ->method('GetScheduleId') - ->will($this->returnValue($scheduleId)); + ->willReturn($scheduleId); $this->page->expects($this->once()) ->method('GetLayoutTimezone') - ->will($this->returnValue($timezone)); + ->willReturn($timezone); $this->page->expects($this->once()) ->method('GetUsingSingleLayout') - ->will($this->returnValue(true)); + ->willReturn(true); $this->page->expects($this->once()) ->method('GetReservableSlots') - ->will($this->returnValue($reservableSlots)); + ->willReturn($reservableSlots); $this->page->expects($this->once()) ->method('GetBlockedSlots') - ->will($this->returnValue($blockedSlots)); + ->willReturn($blockedSlots); $this->scheduleRepo->expects($this->once()) ->method('AddScheduleLayout') @@ -100,23 +100,23 @@ public function testDailyLayoutIsParsedFromPage() $this->page->expects($this->once()) ->method('GetScheduleId') - ->will($this->returnValue($scheduleId)); + ->willReturn($scheduleId); $this->page->expects($this->once()) ->method('GetLayoutTimezone') - ->will($this->returnValue($timezone)); + ->willReturn($timezone); $this->page->expects($this->once()) ->method('GetUsingSingleLayout') - ->will($this->returnValue(false)); + ->willReturn(false); $this->page->expects($this->once()) ->method('GetDailyReservableSlots') - ->will($this->returnValue($reservableSlots)); + ->willReturn($reservableSlots); $this->page->expects($this->once()) ->method('GetDailyBlockedSlots') - ->will($this->returnValue($blockedSlots)); + ->willReturn($blockedSlots); $this->scheduleRepo->expects($this->once()) ->method('AddScheduleLayout') @@ -137,19 +137,19 @@ public function testNewScheduleIsAdded() $this->page->expects($this->once()) ->method('GetSourceScheduleId') - ->will($this->returnValue($sourceScheduleId)); + ->willReturn($sourceScheduleId); $this->page->expects($this->once()) ->method('GetScheduleName') - ->will($this->returnValue($name)); + ->willReturn($name); $this->page->expects($this->once()) ->method('GetStartDay') - ->will($this->returnValue($startDay)); + ->willReturn($startDay); $this->page->expects($this->once()) ->method('GetDaysVisible') - ->will($this->returnValue($daysVisible)); + ->willReturn($daysVisible); $this->scheduleRepo->expects($this->once()) ->method('Add') @@ -175,16 +175,16 @@ public function testDeletesSchedule() $this->page->expects($this->once()) ->method('GetScheduleId') - ->will($this->returnValue($scheduleId)); + ->willReturn($scheduleId); $this->page->expects($this->once()) ->method('GetTargetScheduleId') - ->will($this->returnValue($targetId)); + ->willReturn($targetId); $this->scheduleRepo->expects($this->once()) ->method('LoadById') ->with($this->equalTo($scheduleId)) - ->will($this->returnValue($schedule)); + ->willReturn($schedule); $this->scheduleRepo->expects($this->once()) ->method('Delete') @@ -193,15 +193,19 @@ public function testDeletesSchedule() $this->resourceRepo->expects($this->once()) ->method('GetScheduleResources') ->with($this->equalTo($scheduleId)) - ->will($this->returnValue($resources)); + ->willReturn($resources); - $this->resourceRepo->expects($this->at(1)) + $matcher = $this->exactly(2); + $this->resourceRepo->expects($matcher) ->method('Update') - ->with($this->equalTo($resource1)); - - $this->resourceRepo->expects($this->at(2)) - ->method('Update') - ->with($this->equalTo($resource2)); + ->willReturnCallback(function ($resource) use ($matcher, $resource1, $resource2) + { + match ($matcher->numberOfInvocations()) + { + 1 => $this->assertEquals($resource, $resource1), + 2 => $this->assertEquals($resource, $resource2) + }; + }); $presenter = new ManageSchedulesPresenter($this->page, $this->service, $this->groupRepo); diff --git a/tests/Presenters/Admin/ManageUsersPresenterTest.php b/tests/Presenters/Admin/ManageUsersPresenterTest.php index e16a4dc0a..b2d593aa4 100644 --- a/tests/Presenters/Admin/ManageUsersPresenterTest.php +++ b/tests/Presenters/Admin/ManageUsersPresenterTest.php @@ -113,7 +113,7 @@ public function testBindsUsersAndAttributesAndGroups() $this->groupViewRepository ->expects($this->once()) ->method('GetList') - ->will($this->returnValue($groupList)); + ->willReturn($groupList); $this->presenter->PageLoad(); @@ -178,12 +178,12 @@ public function testResetPasswordEncryptsAndUpdates() $this->encryption->expects($this->once()) ->method('Salt') - ->will($this->returnValue($salt)); + ->willReturn($salt); $this->encryption->expects($this->once()) ->method('Encrypt') ->with($this->equalTo($password), $this->equalTo($salt)) - ->will($this->returnValue($encrypted)); + ->willReturn($encrypted); $user = new User(); @@ -241,7 +241,7 @@ public function testCanUpdateUser() $this->equalTo($extraAttributes), $this->equalTo([new AttributeValue($attributeId, $attributeValue)]) ) - ->will($this->returnValue($user)); + ->willReturn($user); $this->presenter->UpdateUser(); } @@ -263,13 +263,17 @@ public function testDeletesUsers() $userIds = [809, 909]; $this->page->_DeletedUserIds = $userIds; - $this->manageUsersService->expects($this->at(0)) + $matcher = $this->exactly(2); + $this->manageUsersService->expects($matcher) ->method('DeleteUser') - ->with($this->equalTo(809)); - - $this->manageUsersService->expects($this->at(1)) - ->method('DeleteUser') - ->with($this->equalTo(909)); + ->willReturnCallback(function ($userId) use ($matcher) + { + match ($matcher->numberOfInvocations()) + { + 1 => $this->assertEquals(809, $userId), + 2 => $this->assertEquals(909, $userId) + }; + }); $this->presenter->DeleteMultipleUsers(); } @@ -324,12 +328,12 @@ public function testAddsUser() UserAttribute::Position => null]), $this->equalTo([new AttributeValue($attributeId, $attributeValue)]) ) - ->will($this->returnValue($user)); + ->willReturn($user); $this->groupRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($groupId)) - ->will($this->returnValue($group)); + ->willReturn($group); $this->groupRepository->expects($this->once()) ->method('Update') diff --git a/tests/Presenters/CalendarExportPresenterTest.php b/tests/Presenters/CalendarExportPresenterTest.php index 4f6f2fc20..245d5dfdf 100644 --- a/tests/Presenters/CalendarExportPresenterTest.php +++ b/tests/Presenters/CalendarExportPresenterTest.php @@ -49,16 +49,16 @@ public function testLoadsReservationByReferenceNumber() $this->validator->expects($this->atLeastOnce()) ->method('IsValid') - ->will($this->returnValue(true)); + ->willReturn(true); $this->page->expects($this->once()) ->method('GetReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->repo->expects($this->once()) ->method('GetReservationForEditing') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($reservationResult)); + ->willReturn($reservationResult); $this->page->expects($this->once()) ->method('SetReservations') @@ -74,16 +74,16 @@ public function testCannotSeeReservationDetailsIfConfiguredOff() $this->validator->expects($this->atLeastOnce()) ->method('IsValid') - ->will($this->returnValue(true)); + ->willReturn(true); $this->page->expects($this->once()) ->method('GetReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->repo->expects($this->once()) ->method('GetReservationForEditing') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($reservationResult)); + ->willReturn($reservationResult); $this->page->expects($this->once()) ->method('SetReservations') diff --git a/tests/Presenters/CalendarPresenterTest.php b/tests/Presenters/CalendarPresenterTest.php index 95472a73f..840dac9b8 100644 --- a/tests/Presenters/CalendarPresenterTest.php +++ b/tests/Presenters/CalendarPresenterTest.php @@ -109,35 +109,35 @@ public function testBindsDefaultScheduleByMonthWhenNothingSelected() $this->scheduleRepository ->expects($this->atLeastOnce()) ->method('GetAll') - ->will($this->returnValue($schedules)); + ->willReturn($schedules); $this->resourceService ->expects($this->atLeastOnce()) ->method('GetAllResources') ->with($this->equalTo($showInaccessible), $this->equalTo($this->fakeUser)) - ->will($this->returnValue($resources)); + ->willReturn($resources); $this->resourceService ->expects($this->atLeastOnce()) ->method('GetResourceGroups') ->with($this->isNull(), $this->equalTo($this->fakeUser)) - ->will($this->returnValue(new ResourceGroupTree())); + ->willReturn(new ResourceGroupTree()); $this->page ->expects($this->atLeastOnce()) ->method('GetScheduleId') - ->will($this->returnValue($defaultScheduleId)); + ->willReturn($defaultScheduleId); $this->page ->expects($this->atLeastOnce()) ->method('GetResourceId') - ->will($this->returnValue(null)); + ->willReturn(null); $this->page ->expects($this->atLeastOnce()) ->method('GetCalendarType') - ->will($this->returnValue($calendarType)); + ->willReturn($calendarType); $this->page ->expects($this->atLeastOnce()) @@ -145,7 +145,7 @@ public function testBindsDefaultScheduleByMonthWhenNothingSelected() ->with($this->equalTo($schedules[1]->GetWeekdayStart())); $details = new CalendarSubscriptionDetails(true); - $this->subscriptionService->expects($this->once())->method('ForSchedule')->with($this->equalTo($defaultScheduleId))->will($this->returnValue($details)); + $this->subscriptionService->expects($this->once())->method('ForSchedule')->with($this->equalTo($defaultScheduleId))->willReturn($details); $this->page->expects($this->atLeastOnce())->method('BindSubscription')->with($this->equalTo($details)); @@ -213,31 +213,31 @@ public function testBindsReservationsAndBlackoutsAndAvailableSlots() $this->page ->expects($this->atLeastOnce()) ->method('GetResourceId') - ->will($this->returnValue($resourceId)); + ->willReturn($resourceId); $this->page ->expects($this->atLeastOnce()) ->method('GetScheduleId') - ->will($this->returnValue($scheduleId)); + ->willReturn($scheduleId); $this->resourceService ->expects($this->atLeastOnce()) ->method('GetAllResources') - ->will($this->returnValue($resources)); + ->willReturn($resources); $this->resourceService ->expects($this->atLeastOnce()) ->method('GetResource') - ->will($this->returnValue(new FakeBookableResource(1))); + ->willReturn(new FakeBookableResource(1)); $this->repository ->expects($this->atLeastOnce()) ->method('GetReservations') - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $this->repository ->expects($this->atLeastOnce()) ->method('GetBlackoutsWithin') - ->will($this->returnValue($blackouts)); + ->willReturn($blackouts); $this->scheduleRepository ->expects($this->atLeastOnce()) ->method('GetLayout') - ->will($this->returnValue($layout)); + ->willReturn($layout); $this->presenter->ProcessDataRequest('events'); } diff --git a/tests/Presenters/CalendarSubscriptionPresenterTest.php b/tests/Presenters/CalendarSubscriptionPresenterTest.php index 31318d9fa..c37aff93d 100644 --- a/tests/Presenters/CalendarSubscriptionPresenterTest.php +++ b/tests/Presenters/CalendarSubscriptionPresenterTest.php @@ -47,7 +47,7 @@ public function setUp(): void $this->validator->expects($this->atLeastOnce()) ->method('IsValid') - ->will($this->returnValue(true)); + ->willReturn(true); $this->presenter = new CalendarSubscriptionPresenter( $this->page, @@ -74,12 +74,12 @@ public function testGetsScheduleReservationsForTheNextYearByScheduleId() $this->service->expects($this->once()) ->method('GetSchedule') ->with($this->equalTo($publicId)) - ->will($this->returnValue($schedule)); + ->willReturn($schedule); $this->repo->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($weekAgo), $this->equalTo($nextYear), $this->isNull(), ReservationUserLevel::OWNER, $scheduleId, $this->isNull()) - ->will($this->returnValue($reservationResult)); + ->willReturn($reservationResult); $this->presenter->PageLoad(); @@ -102,12 +102,12 @@ public function testGetsScheduleReservationsForTheNextYearByResourceId() $this->service->expects($this->once()) ->method('GetResource') ->with($this->equalTo($publicId)) - ->will($this->returnValue($resource)); + ->willReturn($resource); $this->repo->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($weekAgo), $this->equalTo($nextYear), $this->isNull(), ReservationUserLevel::OWNER, $this->isNull(), $resourceId) - ->will($this->returnValue($reservationResult)); + ->willReturn($reservationResult); $this->presenter->PageLoad(); @@ -130,12 +130,12 @@ public function testGetsUserReservationsForTheNextYearByResourceId() $this->service->expects($this->once()) ->method('GetUser') ->with($this->equalTo($publicId)) - ->will($this->returnValue($user)); + ->willReturn($user); $this->repo->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($weekAgo), $this->equalTo($nextYear), $this->equalTo($userId), ReservationUserLevel::ALL, $this->isNull(), $this->isNull()) - ->will($this->returnValue($reservationResult)); + ->willReturn($reservationResult); $this->presenter->PageLoad(); @@ -160,12 +160,12 @@ public function testGetsResourceGroupReservationsForTheNextYearByGroupId() $this->service->expects($this->once()) ->method('GetResourcesInGroup') ->with($this->equalTo($publicId)) - ->will($this->returnValue($resourceIds)); + ->willReturn($resourceIds); $this->repo->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($weekAgo), $this->equalTo($nextYear), $this->isNull(), ReservationUserLevel::OWNER, $this->isNull(), $this->isNull()) - ->will($this->returnValue($reservationResult)); + ->willReturn($reservationResult); $this->presenter->PageLoad(); diff --git a/tests/Presenters/CalendarSubscriptionValidatorTest.php b/tests/Presenters/CalendarSubscriptionValidatorTest.php index f4b8db70f..25501f3fa 100644 --- a/tests/Presenters/CalendarSubscriptionValidatorTest.php +++ b/tests/Presenters/CalendarSubscriptionValidatorTest.php @@ -38,12 +38,12 @@ public function testIsNotValidWhenTurnedOffForResource() $this->page->expects($this->once()) ->method('GetResourceId') - ->will($this->returnValue($publicId)); + ->willReturn($publicId); $this->subscriptionService->expects($this->once()) ->method('GetResource') ->with($this->equalTo($publicId)) - ->will($this->returnValue($resource)); + ->willReturn($resource); $this->StubSubscriptionKey(); @@ -61,12 +61,12 @@ public function testIsNotValidWhenTurnedOffForSchedule() $this->page->expects($this->once()) ->method('GetScheduleId') - ->will($this->returnValue($publicId)); + ->willReturn($publicId); $this->subscriptionService->expects($this->once()) ->method('GetSchedule') ->with($this->equalTo($publicId)) - ->will($this->returnValue($schedule)); + ->willReturn($schedule); $this->StubSubscriptionKey(); @@ -84,12 +84,12 @@ public function testIsNotValidWhenTurnedOffForUser() $this->page->expects($this->once()) ->method('GetUserId') - ->will($this->returnValue($publicId)); + ->willReturn($publicId); $this->subscriptionService->expects($this->once()) ->method('GetUser') ->with($this->equalTo($publicId)) - ->will($this->returnValue($user)); + ->willReturn($user); $this->StubSubscriptionKey(); @@ -102,7 +102,7 @@ public function testIsNotValidWhenSubscriptionKeyDoesNotMatch() { $this->page->expects($this->once()) ->method('GetSubscriptionKey') - ->will($this->returnValue('12')); + ->willReturn('12'); $this->fakeConfig->SetSectionKey(ConfigSection::ICS, ConfigKeys::ICS_SUBSCRIPTION_KEY, '123'); @@ -124,7 +124,7 @@ private function StubSubscriptionKey() { $this->page->expects($this->once()) ->method('GetSubscriptionKey') - ->will($this->returnValue('123')); + ->willReturn('123'); $this->fakeConfig->SetSectionKey(ConfigSection::ICS, ConfigKeys::ICS_SUBSCRIPTION_KEY, '123'); } diff --git a/tests/Presenters/CheckoutPresenterTest.php b/tests/Presenters/CheckoutPresenterTest.php index 3b02934f8..d88e6e30c 100644 --- a/tests/Presenters/CheckoutPresenterTest.php +++ b/tests/Presenters/CheckoutPresenterTest.php @@ -39,8 +39,9 @@ public function setUp(): void public function testPageLoadCreatesCartAndPresentsPaymentOptions() { $this->page->_CreditQuantity = 10; - $cost = new CreditCost(5); - $this->paymentRepository->_CreditCost = $cost; + $this->page->_CreditCount = 1; + $cost = new CreditCost(1, 5); + $this->paymentRepository->_CreditCost = [$cost]; $this->paymentRepository->_PayPal = new PayPalGateway(true, 'client', 'secret', 'live'); $this->paymentRepository->_Stripe = new StripeGateway(true, 'publish', 'secret'); diff --git a/tests/Presenters/Dashboard/UpcomingReservationsPresenterTest.php b/tests/Presenters/Dashboard/UpcomingReservationsPresenterTest.php index 4f6e90dc4..3b4a32fab 100644 --- a/tests/Presenters/Dashboard/UpcomingReservationsPresenterTest.php +++ b/tests/Presenters/Dashboard/UpcomingReservationsPresenterTest.php @@ -48,7 +48,7 @@ public function testGetsUpToTwoWeeksWorthOfReservationsThatCurrentUserScheduled( $this->repository->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($startDate), $this->equalTo($endDate), $this->equalTo($userId), $this->equalTo(ReservationUserLevel::ALL)) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $this->control->expects($this->once()) ->method('SetTimezone') @@ -95,7 +95,7 @@ public function testGroupsReservations() $this->repository->expects($this->once()) ->method('GetReservations') ->with($this->anything(), $this->anything(), $this->anything()) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $this->control->expects($this->once()) ->method('BindToday') diff --git a/tests/Presenters/LoginPresenterTest.php b/tests/Presenters/LoginPresenterTest.php index 809e926fa..57545020e 100644 --- a/tests/Presenters/LoginPresenterTest.php +++ b/tests/Presenters/LoginPresenterTest.php @@ -201,7 +201,7 @@ public function testLoadsAnnouncements() } } -abstract class FakeLoginPage extends FakePageBase implements ILoginPage +class FakeLoginPage extends FakePageBase implements ILoginPage { public $_EmailAddress; public $_Password; @@ -223,6 +223,12 @@ abstract class FakeLoginPage extends FakePageBase implements ILoginPage public $_ShowScheduleLink = false; public $_Announcements; + public function SetGoogleUrl($URL) { } + + public function SetMicrosoftUrl($URL) { } + + public function SetFacebookUrl($URL) { } + public function PageLoad() { $this->_PageLoadWasCalled = true; diff --git a/tests/Presenters/ParticipationPresenterTest.php b/tests/Presenters/ParticipationPresenterTest.php index d75b32aad..9668dcf5a 100644 --- a/tests/Presenters/ParticipationPresenterTest.php +++ b/tests/Presenters/ParticipationPresenterTest.php @@ -85,24 +85,24 @@ public function testWhenUserAcceptsInviteAndThereIsNotSpace() $this->page->expects($this->once()) ->method('GetResponseType') - ->will($this->returnValue('json')); + ->willReturn('json'); $this->page->expects($this->once()) ->method('GetInvitationAction') - ->will($this->returnValue($invitationAction)); + ->willReturn($invitationAction); $this->page->expects($this->once()) ->method('GetInvitationReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->page->expects($this->once()) ->method('GetUserId') - ->will($this->returnValue($currentUserId)); + ->willReturn($currentUserId); $this->reservationRepo->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($series)); + ->willReturn($series); $this->page->expects($this->once()) ->method('DisplayResult') @@ -140,24 +140,24 @@ public function testWhenUserJoinsAndThereIsNotSpace() $this->page->expects($this->once()) ->method('GetResponseType') - ->will($this->returnValue('json')); + ->willReturn('json'); $this->page->expects($this->once()) ->method('GetInvitationAction') - ->will($this->returnValue($invitationAction)); + ->willReturn($invitationAction); $this->page->expects($this->once()) ->method('GetInvitationReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->page->expects($this->once()) ->method('GetUserId') - ->will($this->returnValue($currentUserId)); + ->willReturn($currentUserId); $this->reservationRepo->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($series)); + ->willReturn($series); $this->page->expects($this->once()) ->method('DisplayResult') @@ -197,24 +197,24 @@ public function testWhenUserJoinsAllAndThereIsNotSpace() $this->page->expects($this->once()) ->method('GetResponseType') - ->will($this->returnValue('json')); + ->willReturn('json'); $this->page->expects($this->once()) ->method('GetInvitationAction') - ->will($this->returnValue($invitationAction)); + ->willReturn($invitationAction); $this->page->expects($this->once()) ->method('GetInvitationReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->page->expects($this->once()) ->method('GetUserId') - ->will($this->returnValue($currentUserId)); + ->willReturn($currentUserId); $this->reservationRepo->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($series)); + ->willReturn($series); $this->page->expects($this->once()) ->method('DisplayResult') @@ -263,7 +263,7 @@ public function testWhenViewingOpenInvites() $this->reservationViewRepo->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($startDate), $this->equalTo($endDate), $this->equalTo($userId), $this->equalTo($inviteeLevel)) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $this->page->expects($this->once()) ->method('BindReservations') @@ -287,24 +287,24 @@ public function testWhenReservationStartConstraintIsViolated() $this->page->expects($this->once()) ->method('GetResponseType') - ->will($this->returnValue('json')); + ->willReturn('json'); $this->page->expects($this->once()) ->method('GetInvitationAction') - ->will($this->returnValue(InvitationAction::Join)); + ->willReturn(InvitationAction::Join); $this->page->expects($this->once()) ->method('GetInvitationReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->page->expects($this->once()) ->method('GetUserId') - ->will($this->returnValue($currentUserId)); + ->willReturn($currentUserId); $this->reservationRepo->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($series)); + ->willReturn($series); $this->page->expects($this->once()) ->method('DisplayResult') @@ -321,29 +321,29 @@ private function assertUpdatesSeriesParticipation($invitationAction, $seriesMeth $currentUserId = 1029; $referenceNumber = 'abc123'; $series = $this->createMock('ExistingReservationSeries'); - $series->expects($this->any())->method('GetAllowParticipation')->will($this->returnValue(true)); - $series->expects($this->any())->method('AllResources')->will($this->returnValue([])); + $series->expects($this->any())->method('GetAllowParticipation')->willReturn(true); + $series->expects($this->any())->method('AllResources')->willReturn([]); $this->page->expects($this->once()) ->method('GetResponseType') - ->will($this->returnValue('json')); + ->willReturn('json'); $this->page->expects($this->once()) ->method('GetInvitationAction') - ->will($this->returnValue($invitationAction)); + ->willReturn($invitationAction); $this->page->expects($this->once()) ->method('GetInvitationReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->page->expects($this->once()) ->method('GetUserId') - ->will($this->returnValue($currentUserId)); + ->willReturn($currentUserId); $this->reservationRepo->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($series)); + ->willReturn($series); $series->expects($this->once()) ->method($seriesMethod) diff --git a/tests/Presenters/PasswordPresenterTest.php b/tests/Presenters/PasswordPresenterTest.php index 3fff37688..0b0f750db 100644 --- a/tests/Presenters/PasswordPresenterTest.php +++ b/tests/Presenters/PasswordPresenterTest.php @@ -22,25 +22,25 @@ public function testResetsPassword() $page->expects($this->once()) ->method('ResettingPassword') - ->will($this->returnValue(true)); + ->willReturn(true); $page->expects($this->once()) ->method('IsValid') - ->will($this->returnValue(true)); + ->willReturn(true); $page->expects($this->atLeastOnce()) ->method('GetPassword') - ->will($this->returnValue($newPassword)); + ->willReturn($newPassword); $userRepo->expects($this->atLeastOnce()) ->method('LoadById') ->with($this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($user)); + ->willReturn($user); $encryption->expects($this->once()) ->method('EncryptPassword') ->with($this->equalTo($newPassword)) - ->will($this->returnValue($encryptedPassword)); + ->willReturn($encryptedPassword); $user->expects($this->once()) ->method('ChangePassword') @@ -52,7 +52,7 @@ public function testResetsPassword() $page->expects($this->once()) ->method('ShowResetPasswordSuccess') - ->will($this->returnValue(true)); + ->willReturn(true); $presenter->PageLoad(); } diff --git a/tests/Presenters/PersonalCalendarPresenterTest.php b/tests/Presenters/PersonalCalendarPresenterTest.php index dc3252968..98e51d439 100644 --- a/tests/Presenters/PersonalCalendarPresenterTest.php +++ b/tests/Presenters/PersonalCalendarPresenterTest.php @@ -94,23 +94,23 @@ public function testBindsEmptyCalendarToPageWhenNoReservationsAreFound() $this->page ->expects($this->atLeastOnce()) ->method('GetScheduleId') - ->will($this->returnValue($defaultScheduleId)); + ->willReturn($defaultScheduleId); $this->page ->expects($this->atLeastOnce()) ->method('GetResourceId') - ->will($this->returnValue(null)); + ->willReturn(null); $this->page->expects($this->once()) ->method('GetCalendarType') - ->will($this->returnValue($calendarType)); + ->willReturn($calendarType); $details = new CalendarSubscriptionDetails(true); $this->subscriptionService->expects($this->once()) ->method('ForUser') ->with($this->equalTo($userId)) - ->will($this->returnValue($details)); + ->willReturn($details); $this->page->expects($this->once()) ->method('BindSubscription') @@ -119,19 +119,19 @@ public function testBindsEmptyCalendarToPageWhenNoReservationsAreFound() $this->scheduleRepository ->expects($this->atLeastOnce()) ->method('GetAll') - ->will($this->returnValue($schedules)); + ->willReturn($schedules); $this->resourceService ->expects($this->atLeastOnce()) ->method('GetAllResources') ->with($this->equalTo($showInaccessible), $this->equalTo($this->fakeUser)) - ->will($this->returnValue($resources)); + ->willReturn($resources); $this->resourceService ->expects($this->atLeastOnce()) ->method('GetResourceGroups') ->with($this->anything(), $this->equalTo($this->fakeUser)) - ->will($this->returnValue($resourceGroupTree)); + ->willReturn($resourceGroupTree); $this->page ->expects($this->atLeastOnce()) ->method('SetFirstDay') @@ -140,7 +140,7 @@ public function testBindsEmptyCalendarToPageWhenNoReservationsAreFound() $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue(new FakeUser())); + ->willReturn(new FakeUser()); $calendarFilters = new CalendarFilters($schedules, $resources, $defaultScheduleId, null, $resourceGroupTree); $this->page->expects($this->atLeastOnce())->method('BindFilters')->with($this->equalTo($calendarFilters)); diff --git a/tests/Presenters/RegisterPresenterTest.php b/tests/Presenters/RegisterPresenterTest.php index de84376b4..d23749937 100644 --- a/tests/Presenters/RegisterPresenterTest.php +++ b/tests/Presenters/RegisterPresenterTest.php @@ -140,6 +140,7 @@ public function testLoadsAllHomepages() public function testSetsSelectedHomepageToDefault() { $expectedHomepage = 1; + $this->fakeConfig->SetKey(ConfigKeys::DEFAULT_HOMEPAGE, $expectedHomepage); $this->page->_IsPostBack = false; @@ -147,7 +148,7 @@ public function testSetsSelectedHomepageToDefault() $this->presenter->PageLoad(); - $this->assertEquals($this->page->_Homepage, $expectedHomepage); + $this->assertEquals($expectedHomepage, $this->page->_Homepage); } public function testSetsSelectedHomepageToServerSubmitted() @@ -160,7 +161,7 @@ public function testSetsSelectedHomepageToServerSubmitted() $this->presenter->PageLoad(); - $this->assertEquals($this->page->_Homepage, $expectedHomepage); + $this->assertEquals($expectedHomepage, $this->page->_Homepage); } public function testSetsCaptchaUrl() @@ -169,7 +170,7 @@ public function testSetsCaptchaUrl() $this->captcha->expects($this->once()) ->method('GetImageUrl') - ->will($this->returnValue($url)); + ->willReturn($url); $this->ExpectAttributeServiceCalled(); @@ -277,7 +278,7 @@ private function ExpectAttributeServiceCalled($attributes = []) $this->attributeService->expects($this->once()) ->method('GetAttributes') ->with($this->equalTo(CustomAttributeCategory::USER)) - ->will($this->returnValue($list)); + ->willReturn($list); } private function LoadPageValues() diff --git a/tests/Presenters/Reports/GenerateReportPresenterTest.php b/tests/Presenters/Reports/GenerateReportPresenterTest.php index c0cb7d508..ecbba7293 100644 --- a/tests/Presenters/Reports/GenerateReportPresenterTest.php +++ b/tests/Presenters/Reports/GenerateReportPresenterTest.php @@ -78,7 +78,7 @@ public function testRunsCustomReport() $this->equalTo($range), $this->equalTo($filter) ) - ->will($this->returnValue($expectedReport)); + ->willReturn($expectedReport); $user = new FakeUser(); $savedReportColumns = 'savedreport'; diff --git a/tests/Presenters/Reports/SavedReportsPresenterTest.php b/tests/Presenters/Reports/SavedReportsPresenterTest.php index 15e2ffdf5..f4880f74b 100644 --- a/tests/Presenters/Reports/SavedReportsPresenterTest.php +++ b/tests/Presenters/Reports/SavedReportsPresenterTest.php @@ -42,7 +42,7 @@ public function testGetsAllSavedReportsForTheUser() $this->service->expects($this->once()) ->method('GetSavedReports') ->with($this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($savedReports)); + ->willReturn($savedReports); $this->presenter->PageLoad(); @@ -58,7 +58,7 @@ public function testRunsSavedReport() $this->service->expects($this->once()) ->method('GenerateSavedReport') ->with($this->equalTo($reportId), $this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($report)); + ->willReturn($report); $user = new FakeUser(); $savedReportColumns = 'savedreport'; @@ -78,7 +78,7 @@ public function testWhenReportIsNotFound() $this->service->expects($this->once()) ->method('GenerateSavedReport') ->with($this->anything(), $this->anything()) - ->will($this->returnValue(null)); + ->willReturn(null); $this->presenter->GenerateReport(); @@ -99,7 +99,7 @@ public function testEmailsReport() $this->service->expects($this->once()) ->method('GenerateSavedReport') ->with($this->equalTo($reportId), $this->equalTo($this->fakeUser->UserId)) - ->will($this->returnValue($report)); + ->willReturn($report); $this->service->expects($this->once()) ->method('SendReport') diff --git a/tests/Presenters/Reservation/EditReservationPresenterTest.php b/tests/Presenters/Reservation/EditReservationPresenterTest.php index d398802c4..245494447 100644 --- a/tests/Presenters/Reservation/EditReservationPresenterTest.php +++ b/tests/Presenters/Reservation/EditReservationPresenterTest.php @@ -63,12 +63,12 @@ public function testPullsReservationViewFromRepository() $this->page->expects($this->once()) ->method('GetReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->reservationViewRepository->expects($this->once()) ->method('GetReservationForEditing') ->with($referenceNumber) - ->will($this->returnValue($reservationView)); + ->willReturn($reservationView); $this->preconditionService->expects($this->once()) ->method('CheckAll') @@ -77,7 +77,7 @@ public function testPullsReservationViewFromRepository() $this->initializerFactory->expects($this->once()) ->method('GetExistingInitializer') ->with($this->equalTo($this->page), $this->equalTo($reservationView)) - ->will($this->returnValue($this->initializer)); + ->willReturn($this->initializer); $this->initializer->expects($this->once()) ->method('Initialize'); diff --git a/tests/Presenters/Reservation/GuestReservationPresenterTest.php b/tests/Presenters/Reservation/GuestReservationPresenterTest.php index 2a5ea0d6c..ef9ab268e 100644 --- a/tests/Presenters/Reservation/GuestReservationPresenterTest.php +++ b/tests/Presenters/Reservation/GuestReservationPresenterTest.php @@ -47,7 +47,7 @@ public function setUp(): void $this->factory->expects($this->any()) ->method('GetNewInitializer') ->with($this->anything()) - ->will($this->returnValue($this->initializer)); + ->willReturn($this->initializer); $this->presenter = new GuestReservationPresenter( $this->page, diff --git a/tests/Presenters/Reservation/NewReservationPresenterTest.php b/tests/Presenters/Reservation/NewReservationPresenterTest.php index 3ee3a26e3..5eea99ab8 100644 --- a/tests/Presenters/Reservation/NewReservationPresenterTest.php +++ b/tests/Presenters/Reservation/NewReservationPresenterTest.php @@ -44,7 +44,7 @@ public function testPageLoadValidatesAllPreconditionsAndGetsReservationInitializ $reservationInitializerFactory->expects($this->once()) ->method('GetNewInitializer') ->with($this->equalTo($page)) - ->will($this->returnValue($initializer)); + ->willReturn($initializer); $initializer->expects($this->once()) ->method('Initialize'); diff --git a/tests/Presenters/Reservation/ReservationApprovalPresenterTest.php b/tests/Presenters/Reservation/ReservationApprovalPresenterTest.php index af873ef67..4ffb6dfdb 100644 --- a/tests/Presenters/Reservation/ReservationApprovalPresenterTest.php +++ b/tests/Presenters/Reservation/ReservationApprovalPresenterTest.php @@ -51,22 +51,22 @@ public function testLoadAndApprovesReservationSendingNotifications() $this->page->expects($this->once()) ->method('GetReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->persistence->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($reservation)); + ->willReturn($reservation); $this->handler->expects($this->once()) ->method('Handle') ->with($this->equalTo($reservation), $this->equalTo($this->page)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->auth->expects($this->once()) ->method('CanApprove') ->with($this->equalTo(new ReservationViewAdapter($reservation)), $this->equalTo($this->fakeUser)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->presenter->PageLoad(); diff --git a/tests/Presenters/Reservation/ReservationAttachmentPresenterTest.php b/tests/Presenters/Reservation/ReservationAttachmentPresenterTest.php index 347a1ad82..4dee7262a 100644 --- a/tests/Presenters/Reservation/ReservationAttachmentPresenterTest.php +++ b/tests/Presenters/Reservation/ReservationAttachmentPresenterTest.php @@ -52,21 +52,21 @@ public function testLoadsAttachmentIfUserHasPermissionToPrimaryResource() $this->page->expects($this->once()) ->method('GetFileId') - ->will($this->returnValue($fileId)); + ->willReturn($fileId); $this->page->expects($this->once()) ->method('GetReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->reservationRepository->expects($this->once()) ->method('LoadReservationAttachment') ->with($this->equalTo($fileId)) - ->will($this->returnValue($reservationAttachment)); + ->willReturn($reservationAttachment); $this->reservationRepository->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($reservationSeries)); + ->willReturn($reservationSeries); $this->page->expects($this->once()) ->method('BindAttachment') @@ -97,21 +97,21 @@ public function testShowsErrorIfUserDoesNotHavePermissionToPrimaryResource() $this->page->expects($this->once()) ->method('GetFileId') - ->will($this->returnValue($fileId)); + ->willReturn($fileId); $this->page->expects($this->once()) ->method('GetReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->reservationRepository->expects($this->once()) ->method('LoadReservationAttachment') ->with($this->equalTo($fileId)) - ->will($this->returnValue($reservationAttachment)); + ->willReturn($reservationAttachment); $this->reservationRepository->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($reservationSeries)); + ->willReturn($reservationSeries); $this->page->expects($this->once()) ->method('ShowError'); @@ -132,21 +132,21 @@ public function testShowsErrorIfReservationNotFound() $this->page->expects($this->once()) ->method('GetFileId') - ->will($this->returnValue($fileId)); + ->willReturn($fileId); $this->page->expects($this->once()) ->method('GetReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->reservationRepository->expects($this->once()) ->method('LoadReservationAttachment') ->with($this->equalTo($fileId)) - ->will($this->returnValue($reservationAttachment)); + ->willReturn($reservationAttachment); $this->reservationRepository->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue(null)); + ->willReturn(null); $this->page->expects($this->once()) ->method('ShowError'); @@ -161,16 +161,16 @@ public function testShowsErrorIfFileNotFound() $this->page->expects($this->once()) ->method('GetFileId') - ->will($this->returnValue($fileId)); + ->willReturn($fileId); $this->page->expects($this->once()) ->method('GetReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->reservationRepository->expects($this->once()) ->method('LoadReservationAttachment') ->with($this->equalTo($fileId)) - ->will($this->returnValue(null)); + ->willReturn(null); $this->page->expects($this->once()) ->method('ShowError'); @@ -196,21 +196,21 @@ public function testShowsErrorFileDoesNotBelongToReservation() $this->page->expects($this->once()) ->method('GetFileId') - ->will($this->returnValue($fileId)); + ->willReturn($fileId); $this->page->expects($this->once()) ->method('GetReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->reservationRepository->expects($this->once()) ->method('LoadReservationAttachment') ->with($this->equalTo($fileId)) - ->will($this->returnValue($reservationAttachment)); + ->willReturn($reservationAttachment); $this->reservationRepository->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($reservationSeries)); + ->willReturn($reservationSeries); $this->page->expects($this->once()) ->method('ShowError'); diff --git a/tests/Presenters/Reservation/ReservationAttributesPresenterTest.php b/tests/Presenters/Reservation/ReservationAttributesPresenterTest.php index 630824ded..dd12e2fba 100644 --- a/tests/Presenters/Reservation/ReservationAttributesPresenterTest.php +++ b/tests/Presenters/Reservation/ReservationAttributesPresenterTest.php @@ -86,7 +86,7 @@ public function testForSecondaryUserAttributes_ShowIfTheCurrentUserCanBookForReq $this->attributeRepository->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo(CustomAttributeCategory::RESERVATION)) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $this->page->_RequestedUserId = $requestedUserId; @@ -115,7 +115,7 @@ public function testForSecondaryUserAttributes_DoNotShowIfTheCurrentUserCanBookF $this->attributeRepository->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo(CustomAttributeCategory::RESERVATION)) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $this->page->_RequestedUserId = $requestedUserId; @@ -137,7 +137,7 @@ public function testWhenExistingReservationIsRequested_ThenLoadValuesForAttribut $this->attributeRepository->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo(CustomAttributeCategory::RESERVATION)) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $this->reservationRepository->_ReservationView->AddAttribute(new AttributeValue(1, 'value1')); $this->reservationRepository->_ReservationView->AddAttribute(new AttributeValue(2, 'value2')); @@ -180,7 +180,7 @@ public function testIfTheAttributeIsPrivate_AndTheCurrentUserIsNotTheOwnerOrAdmi $this->attributeRepository->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo(CustomAttributeCategory::RESERVATION)) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $this->presenter->PageLoad($this->fakeUser); @@ -204,7 +204,7 @@ public function testIfTheAttributeIsPrivate_AndTheCurrentUserCanReserveForReques $this->attributeRepository->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo(CustomAttributeCategory::RESERVATION)) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $this->presenter->PageLoad($this->fakeUser); diff --git a/tests/Presenters/Reservation/ReservationCheckinPresenterTest.php b/tests/Presenters/Reservation/ReservationCheckinPresenterTest.php index 6579ae1e0..a9f902e8f 100644 --- a/tests/Presenters/Reservation/ReservationCheckinPresenterTest.php +++ b/tests/Presenters/Reservation/ReservationCheckinPresenterTest.php @@ -47,12 +47,12 @@ public function testCheckin() $this->persistence->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($this->page->_ReferenceNumber)) - ->will($this->returnValue($reservation)); + ->willReturn($reservation); $this->handler->expects($this->once()) ->method('Handle') ->with($this->equalTo($reservation), $this->equalTo($this->page)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->presenter->PageLoad(); @@ -71,12 +71,12 @@ public function testCheckout() $this->persistence->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($this->page->_ReferenceNumber)) - ->will($this->returnValue($reservation)); + ->willReturn($reservation); $this->handler->expects($this->once()) ->method('Handle') ->with($this->equalTo($reservation), $this->equalTo($this->page)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->presenter->PageLoad(); diff --git a/tests/Presenters/Reservation/ReservationCreditsPresenterTest.php b/tests/Presenters/Reservation/ReservationCreditsPresenterTest.php index 54de08c98..a87a7efcf 100644 --- a/tests/Presenters/Reservation/ReservationCreditsPresenterTest.php +++ b/tests/Presenters/Reservation/ReservationCreditsPresenterTest.php @@ -67,7 +67,7 @@ public function testReturnsNumberOfCreditsConsumedForNewReservation() $expectedCost = Booked\Currency::Create('USD')->Format(150); - $this->paymentRepository->_CreditCost = new CreditCost(15, 'USD'); + $this->paymentRepository->_CreditCost = [new CreditCost(1, 15, 'USD')]; $this->page->_ResourceId = 1; $this->page->_ResourceIds = [2]; diff --git a/tests/Presenters/Reservation/ReservationDeletePresenterTest.php b/tests/Presenters/Reservation/ReservationDeletePresenterTest.php index c63b21f28..bea826b91 100644 --- a/tests/Presenters/Reservation/ReservationDeletePresenterTest.php +++ b/tests/Presenters/Reservation/ReservationDeletePresenterTest.php @@ -68,20 +68,20 @@ public function testLoadsExistingReservationAndDeletesIt() $this->page->expects($this->once()) ->method('GetReferenceNumber') - ->will($this->returnValue($referenceNumber)); + ->willReturn($referenceNumber); $this->page->expects($this->once()) ->method('GetSeriesUpdateScope') - ->will($this->returnValue($seriesUpdateScope)); + ->willReturn($seriesUpdateScope); $this->page->expects($this->once()) ->method('GetReason') - ->will($this->returnValue($reason)); + ->willReturn($reason); $this->persistenceService->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($expectedSeries)); + ->willReturn($expectedSeries); $expectedSeries->expects($this->once()) ->method('Delete') @@ -104,7 +104,7 @@ public function testHandlingReservationCreationDelegatesToServicesForValidationA $this->handler->expects($this->once()) ->method('Handle') ->with($this->equalTo($series), $this->equalTo($this->page)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->presenter->HandleReservation($series); diff --git a/tests/Presenters/Reservation/ReservationHandlerTest.php b/tests/Presenters/Reservation/ReservationHandlerTest.php index 0d475d028..468db81ba 100644 --- a/tests/Presenters/Reservation/ReservationHandlerTest.php +++ b/tests/Presenters/Reservation/ReservationHandlerTest.php @@ -20,7 +20,7 @@ public function testHandlingReservationCreationDelegatesToServicesForValidationA $validationService->expects($this->once()) ->method('Validate') ->with($this->equalTo($series)) - ->will($this->returnValue($validationResult)); + ->willReturn($validationResult); $persistenceService->expects($this->once()) ->method('Persist') @@ -65,7 +65,7 @@ public function testPreventsPersistenceAndNotificationAndShowsFailedMessageWhenV $validationService->expects($this->once()) ->method('Validate') ->with($this->equalTo($series)) - ->will($this->returnValue($validationResult)); + ->willReturn($validationResult); $persistenceService->expects($this->never()) ->method('Persist'); @@ -113,7 +113,7 @@ public function testPreventsPersistenceAndNotificationAndShowsRetryMessageIfCanB $validationService->expects($this->once()) ->method('Validate') ->with($this->equalTo($series), $this->equalTo($page->retryParameters)) - ->will($this->returnValue($validationResult)); + ->willReturn($validationResult); $persistenceService->expects($this->never()) ->method('Persist'); @@ -150,7 +150,7 @@ public function testCanJoinWaitListIfTurnedOnAndNotRecurringSeriesAndOnlyErrorIs $validationService->expects($this->once()) ->method('Validate') ->with($this->equalTo($series)) - ->will($this->returnValue($validationResult)); + ->willReturn($validationResult); $persistenceService->expects($this->never()) ->method('Persist'); diff --git a/tests/Presenters/Reservation/ReservationInitializationTest.php b/tests/Presenters/Reservation/ReservationInitializationTest.php index 3c5c14c33..1d0a61533 100644 --- a/tests/Presenters/Reservation/ReservationInitializationTest.php +++ b/tests/Presenters/Reservation/ReservationInitializationTest.php @@ -83,7 +83,7 @@ public function testInitializesReservationData() $this->page->expects($this->once()) ->method('GetRequestedScheduleId') - ->will($this->returnValue($scheduleId)); + ->willReturn($scheduleId); $this->page->expects($this->once()) ->method('SetScheduleId') @@ -165,7 +165,7 @@ public function testWhenNoScheduleIsPassed_UseDefaultScheduleId() $this->page->expects($this->once()) ->method('GetRequestedScheduleId') - ->will($this->returnValue(null)); + ->willReturn(null); $this->page->expects($this->once()) ->method('SetScheduleId') diff --git a/tests/Presenters/Reservation/ReservationMovePresenterTest.php b/tests/Presenters/Reservation/ReservationMovePresenterTest.php index 6f09f9383..f0d64bc44 100644 --- a/tests/Presenters/Reservation/ReservationMovePresenterTest.php +++ b/tests/Presenters/Reservation/ReservationMovePresenterTest.php @@ -80,7 +80,7 @@ public function testAdjustsDuration() $this->persistenceService->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($this->page->_ReferenceNumber)) - ->will($this->returnValue($expectedSeries)); + ->willReturn($expectedSeries); $this->handler->expects($this->once()) ->method('Handle') @@ -107,12 +107,12 @@ public function testChangesResource() $this->persistenceService->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($this->page->_ReferenceNumber)) - ->will($this->returnValue($expectedSeries)); + ->willReturn($expectedSeries); $this->resourceRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($this->page->_ResourceId)) - ->will($this->returnValue($newResource)); + ->willReturn($newResource); $this->presenter->PageLoad(); @@ -137,7 +137,7 @@ public function testRemovesDuplicateResource() $this->persistenceService->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($this->page->_ReferenceNumber)) - ->will($this->returnValue($expectedSeries)); + ->willReturn($expectedSeries); $this->presenter->PageLoad(); diff --git a/tests/Presenters/Reservation/ReservationSavePresenterTest.php b/tests/Presenters/Reservation/ReservationSavePresenterTest.php index 925ebf15b..fa4a8ef21 100644 --- a/tests/Presenters/Reservation/ReservationSavePresenterTest.php +++ b/tests/Presenters/Reservation/ReservationSavePresenterTest.php @@ -124,20 +124,14 @@ public function testCreationBuildsReservationFromPageData() $startReminder = new ReservationReminder($this->page->GetStartReminderValue(), $this->page->GetStartReminderInterval()); $endReminder = new ReservationReminder($this->page->GetEndReminderValue(), $this->page->GetEndReminderInterval()); - $this->resourceRepository->expects($this->at(0)) + $this->resourceRepository->expects($this->exactly(3)) ->method('LoadById') - ->with($this->equalTo($resourceId)) - ->will($this->returnValue($resource)); - - $this->resourceRepository->expects($this->at(1)) - ->method('LoadById') - ->with($this->equalTo($additionalResources[0])) - ->will($this->returnValue($additionalResource1)); - - $this->resourceRepository->expects($this->at(2)) - ->method('LoadById') - ->with($this->equalTo($additionalResources[1])) - ->will($this->returnValue($additionalResource2)); + ->willReturnMap( + [ + [$resourceId, $resource], + [$additionalResources[0], $additionalResource1], + [$additionalResources[1], $additionalResource2] + ]); $fakeScheduleLayout = new FakeScheduleLayout(); $fakeScheduleLayout->_SlotCount = new SlotCount(1, 2); @@ -183,7 +177,7 @@ public function testHandlingReservationCreationDelegatesToHandler() $this->handler->expects($this->once()) ->method('Handle') ->with($this->equalTo($series), $this->isInstanceOf('FakeReservationSavePage')) - ->will($this->returnValue(true)); + ->willReturn(true); $this->presenter->HandleReservation($series); diff --git a/tests/Presenters/Reservation/ReservationUpdatePresenterTest.php b/tests/Presenters/Reservation/ReservationUpdatePresenterTest.php index 5b236d126..e17bd6fae 100644 --- a/tests/Presenters/Reservation/ReservationUpdatePresenterTest.php +++ b/tests/Presenters/Reservation/ReservationUpdatePresenterTest.php @@ -106,22 +106,16 @@ public function testLoadsExistingReservationAndUpdatesData() $this->persistenceService->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($expectedSeries)); + ->willReturn($expectedSeries); - $this->resourceRepository->expects($this->at(0)) + $this->resourceRepository->expects($this->exactly(3)) ->method('LoadById') - ->with($this->equalTo($this->page->resourceId)) - ->will($this->returnValue($resource)); - - $this->resourceRepository->expects($this->at(1)) - ->method('LoadById') - ->with($this->equalTo($additionalId1)) - ->will($this->returnValue($additional1)); - - $this->resourceRepository->expects($this->at(2)) - ->method('LoadById') - ->with($this->equalTo($additionalId2)) - ->will($this->returnValue($additional2)); + ->willReturnMap( + [ + [$this->page->resourceId, $resource], + [$additionalId1, $additional1], + [$additionalId2, $additional2] + ]); $this->page->repeatType = RepeatType::Daily; $roFactory = new RepeatOptionsFactory(); @@ -206,12 +200,12 @@ public function testUsesFirstAdditionalResourceIfPrimaryIsRemoved() $this->persistenceService->expects($this->once()) ->method('LoadByReferenceNumber') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($expectedSeries)); + ->willReturn($expectedSeries); $this->resourceRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($additionalId)) - ->will($this->returnValue($resource)); + ->willReturn($resource); $existingSeries = $this->presenter->BuildReservation(); @@ -229,7 +223,7 @@ public function testHandlingReservationCreationDelegatesToServicesForValidationA $this->handler->expects($this->once()) ->method('Handle') ->with($this->equalTo($series), $this->isInstanceOf('FakeReservationUpdatePage')) - ->will($this->returnValue(true)); + ->willReturn(true); $this->presenter->HandleReservation($series); diff --git a/tests/Presenters/ResourceDisplayPresenterTest.php b/tests/Presenters/ResourceDisplayPresenterTest.php index 8f09493d7..1f19fc289 100644 --- a/tests/Presenters/ResourceDisplayPresenterTest.php +++ b/tests/Presenters/ResourceDisplayPresenterTest.php @@ -128,7 +128,7 @@ public function testDisplaysReservationsIfResourceAllowsDisplay() $this->attributeService->_ReservationAttributes = []; $this->presenter->reservationCreateHandler = $this->reservationCreateHandler; - $this->presenter->DisplayResource($publicId); + $this->presenter->DisplayResource($publicId, null); $expectedDate = DateRange::Create($now->ToTimezone($timezone)->GetDate()->ToUtc(), $now->ToTimezone($timezone)->GetDate()->AddDays(1)->ToUtc(), 'UTC'); $this->assertEquals(new DailyLayout( @@ -158,7 +158,7 @@ public function testDisplaysUpcomingReservations() $nextItem ]; - $this->presenter->DisplayResource(1); + $this->presenter->DisplayResource(1, null); $this->assertEquals([$nextItem], $this->page->_UpcomingReservations); $this->assertEquals($nextItem, $this->page->_NextReservation); @@ -182,7 +182,7 @@ public function testAsksForNextCheckin() new ReservationListItem($r2), ]; - $this->presenter->DisplayResource(1); + $this->presenter->DisplayResource(1, null); $this->assertEquals(true, $this->page->_RequiresCheckIn); $this->assertEquals("refnum", $this->page->_CheckinReferenceNumber); @@ -203,7 +203,7 @@ public function testDisplaysAvailable() $nextItem ]; - $this->presenter->DisplayResource(1); + $this->presenter->DisplayResource(1, null); $this->assertEquals(true, $this->page->_AvailableNow); $this->assertEquals(false, $this->page->_RequiresCheckIn); @@ -224,7 +224,7 @@ public function testDisplaysUnavailable() $nextItem ]; - $this->presenter->DisplayResource(1); + $this->presenter->DisplayResource(1, null); $this->assertEquals(false, $this->page->_AvailableNow); $this->assertEquals($currentItem, $this->page->_CurrentReservation); @@ -235,7 +235,7 @@ public function testWhenNotEnabledToDisplay() $resource = new FakeBookableResource(1); $this->resourceRepository->_Resource = $resource; - $this->presenter->DisplayResource('whatever'); + $this->presenter->DisplayResource('whatever', null); $this->assertTrue($this->page->_DisplayNotEnabledMessage); } @@ -260,14 +260,14 @@ public function testWhenTheLastSlotIsAlreadyPast_GoToTomorrow() $this->attributeService->_ReservationAttributes = []; $this->presenter->reservationCreateHandler = $this->reservationCreateHandler; - $this->presenter->DisplayResource($publicId); - $expectedDate = DateRange::Create($now->ToTimezone($timezone)->GetDate()->AddDays(1)->ToUtc(), $now->ToTimezone($timezone)->GetDate()->AddDays(2)->ToUtc(), 'UTC'); + $this->presenter->DisplayResource($publicId, null); + $expectedDate = $now->ToTimezone($timezone)->GetDate()->AddDays(1); $this->assertEquals(new DailyLayout( $this->reservationService->_ReservationListing, $this->scheduleRepository->_Layout ), $this->page->_DailyLayout); - $this->assertEquals($expectedDate, $this->reservationService->_LastDateRange); + $this->assertEquals($expectedDate, $this->page->_Today); } public function testWhenBookingSucceeds() @@ -276,6 +276,7 @@ public function testWhenBookingSucceeds() $this->page->_Email = 'some@user.com'; $this->page->_BeginTime = '08:00'; $this->page->_EndTime = '17:00'; + $this->page->_BeginDate = '2016-03-11'; $this->page->_Timezone = 'America/New_York'; $this->page->_ResourceId = 292; @@ -307,6 +308,7 @@ public function testWhenReservationFails() $this->page->_Email = 'some@user.com'; $this->page->_BeginTime = '08:00'; $this->page->_EndTime = '17:00'; + $this->page->_BeginDate = '2016-03-11'; $this->page->_Timezone = 'America/New_York'; $this->page->_ResourceId = 292; @@ -377,10 +379,12 @@ class TestResourceDisplayPage extends FakePageBase implements IResourceDisplayPa public $_DisplayNotEnabledMessage = false; public $_Email; public $_BeginTime; + public $_BeginDate; public $_EndTime; public $_Timezone; public $_ReservationCreatedSuccessfully; public $_ReservationCheckedInSuccessfully; + public $_Today; /** * @var ReservationResultCollector @@ -483,6 +487,7 @@ public function DisplayAvailability(IDailyLayout $dailyLayout, Date $today, Date $this->_UpcomingReservations = $upcoming; $this->_RequiresCheckIn = $requiresCheckin; $this->_CheckinReferenceNumber = $checkinReferenceNumber; + $this->_Today = $today; } public function BindResource(BookableResource $resource) @@ -515,6 +520,11 @@ public function GetBeginTime() return $this->_BeginTime; } + public function GetBeginDate() + { + return $this->_BeginDate; + } + public function GetEndTime() { return $this->_EndTime; diff --git a/tests/Presenters/SchedulePresenterTest.php b/tests/Presenters/SchedulePresenterTest.php index db41fc80c..032b09e63 100644 --- a/tests/Presenters/SchedulePresenterTest.php +++ b/tests/Presenters/SchedulePresenterTest.php @@ -55,24 +55,24 @@ public function testPageLoadBindsAllSchedulesAndProperResourcesWhenNotPostingBac $page ->expects($this->once()) ->method('ShowInaccessibleResources') - ->will($this->returnValue($this->showInaccessibleResources)); + ->willReturn($this->showInaccessibleResources); $page ->expects($this->once()) ->method('GetDisplayTimezone') - ->will($this->returnValue($user->Timezone)); + ->willReturn($user->Timezone); $scheduleService ->expects($this->once()) ->method('GetAll') ->with($this->equalTo($this->showInaccessibleResources), $this->equalTo($this->fakeUser)) - ->will($this->returnValue($this->schedules)); + ->willReturn($this->schedules); $pageBuilder ->expects($this->once()) ->method('GetCurrentSchedule') ->with($this->equalTo($page), $this->equalTo($this->schedules), $this->equalTo($user)) - ->will($this->returnValue($this->currentSchedule)); + ->willReturn($this->currentSchedule); $pageBuilder ->expects($this->once()) @@ -85,7 +85,7 @@ public function testPageLoadBindsAllSchedulesAndProperResourcesWhenNotPostingBac ->expects($this->once()) ->method('GetResourceFilter') ->with($this->equalTo($this->scheduleId), $this->equalTo($page)) - ->will($this->returnValue($resourceFilter)); + ->willReturn($resourceFilter); $pageBuilder ->expects($this->once()) @@ -106,13 +106,13 @@ public function testPageLoadBindsAllSchedulesAndProperResourcesWhenNotPostingBac $this->equalTo($user), $this->equalTo($resourceFilter) ) - ->will($this->returnValue($resources)); + ->willReturn($resources); $resourceService ->expects($this->once()) ->method('GetResourceGroups') ->with($this->equalTo($this->scheduleId)) - ->will($this->returnValue($groups)); + ->willReturn($groups); $pageBuilder ->expects($this->once()) @@ -123,7 +123,7 @@ public function testPageLoadBindsAllSchedulesAndProperResourcesWhenNotPostingBac ->expects($this->once()) ->method('GetScheduleDates') ->with($this->equalTo($user), $this->equalTo($this->currentSchedule), $this->equalTo($page)) - ->will($this->returnValue($bindingDates)); + ->willReturn($bindingDates); $pageBuilder ->expects($this->once()) @@ -134,7 +134,7 @@ public function testPageLoadBindsAllSchedulesAndProperResourcesWhenNotPostingBac ->expects($this->once()) ->method('GetDailyLayout') ->with($this->equalTo($this->scheduleId), new ScheduleLayoutFactory($user->Timezone), new EmptyReservationListing()) - ->will($this->returnValue($dailyLayout)); + ->willReturn($dailyLayout); $pageBuilder ->expects($this->once()) @@ -144,7 +144,7 @@ public function testPageLoadBindsAllSchedulesAndProperResourcesWhenNotPostingBac $resourceService ->expects($this->once()) ->method('GetResourceTypes') - ->will($this->returnValue($resourceTypes)); + ->willReturn($resourceTypes); $pageBuilder ->expects($this->once()) @@ -154,12 +154,12 @@ public function testPageLoadBindsAllSchedulesAndProperResourcesWhenNotPostingBac $resourceService ->expects($this->once()) ->method('GetResourceAttributes') - ->will($this->returnValue($resourceAttributes)); + ->willReturn($resourceAttributes); $resourceService ->expects($this->once()) ->method('GetResourceTypeAttributes') - ->will($this->returnValue($resourceTypeAttributes)); + ->willReturn($resourceTypeAttributes); $presenter->PageLoad($this->fakeUser); } @@ -198,7 +198,7 @@ public function testScheduleBuilderBindsAllSchedulesAndSetsActive() ->expects($this->once()) ->method('GetScheduleStyle') ->with($this->equalTo($activeId)) - ->will($this->returnValue(ScheduleStyle::Tall)); + ->willReturn(ScheduleStyle::Tall); $page ->expects($this->once()) @@ -217,12 +217,12 @@ public function testScheduleBuilderGetCurrentScheduleReturnsSelectedScheduleOnPo $s1 ->expects($this->once()) ->method('GetId') - ->will($this->returnValue(11)); + ->willReturn(11); $s2 ->expects($this->once()) ->method('GetId') - ->will($this->returnValue(10)); + ->willReturn(10); $schedules = [$s1, $s2]; @@ -231,7 +231,7 @@ public function testScheduleBuilderGetCurrentScheduleReturnsSelectedScheduleOnPo $page ->expects($this->atLeastOnce()) ->method('GetScheduleId') - ->will($this->returnValue(10)); + ->willReturn(10); $pageBuilder = new SchedulePageBuilder(); $actual = $pageBuilder->GetCurrentSchedule($page, $schedules, $this->fakeUser); @@ -297,17 +297,17 @@ public function testStartsOnCurrentDateIfShowingLessThanAWeekOfData() $schedulePage ->expects($this->once()) ->method('GetSelectedDate') - ->will($this->returnValue(null)); + ->willReturn(null); $schedule ->expects($this->once()) ->method('GetWeekdayStart') - ->will($this->returnValue($startDay)); + ->willReturn($startDay); $schedule ->expects($this->once()) ->method('GetDaysVisible') - ->will($this->returnValue($daysVisible)); + ->willReturn($daysVisible); $pageBuilder = new SchedulePageBuilder(); $dates = $pageBuilder->GetScheduleDates($user, $schedule, $schedulePage); @@ -339,17 +339,17 @@ public function testStartsToday() $schedulePage ->expects($this->once()) ->method('GetSelectedDate') - ->will($this->returnValue(null)); + ->willReturn(null); $schedule ->expects($this->once()) ->method('GetWeekdayStart') - ->will($this->returnValue($startDay)); + ->willReturn($startDay); $schedule ->expects($this->once()) ->method('GetDaysVisible') - ->will($this->returnValue($daysVisible)); + ->willReturn($daysVisible); $pageBuilder = new SchedulePageBuilder(); $dates = $pageBuilder->GetScheduleDates($user, $schedule, $schedulePage); @@ -383,17 +383,17 @@ public function testGetScheduleDatesStartsOnConfiguredDayOfWeekWhenStartDayIsPri $schedulePage ->expects($this->once()) ->method('GetSelectedDate') - ->will($this->returnValue(null)); + ->willReturn(null); $schedule ->expects($this->once()) ->method('GetWeekdayStart') - ->will($this->returnValue($startDay)); + ->willReturn($startDay); $schedule ->expects($this->once()) ->method('GetDaysVisible') - ->will($this->returnValue($daysVisible)); + ->willReturn($daysVisible); $pageBuilder = new SchedulePageBuilder(); $dates = $pageBuilder->GetScheduleDates($user, $schedule, $schedulePage); @@ -426,17 +426,17 @@ public function testGetScheduleDatesStartsOnConfiguredDayOfWeekWhenStartDayIsAft $schedulePage ->expects($this->once()) ->method('GetSelectedDate') - ->will($this->returnValue(null)); + ->willReturn(null); $schedule ->expects($this->once()) ->method('GetWeekdayStart') - ->will($this->returnValue($startDay)); + ->willReturn($startDay); $schedule ->expects($this->once()) ->method('GetDaysVisible') - ->will($this->returnValue($daysVisible)); + ->willReturn($daysVisible); $pageBuilder = new SchedulePageBuilder(); $dates = $pageBuilder->GetScheduleDates($user, $schedule, $schedulePage); @@ -472,17 +472,17 @@ public function testCorrectDatesAreUsedWhenTheUsersTimezoneIsAheadByAWeek() $schedulePage ->expects($this->once()) ->method('GetSelectedDate') - ->will($this->returnValue(null)); + ->willReturn(null); $schedule ->expects($this->once()) ->method('GetWeekdayStart') - ->will($this->returnValue($startDay)); + ->willReturn($startDay); $schedule ->expects($this->once()) ->method('GetDaysVisible') - ->will($this->returnValue($daysVisible)); + ->willReturn($daysVisible); $pageBuilder = new SchedulePageBuilder(); $dates = $pageBuilder->GetScheduleDates($user, $schedule, $schedulePage); @@ -518,17 +518,17 @@ public function testCorrectDatesAreUsedWhenTheUsersTimezoneIsBehindByAWeek() $schedulePage ->expects($this->once()) ->method('GetSelectedDate') - ->will($this->returnValue(null)); + ->willReturn(null); $schedule ->expects($this->once()) ->method('GetWeekdayStart') - ->will($this->returnValue($startDay)); + ->willReturn($startDay); $schedule ->expects($this->once()) ->method('GetDaysVisible') - ->will($this->returnValue($daysVisible)); + ->willReturn($daysVisible); $pageBuilder = new SchedulePageBuilder(); $dates = $pageBuilder->GetScheduleDates($user, $schedule, $schedulePage); @@ -560,17 +560,17 @@ public function testProvidedStartDateIsUsedIfSpecified() $schedulePage ->expects($this->once()) ->method('GetSelectedDate') - ->will($this->returnValue($selectedDate->Format("Y-m-d"))); + ->willReturn($selectedDate->Format("Y-m-d")); $schedule ->expects($this->once()) ->method('GetWeekdayStart') - ->will($this->returnValue($startDay)); + ->willReturn($startDay); $schedule ->expects($this->once()) ->method('GetDaysVisible') - ->will($this->returnValue($daysVisible)); + ->willReturn($daysVisible); $pageBuilder = new SchedulePageBuilder(); $dates = $pageBuilder->GetScheduleDates($user, $schedule, $schedulePage); @@ -753,22 +753,22 @@ public function testShowsSevenDaysIfWeAreShowingFullWeek() $schedulePage ->expects($this->once()) ->method('GetSelectedDate') - ->will($this->returnValue($selectedDate->Format("Y-m-d"))); + ->willReturn($selectedDate->Format("Y-m-d")); $schedulePage ->expects($this->once()) ->method('GetShowFullWeek') - ->will($this->returnValue(true)); + ->willReturn(true); $schedule ->expects($this->once()) ->method('GetWeekdayStart') - ->will($this->returnValue($startDay)); + ->willReturn($startDay); $schedule ->expects($this->once()) ->method('GetDaysVisible') - ->will($this->returnValue($daysVisible)); + ->willReturn($daysVisible); $pageBuilder = new SchedulePageBuilder(); $dates = $pageBuilder->GetScheduleDates($user, $schedule, $schedulePage); @@ -798,24 +798,24 @@ public function testCanGetLayoutForScheduleOnDate() $page ->expects($this->once()) ->method('GetScheduleId') - ->will($this->returnValue($scheduleId)); + ->willReturn($scheduleId); $page ->expects($this->once()) ->method('GetLayoutDate') - ->will($this->returnValue($dateString)); + ->willReturn($dateString); $scheduleService ->expects($this->once()) ->method('GetLayout') ->with($this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory($user->Timezone))) - ->will($this->returnValue($layout)); + ->willReturn($layout); $layout ->expects($this->once()) ->method('GetLayout') ->with($this->equalTo($date)) - ->will($this->returnValue($periods)); + ->willReturn($periods); $page ->expects($this->once()) diff --git a/tests/Presenters/SearchAvailabilityPresenterTest.php b/tests/Presenters/SearchAvailabilityPresenterTest.php index 3103faba1..d04fe6248 100644 --- a/tests/Presenters/SearchAvailabilityPresenterTest.php +++ b/tests/Presenters/SearchAvailabilityPresenterTest.php @@ -128,7 +128,7 @@ public function testWhenThisWeekSelected() $this->presenter->SearchAvailability(); - $expectedSearchRange = new DateRange(Date::Parse('2016-07-03', $this->fakeUser->Timezone), Date::Parse('2016-07-09', $this->fakeUser->Timezone)); + $expectedSearchRange = new DateRange(Date::Parse('2016-07-03', $this->fakeUser->Timezone), Date::Parse('2016-07-10', $this->fakeUser->Timezone)); $this->assertEquals($expectedSearchRange, $this->reservationService->_LastDateRange); } @@ -283,13 +283,13 @@ public function testWhenSearchingForSpecificTime() $resource = new TestResourceDto($resourceId); $this->resourceService->_AllResources = [$resource]; - $sun = new Date('2019-01-20', $tz); $mon = new Date('2019-01-21', $tz); $tue = new Date('2019-01-22', $tz); $wed = new Date('2019-01-23', $tz); $thu = new Date('2019-01-24', $tz); $fri = new Date('2019-01-25', $tz); $sat = new Date('2019-01-26', $tz); + $sun = new Date('2019-01-27', $tz); Date::_SetNow($tue); $this->page->_Range = 'thisweek'; diff --git a/tests/Presenters/UserCreditsPresenterTest.php b/tests/Presenters/UserCreditsPresenterTest.php index a7005fbd3..7c46b3f5f 100644 --- a/tests/Presenters/UserCreditsPresenterTest.php +++ b/tests/Presenters/UserCreditsPresenterTest.php @@ -47,7 +47,7 @@ public function testPageLoad() $currentCredits = 10.5; $this->userRepository->_User = new FakeUser(); $this->userRepository->_User->WithCredits($currentCredits); - $this->paymentRepository->_CreditCost = new CreditCost('10.11'); + $this->paymentRepository->_CreditCost = [new CreditCost(1, '10.11')]; $this->presenter->PageLoad($this->fakeUser); diff --git a/tests/WebService/WebServiceSecurityTest.php b/tests/WebService/WebServiceSecurityTest.php index 19a4cb34e..f4a62fc3c 100644 --- a/tests/WebService/WebServiceSecurityTest.php +++ b/tests/WebService/WebServiceSecurityTest.php @@ -41,20 +41,18 @@ public function setUp(): void public function testSetsUserSessionIfValidAndNotExpired() { - $this->server->expects($this->at(0)) + $this->server->expects($this->exactly(2)) ->method('GetHeader') - ->with($this->equalTo(WebServiceHeaders::SESSION_TOKEN)) - ->will($this->returnValue($this->sessionToken)); - - $this->server->expects($this->at(1)) - ->method('GetHeader') - ->with($this->equalTo(WebServiceHeaders::USER_ID)) - ->will($this->returnValue($this->userId)); + ->willReturnMap( + [ + [WebServiceHeaders::SESSION_TOKEN, $this->sessionToken], + [WebServiceHeaders::USER_ID, $this->userId] + ]); $this->userSessionRepository->expects($this->once()) ->method('LoadBySessionToken') ->with($this->equalTo($this->sessionToken)) - ->will($this->returnValue($this->session)); + ->willReturn($this->session); $this->userSessionRepository->expects($this->once()) ->method('Update') @@ -74,20 +72,18 @@ public function testDeletesExpiredSessions() { $this->session->_IsExpired = true; - $this->server->expects($this->at(0)) - ->method('GetHeader') - ->with($this->equalTo(WebServiceHeaders::SESSION_TOKEN)) - ->will($this->returnValue($this->sessionToken)); - - $this->server->expects($this->at(1)) + $this->server->expects($this->exactly(2)) ->method('GetHeader') - ->with($this->equalTo(WebServiceHeaders::USER_ID)) - ->will($this->returnValue($this->userId)); + ->willReturnMap( + [ + [WebServiceHeaders::SESSION_TOKEN, $this->sessionToken], + [WebServiceHeaders::USER_ID, $this->userId] + ]); $this->userSessionRepository->expects($this->once()) ->method('LoadBySessionToken') ->with($this->equalTo($this->sessionToken)) - ->will($this->returnValue($this->session)); + ->willReturn($this->session); $this->userSessionRepository->expects($this->once()) ->method('Delete') @@ -101,20 +97,18 @@ public function testDeletesExpiredSessions() public function testHandlesSessionNotFound() { - $this->server->expects($this->at(0)) - ->method('GetHeader') - ->with($this->equalTo(WebServiceHeaders::SESSION_TOKEN)) - ->will($this->returnValue($this->sessionToken)); - - $this->server->expects($this->at(1)) + $this->server->expects($this->exactly(2)) ->method('GetHeader') - ->with($this->equalTo(WebServiceHeaders::USER_ID)) - ->will($this->returnValue($this->userId)); + ->willReturnMap( + [ + [WebServiceHeaders::SESSION_TOKEN, $this->sessionToken], + [WebServiceHeaders::USER_ID, $this->userId] + ]); $this->userSessionRepository->expects($this->once()) ->method('LoadBySessionToken') ->with($this->equalTo($this->sessionToken)) - ->will($this->returnValue(null)); + ->willReturn(null); $wasHandled = $this->security->HandleSecureRequest($this->server); @@ -123,20 +117,18 @@ public function testHandlesSessionNotFound() public function testHandlesSessionMisMatch() { - $this->server->expects($this->at(0)) + $this->server->expects($this->exactly(2)) ->method('GetHeader') - ->with($this->equalTo(WebServiceHeaders::SESSION_TOKEN)) - ->will($this->returnValue('not the right token')); - - $this->server->expects($this->at(1)) - ->method('GetHeader') - ->with($this->equalTo(WebServiceHeaders::USER_ID)) - ->will($this->returnValue('not the right id')); + ->willReturnMap( + [ + [WebServiceHeaders::SESSION_TOKEN, 'not the right token'], + [WebServiceHeaders::USER_ID, 'not the right id'] + ]); $this->userSessionRepository->expects($this->once()) ->method('LoadBySessionToken') ->with($this->equalTo('not the right token')) - ->will($this->returnValue($this->session)); + ->willReturn($this->session); $wasHandled = $this->security->HandleSecureRequest($this->server); @@ -146,20 +138,18 @@ public function testHandlesSessionMisMatch() public function testHandlesAdminRequest() { $this->session->IsAdmin = true; - $this->server->expects($this->at(0)) - ->method('GetHeader') - ->with($this->equalTo(WebServiceHeaders::SESSION_TOKEN)) - ->will($this->returnValue($this->sessionToken)); - - $this->server->expects($this->at(1)) + $this->server->expects($this->exactly(2)) ->method('GetHeader') - ->with($this->equalTo(WebServiceHeaders::USER_ID)) - ->will($this->returnValue($this->userId)); + ->willReturnMap( + [ + [WebServiceHeaders::SESSION_TOKEN, $this->sessionToken], + [WebServiceHeaders::USER_ID, $this->userId] + ]); $this->userSessionRepository->expects($this->once()) ->method('LoadBySessionToken') ->with($this->equalTo($this->sessionToken)) - ->will($this->returnValue($this->session)); + ->willReturn($this->session); $this->userSessionRepository->expects($this->once()) ->method('Update') @@ -178,20 +168,18 @@ public function testHandlesAdminRequest() public function testHandlesWhenUserIsNotAdmin() { $this->session->IsAdmin = false; - $this->server->expects($this->at(0)) - ->method('GetHeader') - ->with($this->equalTo(WebServiceHeaders::SESSION_TOKEN)) - ->will($this->returnValue($this->sessionToken)); - - $this->server->expects($this->at(1)) + $this->server->expects($this->exactly(2)) ->method('GetHeader') - ->with($this->equalTo(WebServiceHeaders::USER_ID)) - ->will($this->returnValue($this->userId)); + ->willReturnMap( + [ + [WebServiceHeaders::SESSION_TOKEN, $this->sessionToken], + [WebServiceHeaders::USER_ID, $this->userId] + ]); $this->userSessionRepository->expects($this->once()) ->method('LoadBySessionToken') ->with($this->equalTo($this->sessionToken)) - ->will($this->returnValue($this->session)); + ->willReturn($this->session); $wasHandled = $this->security->HandleSecureRequest($this->server, true); diff --git a/tests/WebServices/AccessoriesWebServiceTest.php b/tests/WebServices/AccessoriesWebServiceTest.php index ca78ea2a4..052f6a45b 100644 --- a/tests/WebServices/AccessoriesWebServiceTest.php +++ b/tests/WebServices/AccessoriesWebServiceTest.php @@ -41,7 +41,7 @@ public function testGetsAllAccessories() $this->resourceRepository->expects($this->once()) ->method('GetAccessoryList') - ->will($this->returnValue($accessories)); + ->willReturn($accessories); $this->service->GetAll(); @@ -58,7 +58,7 @@ public function testGetsAccessoryById() $this->accessoryRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($accessoryId)) - ->will($this->returnValue($accessory)); + ->willReturn($accessory); $this->service->GetAccessory($accessoryId); @@ -73,7 +73,7 @@ public function testWhenAccessoryNotFound() $this->accessoryRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($accessoryId)) - ->will($this->returnValue(null)); + ->willReturn(null); $this->service->GetAccessory($accessoryId); diff --git a/tests/WebServices/AttributesWebServiceTest.php b/tests/WebServices/AttributesWebServiceTest.php index 541e07c76..8da046850 100644 --- a/tests/WebServices/AttributesWebServiceTest.php +++ b/tests/WebServices/AttributesWebServiceTest.php @@ -38,7 +38,7 @@ public function testGetsSingleAttribute() $this->attributeService->expects($this->once()) ->method('GetById') ->with($this->equalTo($attributeId)) - ->will($this->returnValue($attribute)); + ->willReturn($attribute); $expectedResponse = new CustomAttributeDefinitionResponse($this->server, $attribute); @@ -54,7 +54,7 @@ public function testWhenAttributeNotFound() $this->attributeService->expects($this->once()) ->method('GetById') ->with($this->equalTo($attributeId)) - ->will($this->returnValue(null)); + ->willReturn(null); $this->service->GetAttribute($attributeId); @@ -69,7 +69,7 @@ public function testGetsAttributesByCategory() $this->attributeService->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo($categoryId)) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $expectedResponse = new CustomAttributesResponse($this->server, $attributes); diff --git a/tests/WebServices/AuthenticationWebServiceTest.php b/tests/WebServices/AuthenticationWebServiceTest.php index 8ee59b589..bb0bb138c 100644 --- a/tests/WebServices/AuthenticationWebServiceTest.php +++ b/tests/WebServices/AuthenticationWebServiceTest.php @@ -41,12 +41,12 @@ public function testLogsUserInIfValidCredentials() $this->authentication->expects($this->once()) ->method('Validate') ->with($this->equalTo($username), $this->equalTo($password)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->authentication->expects($this->once()) ->method('Login') ->with($this->equalTo($username)) - ->will($this->returnValue($session)); + ->willReturn($session); $this->service->Authenticate($this->server); @@ -65,7 +65,7 @@ public function testRestrictsUserIfInvalidCredentials() $this->authentication->expects($this->once()) ->method('Validate') ->with($this->equalTo($username), $this->equalTo($password)) - ->will($this->returnValue(false)); + ->willReturn(false); $this->service->Authenticate($this->server); diff --git a/tests/WebServices/Controllers/ReservationSaveControllerTest.php b/tests/WebServices/Controllers/ReservationSaveControllerTest.php index 651eed43f..7e8e33294 100644 --- a/tests/WebServices/Controllers/ReservationSaveControllerTest.php +++ b/tests/WebServices/Controllers/ReservationSaveControllerTest.php @@ -37,11 +37,11 @@ public function testUsesPresenterToCreateReservation() $this->presenterFactory->expects($this->once()) ->method('Create') ->with($this->equalTo($facade), $this->equalTo($session)) - ->will($this->returnValue($presenter)); + ->willReturn($presenter); $presenter->expects($this->once()) ->method('BuildReservation') - ->will($this->returnValue($series)); + ->willReturn($series); $presenter->expects($this->once()) ->method('HandleReservation') @@ -70,10 +70,10 @@ public function testUpdatesExistingReservation() $this->presenterFactory->expects($this->once()) ->method('Update') ->with($this->equalTo($facade), $this->equalTo($session)) - ->will($this->returnValue($presenter)); + ->willReturn($presenter); $presenter->expects($this->once()) ->method('BuildReservation') - ->will($this->returnValue($series)); + ->willReturn($series); $presenter->expects($this->once()) ->method('HandleReservation') @@ -97,7 +97,7 @@ public function testApprovesExistingReservation() $this->presenterFactory->expects($this->once()) ->method('Approve') ->with($this->equalTo($facade), $this->equalTo($session)) - ->will($this->returnValue($presenter)); + ->willReturn($presenter); $presenter->expects($this->once()) ->method('PageLoad'); @@ -123,11 +123,11 @@ public function testDeletesReservation() $this->presenterFactory->expects($this->once()) ->method('Delete') ->with($this->equalTo($facade), $this->equalTo($session)) - ->will($this->returnValue($presenter)); + ->willReturn($presenter); $presenter->expects($this->once()) ->method('BuildReservation') - ->will($this->returnValue($reservation)); + ->willReturn($reservation); $presenter->expects($this->once()) ->method('HandleReservation') diff --git a/tests/WebServices/Controllers/ResourceSaveControllerTest.php b/tests/WebServices/Controllers/ResourceSaveControllerTest.php index f70ac9f20..b2fcb17a0 100644 --- a/tests/WebServices/Controllers/ResourceSaveControllerTest.php +++ b/tests/WebServices/Controllers/ResourceSaveControllerTest.php @@ -57,10 +57,15 @@ public function testAddsNewResource() $request->requiresApproval, $request->allowMultiday, $request->maxParticipants, - $request->minNotice, + $request->minNoticeAdd, $request->maxNotice, $request->description, - $request->scheduleId + $request->scheduleId, + minNoticeDelete: $request->minNoticeDelete, + minNoticeUpdate: $request->minNoticeUpdate, + bufferTime: $request->bufferTime, + groupIds: $request->groupIds, + resourceTypeId: $request->typeId ); $expectedUpdateResource->SetSortOrder($request->sortOrder); @@ -75,12 +80,12 @@ public function testAddsNewResource() $this->validator->expects($this->once()) ->method('ValidateCreateRequest') ->with($this->equalTo($request)) - ->will($this->returnValue([])); + ->willReturn([]); $this->repository->expects($this->once()) ->method('Add') ->with($this->equalTo($expectedCreateResource)) - ->will($this->returnValue($resourceId)); + ->willReturn($resourceId); $this->repository->expects($this->once()) ->method('Update') @@ -101,7 +106,7 @@ public function testWhenAddValidationFails() $this->validator->expects($this->once()) ->method('ValidateCreateRequest') ->with($this->anything()) - ->will($this->returnValue($errors)); + ->willReturn($errors); $response = $this->controller->Create($request, $this->session); @@ -126,10 +131,15 @@ public function testUpdatesResource() $request->requiresApproval, $request->allowMultiday, $request->maxParticipants, - $request->minNotice, + $request->minNoticeAdd, $request->maxNotice, $request->description, - $request->scheduleId + $request->scheduleId, + minNoticeDelete: $request->minNoticeDelete, + minNoticeUpdate: $request->minNoticeUpdate, + bufferTime: $request->bufferTime, + groupIds: $request->groupIds, + resourceTypeId: $request->typeId ); $expectedUpdateResource->SetSortOrder($request->sortOrder); @@ -144,12 +154,19 @@ public function testUpdatesResource() $this->validator->expects($this->once()) ->method('ValidateUpdateRequest') ->with($this->equalTo($resourceId), $this->equalTo($request)) - ->will($this->returnValue([])); + ->willReturn([]); $this->repository->expects($this->once()) ->method('Update') ->with($this->equalTo($expectedUpdateResource)); + $this->repository->expects($this->once()) + ->method('LoadById') + ->willReturnMap( + [ + [$resourceId, $expectedUpdateResource] + ]); + $response = $this->controller->Update($resourceId, $request, $this->session); $this->assertTrue($response->WasSuccessful()); @@ -166,7 +183,7 @@ public function testWhenUpdateValidationFails() $this->validator->expects($this->once()) ->method('ValidateUpdateRequest') ->with($this->anything(), $this->anything()) - ->will($this->returnValue($errors)); + ->willReturn($errors); $response = $this->controller->Update($resourceId, $request, $this->session); @@ -183,12 +200,12 @@ public function testDeletesResource() $this->validator->expects($this->once()) ->method('ValidateDeleteRequest') ->with($this->equalTo($resourceId)) - ->will($this->returnValue([])); + ->willReturn([]); $this->repository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($resourceId)) - ->will($this->returnValue($resource)); + ->willReturn($resource); $this->repository->expects($this->once()) ->method('Delete') @@ -209,7 +226,7 @@ public function testWhenDeleteFails() $this->validator->expects($this->once()) ->method('ValidateDeleteRequest') ->with($this->equalTo($resourceId)) - ->will($this->returnValue($errors)); + ->willReturn($errors); $response = $this->controller->Delete($resourceId, $this->session); diff --git a/tests/WebServices/Controllers/UserSaveControllerTest.php b/tests/WebServices/Controllers/UserSaveControllerTest.php index 1f2ffc3af..81ae66955 100644 --- a/tests/WebServices/Controllers/UserSaveControllerTest.php +++ b/tests/WebServices/Controllers/UserSaveControllerTest.php @@ -46,11 +46,11 @@ public function testCreatesNewUser() $this->requestValidator->expects($this->once()) ->method('ValidateCreateRequest') ->with($this->equalTo($request)) - ->will($this->returnValue(null)); + ->willReturn(null); $this->manageUserServiceFactory->expects($this->once()) ->method('CreateAdmin') - ->will($this->returnValue($this->manageUsersService)); + ->willReturn($this->manageUsersService); $this->manageUsersService->expects($this->once()) ->method('AddUser') @@ -69,7 +69,7 @@ public function testCreatesNewUser() $request->customAttributes[0]->attributeValue )]) ) - ->will($this->returnValue($createdUser)); + ->willReturn($createdUser); $result = $this->controller->Create($request, $session); @@ -88,7 +88,7 @@ public function testValidatesCreateRequest() $this->requestValidator->expects($this->once()) ->method('ValidateCreateRequest') ->with($this->equalTo($request)) - ->will($this->returnValue($errors)); + ->willReturn($errors); $result = $this->controller->Create($request, $session); @@ -106,11 +106,11 @@ public function testUpdatesUser() $this->requestValidator->expects($this->once()) ->method('ValidateUpdateRequest') ->with($this->equalTo($userId), $this->equalTo($request)) - ->will($this->returnValue(null)); + ->willReturn(null); $this->manageUserServiceFactory->expects($this->once()) ->method('CreateAdmin') - ->will($this->returnValue($this->manageUsersService)); + ->willReturn($this->manageUsersService); $this->manageUsersService->expects($this->once()) ->method('UpdateUser') @@ -127,7 +127,7 @@ public function testUpdatesUser() $request->customAttributes[0]->attributeValue )]) ) - ->will($this->returnValue($user)); + ->willReturn($user); $result = $this->controller->Update($userId, $request, $session); @@ -147,7 +147,7 @@ public function testValidatesUpdateRequest() $this->requestValidator->expects($this->once()) ->method('ValidateUpdateRequest') ->with($this->equalTo(1), $this->equalTo($request)) - ->will($this->returnValue($errors)); + ->willReturn($errors); $result = $this->controller->Update(1, $request, $session); @@ -162,7 +162,7 @@ public function testDeletesUser() $this->manageUserServiceFactory->expects($this->once()) ->method('CreateAdmin') - ->will($this->returnValue($this->manageUsersService)); + ->willReturn($this->manageUsersService); $this->manageUsersService->expects($this->once()) ->method('DeleteUser') @@ -182,11 +182,11 @@ public function testUpdatesUserPassword() $this->requestValidator->expects($this->once()) ->method('ValidateUpdatePasswordRequest') ->with($this->equalTo($userId), $this->equalTo($password)) - ->will($this->returnValue(null)); + ->willReturn(null); $this->manageUserServiceFactory->expects($this->once()) ->method('CreateAdmin') - ->will($this->returnValue($this->manageUsersService)); + ->willReturn($this->manageUsersService); $this->manageUsersService->expects($this->once()) ->method('UpdatePassword') diff --git a/tests/WebServices/GroupsWebServiceTest.php b/tests/WebServices/GroupsWebServiceTest.php index f41c6b89b..c4574c3f6 100644 --- a/tests/WebServices/GroupsWebServiceTest.php +++ b/tests/WebServices/GroupsWebServiceTest.php @@ -47,7 +47,7 @@ public function testGetsAllGroups() $this->groupViewRepository->expects($this->once()) ->method('GetList') ->with($this->isNull(), $this->isNull()) - ->will($this->returnValue($groups)); + ->willReturn($groups); $this->service->GetGroups(); @@ -63,7 +63,7 @@ public function testGetsASingleGroup() $this->groupRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($groupId)) - ->will($this->returnValue($group)); + ->willReturn($group); $expectedResponse = new GroupResponse($this->server, $group); @@ -78,7 +78,7 @@ public function testWhenGroupIsNotFound() $this->groupRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($groupId)) - ->will($this->returnValue(null)); + ->willReturn(null); $expectedResponse = RestResponse::NotFound(); diff --git a/tests/WebServices/ReservationWriteWebServiceTest.php b/tests/WebServices/ReservationWriteWebServiceTest.php index c0428015c..f98d51e7d 100644 --- a/tests/WebServices/ReservationWriteWebServiceTest.php +++ b/tests/WebServices/ReservationWriteWebServiceTest.php @@ -41,7 +41,7 @@ public function testCreatesNewReservation() $this->controller->expects($this->once()) ->method('Create') ->with($this->equalTo($reservationRequest), $this->equalTo($this->server->GetSession())) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Create(); @@ -69,7 +69,7 @@ public function testUpdatesExistingReservation() $this->equalTo($referenceNumber), $this->equalTo($updateScope) ) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Update($referenceNumber); @@ -92,7 +92,7 @@ public function testApprovesExistingReservation() $this->equalTo($this->server->GetSession()), $this->equalTo($referenceNumber) ) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Approve($referenceNumber); @@ -116,7 +116,7 @@ public function testDeletesExistingReservation() $this->equalTo($referenceNumber), $this->equalTo($updateScope) ) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Delete($referenceNumber); @@ -137,7 +137,7 @@ public function testWhenCreationValidationFails() $this->controller->expects($this->once()) ->method('Create') ->with($this->equalTo($reservationRequest), $this->equalTo($this->server->GetSession())) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Create(); @@ -159,7 +159,7 @@ public function testWhenUpdateValidationFails() $this->controller->expects($this->once()) ->method('Update') ->with($this->anything(), $this->anything(), $this->anything(), $this->anything()) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Update($referenceNumber); @@ -182,7 +182,7 @@ public function testWhenApproveValidationFails() $this->equalTo($this->server->GetSession()), $this->equalTo($referenceNumber) ) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Approve($referenceNumber); @@ -201,7 +201,7 @@ public function testWhenDeleteValidationFails() $this->controller->expects($this->once()) ->method('Delete') ->with($this->anything(), $this->anything(), $this->anything()) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Delete($referenceNumber); diff --git a/tests/WebServices/ReservationsWebServiceTest.php b/tests/WebServices/ReservationsWebServiceTest.php index a9b7546b1..c0887dde6 100644 --- a/tests/WebServices/ReservationsWebServiceTest.php +++ b/tests/WebServices/ReservationsWebServiceTest.php @@ -80,7 +80,7 @@ public function testDefaultsToNextTwoWeeks() $this->reservationViewRepository->expects($this->once()) ->method('GetReservations') ->with($this->equalTo($this->defaultStartDate), $this->equalTo($this->defaultEndDate)) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $this->service->GetReservations(); @@ -99,7 +99,7 @@ public function testWhenUserIdIsForAnotherUser() $this->reservationViewRepository->expects($this->once()) ->method('GetReservations') ->with($this->anything(), $this->anything(), $this->equalTo($userId)) - ->will($this->returnValue([])); + ->willReturn([]); $this->service->GetReservations(); } @@ -120,7 +120,7 @@ public function testWhenResourceIdIsProvided() $this->isNull(), $this->equalTo($resourceId) ) - ->will($this->returnValue([])); + ->willReturn([]); $this->service->GetReservations(); } @@ -141,7 +141,7 @@ public function testWhenScheduleIdIsProvided() $this->equalTo($scheduleId), $this->isNull() ) - ->will($this->returnValue([])); + ->willReturn([]); $this->service->GetReservations(); } @@ -158,12 +158,12 @@ public function testLoadsASingleReservation() $this->reservationViewRepository->expects($this->once()) ->method('GetReservationForEditing') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($reservation)); + ->willReturn($reservation); $this->attributeService->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo(CustomAttributeCategory::RESERVATION)) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $this->service->GetReservation($referenceNumber); @@ -181,7 +181,7 @@ public function testWhenReservationIsNotFound() $this->reservationViewRepository->expects($this->once()) ->method('GetReservationForEditing') ->with($this->equalTo($referenceNumber)) - ->will($this->returnValue($reservation)); + ->willReturn($reservation); $this->service->GetReservation($referenceNumber); diff --git a/tests/WebServices/ResourcesWebServiceTest.php b/tests/WebServices/ResourcesWebServiceTest.php index e7bdbb903..f334aef55 100644 --- a/tests/WebServices/ResourcesWebServiceTest.php +++ b/tests/WebServices/ResourcesWebServiceTest.php @@ -52,7 +52,11 @@ public function testGetsResourceById() $this->repository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($resourceId)) - ->will($this->returnValue($resource)); + ->willReturn($resource); + + $this->repository->expects($this->once()) + ->method('GetUserResourceIdList') + ->willReturn([$resourceId]); $this->attributeService->expects($this->once()) ->method('GetAttributes') @@ -60,7 +64,7 @@ public function testGetsResourceById() $this->equalTo(CustomAttributeCategory::RESOURCE), $this->equalTo([$resourceId]) ) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $this->service->GetResource($resourceId); @@ -73,7 +77,11 @@ public function testWhenNotFound() $this->repository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($resourceId)) - ->will($this->returnValue(BookableResource::Null())); + ->willReturn(BookableResource::Null()); + + $this->repository->expects($this->once()) + ->method('GetUserResourceIdList') + ->willReturn([$resourceId]); $this->service->GetResource($resourceId); @@ -87,8 +95,8 @@ public function testGetsResourceList() $attributes = new AttributeList(); $this->repository->expects($this->once()) - ->method('GetResourceList') - ->will($this->returnValue($resources)); + ->method('GetUserResourceList') + ->willReturn($resources); $this->attributeService->expects($this->once()) ->method('GetAttributes') @@ -96,7 +104,7 @@ public function testGetsResourceList() $this->equalTo(CustomAttributeCategory::RESOURCE), $this->equalTo([$resourceId]) ) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $this->service->GetAll(); @@ -119,7 +127,7 @@ public function testGetsStatusReasons() $this->repository->expects($this->once()) ->method('GetStatusReasons') - ->will($this->returnValue($reasons)); + ->willReturn($reasons); $this->service->GetStatusReasons(); @@ -137,8 +145,8 @@ public function testGetsAllResourceAvailability() $resources = [new FakeBookableResource($resourceId1), new FakeBookableResource($resourceId2), new FakeBookableResource($resourceId3)]; $this->repository->expects($this->once()) - ->method('GetResourceList') - ->will($this->returnValue($resources)); + ->method('GetUserResourceList') + ->willReturn($resources); $conflicting = new TestReservationItemView(1, $startTime, $endTime, $resourceId1); $upcoming = new TestReservationItemView(2, $endTime, $endTime->AddHours(3), $resourceId1); @@ -148,11 +156,10 @@ public function testGetsAllResourceAvailability() $upcoming5 = new TestReservationItemView(6, $startTime, $endTime->AddHours(2), $resourceId3); $reservations = [$conflicting, $upcoming, $upcoming2, $upcoming3, $upcoming4, $upcoming5]; - $endDate = Date::Now()->AddDays(30); + $endDate = Date::Now()->AddDays(7); $this->reservationRepository->expects($this->once()) ->method('GetReservations') - ->with($this->equalTo(Date::Now()), $this->equalTo($endDate)) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $this->service->GetAvailability(); @@ -173,19 +180,19 @@ public function testGetsAllResourceAvailabilityForARequestTime() $resources = [new FakeBookableResource(1)]; $this->repository->expects($this->once()) - ->method('GetResourceList') - ->will($this->returnValue($resources)); + ->method('GetUserResourceList') + ->willReturn($resources); $reservations = []; - $endDate = $date->AddDays(30); + $endDate = $date->AddDays(7); $this->reservationRepository->expects($this->once()) ->method('GetReservations') ->with( $this->equalTo($date->ToUtc()), $this->equalTo($endDate->ToUtc()) ) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $this->service->GetAvailability(); } @@ -194,15 +201,20 @@ public function testGetsSingleResourceAvailability() { $resourceId1 = 1; $resource = new FakeBookableResource($resourceId1); + $this->server->SetQueryString(WebServiceQueryStringKeys::RESOURCE_ID, $resourceId1); $this->repository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($resourceId1)) - ->will($this->returnValue($resource)); + ->willReturn($resource); + + $this->repository->expects($this->once()) + ->method('GetUserResourceIdList') + ->willReturn([$resourceId1]); $reservations = []; - $endDate = Date::Now()->AddDays(30); + $endDate = Date::Now()->AddDays(7); $this->reservationRepository->expects($this->once()) ->method('GetReservations') ->with( @@ -213,7 +225,7 @@ public function testGetsSingleResourceAvailability() $this->isEmpty(), $this->equalTo($resourceId1) ) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $this->service->GetAvailability($resourceId1); } @@ -224,15 +236,20 @@ public function testGetsSingleResourceAvailabilityForARequestTime() $this->server->SetQueryString(WebServiceQueryStringKeys::DATE_TIME, $date->ToIso()); $resourceId1 = 1; $resource = new FakeBookableResource($resourceId1); + $this->server->SetQueryString(WebServiceQueryStringKeys::RESOURCE_ID, $resourceId1); $this->repository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($resourceId1)) - ->will($this->returnValue($resource)); + ->willReturn($resource); + + $this->repository->expects($this->once()) + ->method('GetUserResourceIdList') + ->willReturn([$resourceId1]); $reservations = []; - $endDate = $date->AddDays(30); + $endDate = $date->AddDays(7); $this->reservationRepository->expects($this->once()) ->method('GetReservations') ->with( @@ -243,7 +260,7 @@ public function testGetsSingleResourceAvailabilityForARequestTime() $this->isEmpty(), $this->equalTo($resourceId1) ) - ->will($this->returnValue($reservations)); + ->willReturn($reservations); $this->service->GetAvailability($resourceId1); } diff --git a/tests/WebServices/ResourcesWriteWebServiceTest.php b/tests/WebServices/ResourcesWriteWebServiceTest.php index 8aa186921..7d63da083 100644 --- a/tests/WebServices/ResourcesWriteWebServiceTest.php +++ b/tests/WebServices/ResourcesWriteWebServiceTest.php @@ -41,7 +41,7 @@ public function testCanCreateNewResource() $this->controller->expects($this->once()) ->method('Create') ->with($this->equalTo($request), $this->equalTo($this->server->GetSession())) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Create(); @@ -59,7 +59,7 @@ public function testFailedCreate() $this->controller->expects($this->once()) ->method('Create') ->with($this->equalTo($request), $this->equalTo($this->server->GetSession())) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Create(); @@ -83,7 +83,7 @@ public function testCanUpdateResource() $this->equalTo($request), $this->equalTo($this->server->GetSession()) ) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Update($resourceId); @@ -106,7 +106,7 @@ public function testFailedUpdate() $this->equalTo($request), $this->equalTo($this->server->GetSession()) ) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Update($resourceId); @@ -123,7 +123,7 @@ public function testCanDeleteResource() $this->controller->expects($this->once()) ->method('Delete') ->with($this->equalTo($resourceId), $this->equalTo($this->server->GetSession())) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Delete($resourceId); @@ -140,7 +140,7 @@ public function testFailedDelete() $this->controller->expects($this->once()) ->method('Delete') ->with($this->equalTo($resourceId), $this->equalTo($this->server->GetSession())) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Delete($resourceId); diff --git a/tests/WebServices/SchedulesWebServiceTest.php b/tests/WebServices/SchedulesWebServiceTest.php index 17f77fb3b..010591d7d 100644 --- a/tests/WebServices/SchedulesWebServiceTest.php +++ b/tests/WebServices/SchedulesWebServiceTest.php @@ -1,5 +1,8 @@ scheduleRepository->expects($this->once()) ->method('GetAll') - ->will($this->returnValue($schedules)); + ->willReturn($schedules); $this->service->GetSchedules(); @@ -59,12 +62,12 @@ public function testGetsScheduleById() $layout->expects($this->any()) ->method('GetLayout') ->with($this->anything()) - ->will($this->returnValue([])); + ->willReturn([]); $this->scheduleRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($scheduleId)) - ->will($this->returnValue($schedule)); + ->willReturn($schedule); $this->scheduleRepository->expects($this->once()) ->method('GetLayout') @@ -72,7 +75,7 @@ public function testGetsScheduleById() $this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory($this->server->GetSession()->Timezone)) ) - ->will($this->returnValue($layout)); + ->willReturn($layout); $this->service->GetSchedule($scheduleId); @@ -86,7 +89,7 @@ public function testWhenScheduleNotFound() $this->scheduleRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($scheduleId)) - ->will($this->returnValue(null)); + ->willReturn(null); $this->service->GetSchedule($scheduleId); @@ -115,34 +118,24 @@ public function testScheduleResponseReturnsLayoutForEachDayOfWeek() $periods6 = [new SchedulePeriod($date6, $date6)]; $periods7 = [new SchedulePeriod($date7, $date7)]; - $layout->expects($this->at(0)) - ->method('GetLayout') - ->with($this->equalTo($date1)) - ->will($this->returnValue($periods1)); - $layout->expects($this->at(1)) - ->method('GetLayout') - ->with($this->equalTo($date2)) - ->will($this->returnValue($periods2)); - $layout->expects($this->at(2)) - ->method('GetLayout') - ->with($this->equalTo($date3)) - ->will($this->returnValue($periods3)); - $layout->expects($this->at(3)) - ->method('GetLayout') - ->with($this->equalTo($date4)) - ->will($this->returnValue($periods4)); - $layout->expects($this->at(4)) - ->method('GetLayout') - ->with($this->equalTo($date5)) - ->will($this->returnValue($periods5)); - $layout->expects($this->at(5)) - ->method('GetLayout') - ->with($this->equalTo($date6)) - ->will($this->returnValue($periods6)); - $layout->expects($this->at(6)) + $matcher = $this->exactly(7); + $layout->expects($matcher) ->method('GetLayout') - ->with($this->equalTo($date7)) - ->will($this->returnValue($periods7)); + ->willReturnCallback(function($date) use ( + $periods1, $periods2, $periods3, $periods4, $periods5, + $periods6, $periods7, + $date1, $date2, $date3, $date4, $date5, $date6, $date7) { + return match (true) { + $this->equalTo($date1)->evaluate($date, returnResult: true) => $periods1, + $this->equalTo($date2)->evaluate($date, returnResult: true) => $periods2, + $this->equalTo($date3)->evaluate($date, returnResult: true) => $periods3, + $this->equalTo($date4)->evaluate($date, returnResult: true) => $periods4, + $this->equalTo($date5)->evaluate($date, returnResult: true) => $periods5, + $this->equalTo($date6)->evaluate($date, returnResult: true) => $periods6, + $this->equalTo($date7)->evaluate($date, returnResult: true) => $periods7, + default => throw new Exception('Unexpected date') + }; + }); $response = new ScheduleResponse($this->server, $schedule, $layout); diff --git a/tests/WebServices/UsersWebServiceTest.php b/tests/WebServices/UsersWebServiceTest.php index 822d38041..faeac4356 100644 --- a/tests/WebServices/UsersWebServiceTest.php +++ b/tests/WebServices/UsersWebServiceTest.php @@ -66,17 +66,17 @@ public function testGetsAllUsers() $this->userRepositoryFactory->expects($this->once()) ->method('Create') ->with($this->equalTo($this->server->GetSession())) - ->will($this->returnValue($this->userRepository)); + ->willReturn($this->userRepository); $this->userRepository->expects($this->once()) ->method('GetList') ->with($this->isNull(), $this->isNull(), $this->isNull(), $this->isNull(), $expectedFilter->GetFilter(), AccountStatus::ACTIVE) - ->will($this->returnValue($users)); + ->willReturn($users); $this->attributeService->expects($this->once()) ->method('GetByCategory') ->with($this->equalTo(CustomAttributeCategory::USER)) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $expectedResponse = new UsersResponse($this->server, $userList, [1=>'fakeCustomAttribute1', 2=>'fakeCustomAttribute2']); @@ -101,22 +101,20 @@ public function testGetsASingleUserIfAllowed() $this->userRepositoryFactory->expects($this->once()) ->method('Create') ->with($this->equalTo($this->server->GetSession())) - ->will($this->returnValue($this->userRepository)); + ->willReturn($this->userRepository); - $this->userRepository->expects($this->at(0)) + $this->userRepository->expects($this->exactly(2)) ->method('LoadById') - ->with($this->equalTo($userId)) - ->will($this->returnValue($user)); - - $this->userRepository->expects($this->at(1)) - ->method('LoadById') - ->with($this->equalTo($sessionUserId)) - ->will($this->returnValue($me)); + ->willReturnMap( + [ + [$userId, $user], + [$sessionUserId, $me] + ]); $this->attributeService->expects($this->once()) ->method('GetAttributes') ->with($this->equalTo(CustomAttributeCategory::USER), $this->equalTo([$userId])) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $expectedResponse = new UserResponse($this->server, $user, $attributes); @@ -137,17 +135,17 @@ public function testGetsASingleUserIfCurrentUserIdMatches() $this->userRepositoryFactory->expects($this->once()) ->method('Create') ->with($this->equalTo($this->server->GetSession())) - ->will($this->returnValue($this->userRepository)); + ->willReturn($this->userRepository); - $this->userRepository->expects($this->at(0)) + $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue($user)); + ->willReturn($user); $this->attributeService->expects($this->once()) ->method('GetAttributes') ->with($this->equalTo(CustomAttributeCategory::USER), $this->equalTo([$userId])) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $expectedResponse = new UserResponse($this->server, $user, $attributes); @@ -164,12 +162,12 @@ public function testWhenUserIsNotFound() $this->userRepositoryFactory->expects($this->once()) ->method('Create') ->with($this->equalTo($this->server->GetSession())) - ->will($this->returnValue($this->userRepository)); + ->willReturn($this->userRepository); - $this->userRepository->expects($this->at(0)) + $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue(User::Null())); + ->willReturn(User::Null()); $expectedResponse = RestResponse::NotFound(); @@ -194,22 +192,20 @@ public function testWhenNotAllowedToGetUser() $this->userRepositoryFactory->expects($this->once()) ->method('Create') ->with($this->equalTo($this->server->GetSession())) - ->will($this->returnValue($this->userRepository)); + ->willReturn($this->userRepository); - $this->userRepository->expects($this->at(0)) + $this->userRepository->expects($this->exactly(2)) ->method('LoadById') - ->with($this->equalTo($userId)) - ->will($this->returnValue($user)); - - $this->userRepository->expects($this->at(1)) - ->method('LoadById') - ->with($this->equalTo($sessionUserId)) - ->will($this->returnValue($me)); + ->willReturnMap( + [ + [$userId, $user], + [$sessionUserId, $me] + ]); $this->attributeService->expects($this->once()) ->method('GetAttributes') ->with($this->equalTo(CustomAttributeCategory::USER), $this->equalTo([$userId])) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $this->service->GetUser($userId); @@ -229,17 +225,17 @@ public function testWhenNotHidingUserDetails() $this->userRepositoryFactory->expects($this->once()) ->method('Create') ->with($this->equalTo($this->server->GetSession())) - ->will($this->returnValue($this->userRepository)); + ->willReturn($this->userRepository); - $this->userRepository->expects($this->at(0)) + $this->userRepository->expects($this->once()) ->method('LoadById') ->with($this->equalTo($userId)) - ->will($this->returnValue($user)); + ->willReturn($user); $this->attributeService->expects($this->once()) ->method('GetAttributes') ->with($this->equalTo(CustomAttributeCategory::USER), $this->equalTo([$userId])) - ->will($this->returnValue($attributes)); + ->willReturn($attributes); $expectedResponse = new UserResponse($this->server, $user, $attributes); diff --git a/tests/WebServices/UsersWriteWebServiceTest.php b/tests/WebServices/UsersWriteWebServiceTest.php index 12f15e04b..e740e07a3 100644 --- a/tests/WebServices/UsersWriteWebServiceTest.php +++ b/tests/WebServices/UsersWriteWebServiceTest.php @@ -43,7 +43,7 @@ public function testCanCreateNewUser() $this->controller->expects($this->once()) ->method('Create') ->with($this->equalTo($userRequest), $this->equalTo($this->server->GetSession())) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Create(); @@ -61,7 +61,7 @@ public function testFailedCreate() $this->controller->expects($this->once()) ->method('Create') ->with($this->equalTo($userRequest), $this->equalTo($this->server->GetSession())) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Create(); @@ -85,7 +85,7 @@ public function testCanUpdateUser() $this->equalTo($userRequest), $this->equalTo($this->server->GetSession()) ) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Update($userId); @@ -108,7 +108,7 @@ public function testFailedUpdate() $this->equalTo($userRequest), $this->equalTo($this->server->GetSession()) ) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Update($userId); @@ -125,7 +125,7 @@ public function testCanDeleteUser() $this->controller->expects($this->once()) ->method('Delete') ->with($this->equalTo($userId), $this->equalTo($this->server->GetSession())) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Delete($userId); @@ -142,7 +142,7 @@ public function testFailedDelete() $this->controller->expects($this->once()) ->method('Delete') ->with($this->equalTo($userId), $this->equalTo($this->server->GetSession())) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->Delete($userId); @@ -163,7 +163,7 @@ public function testCanUpdatePassword() $this->controller->expects($this->once()) ->method('UpdatePassword') ->with($this->equalTo($userId), $this->equalTo($password), $this->equalTo($this->server->GetSession())) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->UpdatePassword($userId); @@ -184,7 +184,7 @@ public function testFailedPasswordUpdate() $this->controller->expects($this->once()) ->method('UpdatePassword') ->with($this->equalTo($userId), $this->equalTo($password), $this->equalTo($this->server->GetSession())) - ->will($this->returnValue($controllerResult)); + ->willReturn($controllerResult); $this->service->UpdatePassword($userId); diff --git a/tests/WebServices/Validators/ResourceRequestValidatorTest.php b/tests/WebServices/Validators/ResourceRequestValidatorTest.php index bc8e0326d..610370781 100644 --- a/tests/WebServices/Validators/ResourceRequestValidatorTest.php +++ b/tests/WebServices/Validators/ResourceRequestValidatorTest.php @@ -59,7 +59,7 @@ public function testCustomAttributesAreValidated() $this->equalTo(CustomAttributeCategory::RESOURCE), $this->equalTo([new AttributeValue($request->customAttributes[0]->attributeId, $request->customAttributes[0]->attributeValue)]) ) - ->will($this->returnValue($result)); + ->willReturn($result); $createErrors = $this->validator->ValidateCreateRequest($request); $updateErrors = $this->validator->ValidateUpdateRequest(1, $request); diff --git a/tests/WebServices/Validators/UserRequestValidatorTest.php b/tests/WebServices/Validators/UserRequestValidatorTest.php index 1083f8da6..4da508a63 100644 --- a/tests/WebServices/Validators/UserRequestValidatorTest.php +++ b/tests/WebServices/Validators/UserRequestValidatorTest.php @@ -59,32 +59,21 @@ public function testCreateValidatesEmailFormat() $this->assertTrue(count($errors) == 1); } - public function testCreateValidatesExistingEmail() + public function testCreateValidatesExistingEmailAndUsername() { $this->expectsAttributeValidator(); $request = CreateUserRequest::Example(); - $this->userRepository->expects($this->at(0)) + $this->userRepository->expects($this->exactly(2)) ->method('UserExists') - ->with($this->equalTo($request->emailAddress), $this->isNull()) - ->will($this->returnValue(1)); + ->willReturnMap( + [ + [$request->emailAddress, null, 1], + [null, $request->userName, 1] + ]); $errors = $this->validator->ValidateCreateRequest($request); - $this->assertTrue(count($errors) == 1); - } - - public function testCreateValidatesExistingUsername() - { - $this->expectsAttributeValidator(); - $request = CreateUserRequest::Example(); - - $this->userRepository->expects($this->at(1)) - ->method('UserExists') - ->with($this->isNull(), $this->equalTo($request->userName)) - ->will($this->returnValue(1)); - - $errors = $this->validator->ValidateCreateRequest($request); - $this->assertTrue(count($errors) == 1); + $this->assertTrue(count($errors) == 2); } public function testCreateValidatesAttributes() @@ -97,7 +86,7 @@ public function testCreateValidatesAttributes() $this->equalTo(CustomAttributeCategory::USER), $this->equalTo([new AttributeValue($request->customAttributes[0]->attributeId, $request->customAttributes[0]->attributeValue)]) ) - ->will($this->returnValue($result)); + ->willReturn($result); $errors = $this->validator->ValidateCreateRequest($request); $this->assertTrue(count($errors) == 1); @@ -136,10 +125,13 @@ public function testUpdateValidatesExistingEmail() $this->expectsAttributeValidator(); $request = UpdateUserRequest::Example(); - $this->userRepository->expects($this->at(0)) + $this->userRepository->expects($this->exactly(2)) ->method('UserExists') - ->with($this->equalTo($request->emailAddress), $this->isNull()) - ->will($this->returnValue(2)); + ->willReturnMap( + [ + [$request->emailAddress, null, 2], + [null, $request->userName, 1] + ]); $errors = $this->validator->ValidateUpdateRequest(1, $request); $this->assertTrue(count($errors) == 1); @@ -150,10 +142,13 @@ public function testUpdateValidatesExistingUsername() $this->expectsAttributeValidator(); $request = UpdateUserRequest::Example(); - $this->userRepository->expects($this->at(1)) + $this->userRepository->expects($this->exactly(2)) ->method('UserExists') - ->with($this->isNull(), $this->equalTo($request->userName)) - ->will($this->returnValue(2)); + ->willReturnMap( + [ + [$request->emailAddress, null, 1], + [null, $request->userName, 2] + ]); $errors = $this->validator->ValidateUpdateRequest(1, $request); $this->assertTrue(count($errors) == 1); @@ -169,7 +164,7 @@ public function testUpdateValidatesAttributes() $this->equalTo(CustomAttributeCategory::USER), $this->equalTo([new AttributeValue($request->customAttributes[0]->attributeId, $request->customAttributes[0]->attributeValue)]) ) - ->will($this->returnValue($result)); + ->willReturn($result); $errors = $this->validator->ValidateUpdateRequest(1, $request); $this->assertTrue(count($errors) == 1); @@ -180,6 +175,6 @@ private function expectsAttributeValidator() $this->attributeService->expects($this->any()) ->method('Validate') ->with($this->anything(), $this->anything()) - ->will($this->returnValue(new AttributeServiceValidationResult(true, null))); + ->willReturn(new AttributeServiceValidationResult(true, null)); } } diff --git a/tests/fakes/FakePaymentRepository.php b/tests/fakes/FakePaymentRepository.php index bac291e9b..bb5cb3c4b 100644 --- a/tests/fakes/FakePaymentRepository.php +++ b/tests/fakes/FakePaymentRepository.php @@ -45,12 +45,15 @@ public function __construct() { $this->_PayPal = new FakePayPalGateway(); $this->_Stripe = new FakeStripeGateway(); - $this->_CreditCost = new CreditCost(); + $this->_CreditCost = [new CreditCost()]; } public function DeleteCreditCost($creditCount) { } - public function GetCreditCosts() { } + public function GetCreditCosts() + { + return $this->_CreditCost; + } public function UpdateCreditCost($cost) { diff --git a/tests/fakes/FakeResourceAccess.php b/tests/fakes/FakeResourceAccess.php index 4206fac51..4da4cb92c 100644 --- a/tests/fakes/FakeResourceAccess.php +++ b/tests/fakes/FakeResourceAccess.php @@ -30,7 +30,7 @@ public function LoadByName($name) private function FillRows() { - $rows = $this->GetRows(); + $rows = $this->BuildRows(); foreach ($rows as $row) { $this->_Resources[] = BookableResource::Create($row); } @@ -115,7 +115,7 @@ public function With( return $this; } - public function GetRows() + private function BuildRows() { $this->With( 1, From 163b15353f6ea113a6886b4dc4d58972bd6a9789 Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Sun, 1 Sep 2024 09:52:13 +0000 Subject: [PATCH 6/6] Run tests in workflow --- .github/workflows/lint-and-analyse-php.yml | 35 +++++++++++++++++++++- composer.json | 3 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-and-analyse-php.yml b/.github/workflows/lint-and-analyse-php.yml index b9abd655d..aaf141fe4 100644 --- a/.github/workflows/lint-and-analyse-php.yml +++ b/.github/workflows/lint-and-analyse-php.yml @@ -17,6 +17,39 @@ permissions: contents: read jobs: + phpunit: + runs-on: ubuntu-latest + strategy: + matrix: + php-version: ["8.2", "8.3"] + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + + - name: Set up PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + + - name: Install Composer dependencies + # Allow the previous check to fail but not abort + if: always() + uses: ramsey/composer-install@v2 + with: + # Ignore zip for php-webdriver/webdriver + composer-options: "--ignore-platform-req=ext-zip" + + - name: Create config.php for unit tests + run: cp config/config.dist.php config/config.php + + - name: Unit Tests + run: composer phpunit + lint-php-files: runs-on: ubuntu-latest strategy: @@ -41,7 +74,7 @@ jobs: uses: ramsey/composer-install@v2 with: # Ignore zip for php-webdriver/webdriver - composer-options: "--ignore-platform-req=ext-zip" + composer-options: "--ignore-platform-reqs" # TODO: Enable this after resolving issues # - name: Cache coding-standard diff --git a/composer.json b/composer.json index 7bb3ad5c8..813b72a78 100644 --- a/composer.json +++ b/composer.json @@ -36,8 +36,9 @@ "build": "./tools/phing", "fix": "./tools/php-cs-fixer fix -v", "lint": "./tools/php-cs-fixer fix -vv --dry-run", + "phpunit": "./vendor/bin/phpunit", "test": [ - "./vendor/bin/phpunit", + "@phpunit", "@lint" ], "sniffer:php8": "phpcs -p ./ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --report-full=./php8-report.log --ignore=./vendor/*,./tools/*,./.git/*,./tpl_c/*,./build/*,./.phpdoc/*,./var/*,./Web/scripts/*,./Web/css/* --runtime-set testVersion 8.0"