| @@ 166-200 (lines=35) @@ | ||
| 163 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 164 | } |
|
| 165 | ||
| 166 | public function testReturnCopyContentResultInBeforeEvents() |
|
| 167 | { |
|
| 168 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 169 | ContentEvents::BEFORE_COPY_CONTENT, |
|
| 170 | ContentEvents::COPY_CONTENT |
|
| 171 | ); |
|
| 172 | ||
| 173 | $parameters = [ |
|
| 174 | $this->createMock(ContentInfo::class), |
|
| 175 | $this->createMock(LocationCreateStruct::class), |
|
| 176 | $this->createMock(VersionInfo::class), |
|
| 177 | ]; |
|
| 178 | ||
| 179 | $content = $this->createMock(Content::class); |
|
| 180 | $eventContent = $this->createMock(Content::class); |
|
| 181 | $innerServiceMock = $this->createMock(ContentServiceInterface::class); |
|
| 182 | $innerServiceMock->method('copyContent')->willReturn($content); |
|
| 183 | ||
| 184 | $traceableEventDispatcher->addListener(ContentEvents::BEFORE_COPY_CONTENT, function (BeforeCopyContentEvent $event) use ($eventContent) { |
|
| 185 | $event->setContent($eventContent); |
|
| 186 | }, 10); |
|
| 187 | ||
| 188 | $service = new ContentService($innerServiceMock, $traceableEventDispatcher); |
|
| 189 | $result = $service->copyContent(...$parameters); |
|
| 190 | ||
| 191 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 192 | ||
| 193 | $this->assertSame($eventContent, $result); |
|
| 194 | $this->assertSame($calledListeners, [ |
|
| 195 | [ContentEvents::BEFORE_COPY_CONTENT, 10], |
|
| 196 | [ContentEvents::BEFORE_COPY_CONTENT, 0], |
|
| 197 | [ContentEvents::COPY_CONTENT, 0], |
|
| 198 | ]); |
|
| 199 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 200 | } |
|
| 201 | ||
| 202 | public function testCopyContentStopPropagationInBeforeEvents() |
|
| 203 | { |
|
| @@ 270-303 (lines=34) @@ | ||
| 267 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 268 | } |
|
| 269 | ||
| 270 | public function testReturnUpdateContentResultInBeforeEvents() |
|
| 271 | { |
|
| 272 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 273 | ContentEvents::BEFORE_UPDATE_CONTENT, |
|
| 274 | ContentEvents::UPDATE_CONTENT |
|
| 275 | ); |
|
| 276 | ||
| 277 | $parameters = [ |
|
| 278 | $this->createMock(VersionInfo::class), |
|
| 279 | $this->createMock(ContentUpdateStruct::class), |
|
| 280 | ]; |
|
| 281 | ||
| 282 | $content = $this->createMock(Content::class); |
|
| 283 | $eventContent = $this->createMock(Content::class); |
|
| 284 | $innerServiceMock = $this->createMock(ContentServiceInterface::class); |
|
| 285 | $innerServiceMock->method('updateContent')->willReturn($content); |
|
| 286 | ||
| 287 | $traceableEventDispatcher->addListener(ContentEvents::BEFORE_UPDATE_CONTENT, function (BeforeUpdateContentEvent $event) use ($eventContent) { |
|
| 288 | $event->setContent($eventContent); |
|
| 289 | }, 10); |
|
| 290 | ||
| 291 | $service = new ContentService($innerServiceMock, $traceableEventDispatcher); |
|
| 292 | $result = $service->updateContent(...$parameters); |
|
| 293 | ||
| 294 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 295 | ||
| 296 | $this->assertSame($eventContent, $result); |
|
| 297 | $this->assertSame($calledListeners, [ |
|
| 298 | [ContentEvents::BEFORE_UPDATE_CONTENT, 10], |
|
| 299 | [ContentEvents::BEFORE_UPDATE_CONTENT, 0], |
|
| 300 | [ContentEvents::UPDATE_CONTENT, 0], |
|
| 301 | ]); |
|
| 302 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 303 | } |
|
| 304 | ||
| 305 | public function testUpdateContentStopPropagationInBeforeEvents() |
|
| 306 | { |
|
| @@ 647-680 (lines=34) @@ | ||
| 644 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 645 | } |
|
| 646 | ||
| 647 | public function testReturnAddRelationResultInBeforeEvents() |
|
| 648 | { |
|
| 649 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 650 | ContentEvents::BEFORE_ADD_RELATION, |
|
| 651 | ContentEvents::ADD_RELATION |
|
| 652 | ); |
|
| 653 | ||
| 654 | $parameters = [ |
|
| 655 | $this->createMock(VersionInfo::class), |
|
| 656 | $this->createMock(ContentInfo::class), |
|
| 657 | ]; |
|
| 658 | ||
| 659 | $relation = $this->createMock(Relation::class); |
|
| 660 | $eventRelation = $this->createMock(Relation::class); |
|
| 661 | $innerServiceMock = $this->createMock(ContentServiceInterface::class); |
|
| 662 | $innerServiceMock->method('addRelation')->willReturn($relation); |
|
| 663 | ||
| 664 | $traceableEventDispatcher->addListener(ContentEvents::BEFORE_ADD_RELATION, function (BeforeAddRelationEvent $event) use ($eventRelation) { |
|
| 665 | $event->setRelation($eventRelation); |
|
| 666 | }, 10); |
|
| 667 | ||
| 668 | $service = new ContentService($innerServiceMock, $traceableEventDispatcher); |
|
| 669 | $result = $service->addRelation(...$parameters); |
|
| 670 | ||
| 671 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 672 | ||
| 673 | $this->assertSame($eventRelation, $result); |
|
| 674 | $this->assertSame($calledListeners, [ |
|
| 675 | [ContentEvents::BEFORE_ADD_RELATION, 10], |
|
| 676 | [ContentEvents::BEFORE_ADD_RELATION, 0], |
|
| 677 | [ContentEvents::ADD_RELATION, 0], |
|
| 678 | ]); |
|
| 679 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 680 | } |
|
| 681 | ||
| 682 | public function testAddRelationStopPropagationInBeforeEvents() |
|
| 683 | { |
|
| @@ 749-782 (lines=34) @@ | ||
| 746 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 747 | } |
|
| 748 | ||
| 749 | public function testReturnUpdateContentMetadataResultInBeforeEvents() |
|
| 750 | { |
|
| 751 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 752 | ContentEvents::BEFORE_UPDATE_CONTENT_METADATA, |
|
| 753 | ContentEvents::UPDATE_CONTENT_METADATA |
|
| 754 | ); |
|
| 755 | ||
| 756 | $parameters = [ |
|
| 757 | $this->createMock(ContentInfo::class), |
|
| 758 | $this->createMock(ContentMetadataUpdateStruct::class), |
|
| 759 | ]; |
|
| 760 | ||
| 761 | $content = $this->createMock(Content::class); |
|
| 762 | $eventContent = $this->createMock(Content::class); |
|
| 763 | $innerServiceMock = $this->createMock(ContentServiceInterface::class); |
|
| 764 | $innerServiceMock->method('updateContentMetadata')->willReturn($content); |
|
| 765 | ||
| 766 | $traceableEventDispatcher->addListener(ContentEvents::BEFORE_UPDATE_CONTENT_METADATA, function (BeforeUpdateContentMetadataEvent $event) use ($eventContent) { |
|
| 767 | $event->setContent($eventContent); |
|
| 768 | }, 10); |
|
| 769 | ||
| 770 | $service = new ContentService($innerServiceMock, $traceableEventDispatcher); |
|
| 771 | $result = $service->updateContentMetadata(...$parameters); |
|
| 772 | ||
| 773 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 774 | ||
| 775 | $this->assertSame($eventContent, $result); |
|
| 776 | $this->assertSame($calledListeners, [ |
|
| 777 | [ContentEvents::BEFORE_UPDATE_CONTENT_METADATA, 10], |
|
| 778 | [ContentEvents::BEFORE_UPDATE_CONTENT_METADATA, 0], |
|
| 779 | [ContentEvents::UPDATE_CONTENT_METADATA, 0], |
|
| 780 | ]); |
|
| 781 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 782 | } |
|
| 783 | ||
| 784 | public function testUpdateContentMetadataStopPropagationInBeforeEvents() |
|
| 785 | { |
|
| @@ 1010-1044 (lines=35) @@ | ||
| 1007 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 1008 | } |
|
| 1009 | ||
| 1010 | public function testReturnCreateContentDraftResultInBeforeEvents() |
|
| 1011 | { |
|
| 1012 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 1013 | ContentEvents::BEFORE_CREATE_CONTENT_DRAFT, |
|
| 1014 | ContentEvents::CREATE_CONTENT_DRAFT |
|
| 1015 | ); |
|
| 1016 | ||
| 1017 | $parameters = [ |
|
| 1018 | $this->createMock(ContentInfo::class), |
|
| 1019 | $this->createMock(VersionInfo::class), |
|
| 1020 | $this->createMock(User::class), |
|
| 1021 | ]; |
|
| 1022 | ||
| 1023 | $contentDraft = $this->createMock(Content::class); |
|
| 1024 | $eventContentDraft = $this->createMock(Content::class); |
|
| 1025 | $innerServiceMock = $this->createMock(ContentServiceInterface::class); |
|
| 1026 | $innerServiceMock->method('createContentDraft')->willReturn($contentDraft); |
|
| 1027 | ||
| 1028 | $traceableEventDispatcher->addListener(ContentEvents::BEFORE_CREATE_CONTENT_DRAFT, function (BeforeCreateContentDraftEvent $event) use ($eventContentDraft) { |
|
| 1029 | $event->setContentDraft($eventContentDraft); |
|
| 1030 | }, 10); |
|
| 1031 | ||
| 1032 | $service = new ContentService($innerServiceMock, $traceableEventDispatcher); |
|
| 1033 | $result = $service->createContentDraft(...$parameters); |
|
| 1034 | ||
| 1035 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 1036 | ||
| 1037 | $this->assertSame($eventContentDraft, $result); |
|
| 1038 | $this->assertSame($calledListeners, [ |
|
| 1039 | [ContentEvents::BEFORE_CREATE_CONTENT_DRAFT, 10], |
|
| 1040 | [ContentEvents::BEFORE_CREATE_CONTENT_DRAFT, 0], |
|
| 1041 | [ContentEvents::CREATE_CONTENT_DRAFT, 0], |
|
| 1042 | ]); |
|
| 1043 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 1044 | } |
|
| 1045 | ||
| 1046 | public function testCreateContentDraftStopPropagationInBeforeEvents() |
|
| 1047 | { |
|
| @@ 1058-1091 (lines=34) @@ | ||
| 1055 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 1056 | } |
|
| 1057 | ||
| 1058 | public function testReturnCopyContentTypeResultInBeforeEvents() |
|
| 1059 | { |
|
| 1060 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 1061 | ContentTypeEvents::BEFORE_COPY_CONTENT_TYPE, |
|
| 1062 | ContentTypeEvents::COPY_CONTENT_TYPE |
|
| 1063 | ); |
|
| 1064 | ||
| 1065 | $parameters = [ |
|
| 1066 | $this->createMock(ContentType::class), |
|
| 1067 | $this->createMock(User::class), |
|
| 1068 | ]; |
|
| 1069 | ||
| 1070 | $contentTypeCopy = $this->createMock(ContentType::class); |
|
| 1071 | $eventContentTypeCopy = $this->createMock(ContentType::class); |
|
| 1072 | $innerServiceMock = $this->createMock(ContentTypeServiceInterface::class); |
|
| 1073 | $innerServiceMock->method('copyContentType')->willReturn($contentTypeCopy); |
|
| 1074 | ||
| 1075 | $traceableEventDispatcher->addListener(ContentTypeEvents::BEFORE_COPY_CONTENT_TYPE, function (BeforeCopyContentTypeEvent $event) use ($eventContentTypeCopy) { |
|
| 1076 | $event->setContentTypeCopy($eventContentTypeCopy); |
|
| 1077 | }, 10); |
|
| 1078 | ||
| 1079 | $service = new ContentTypeService($innerServiceMock, $traceableEventDispatcher); |
|
| 1080 | $result = $service->copyContentType(...$parameters); |
|
| 1081 | ||
| 1082 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 1083 | ||
| 1084 | $this->assertSame($eventContentTypeCopy, $result); |
|
| 1085 | $this->assertSame($calledListeners, [ |
|
| 1086 | [ContentTypeEvents::BEFORE_COPY_CONTENT_TYPE, 10], |
|
| 1087 | [ContentTypeEvents::BEFORE_COPY_CONTENT_TYPE, 0], |
|
| 1088 | [ContentTypeEvents::COPY_CONTENT_TYPE, 0], |
|
| 1089 | ]); |
|
| 1090 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 1091 | } |
|
| 1092 | ||
| 1093 | public function testCopyContentTypeStopPropagationInBeforeEvents() |
|
| 1094 | { |
|
| @@ 56-89 (lines=34) @@ | ||
| 53 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 54 | } |
|
| 55 | ||
| 56 | public function testReturnCopySubtreeResultInBeforeEvents() |
|
| 57 | { |
|
| 58 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 59 | LocationEvents::BEFORE_COPY_SUBTREE, |
|
| 60 | LocationEvents::COPY_SUBTREE |
|
| 61 | ); |
|
| 62 | ||
| 63 | $parameters = [ |
|
| 64 | $this->createMock(Location::class), |
|
| 65 | $this->createMock(Location::class), |
|
| 66 | ]; |
|
| 67 | ||
| 68 | $location = $this->createMock(Location::class); |
|
| 69 | $eventLocation = $this->createMock(Location::class); |
|
| 70 | $innerServiceMock = $this->createMock(LocationServiceInterface::class); |
|
| 71 | $innerServiceMock->method('copySubtree')->willReturn($location); |
|
| 72 | ||
| 73 | $traceableEventDispatcher->addListener(LocationEvents::BEFORE_COPY_SUBTREE, function (BeforeCopySubtreeEvent $event) use ($eventLocation) { |
|
| 74 | $event->setLocation($eventLocation); |
|
| 75 | }, 10); |
|
| 76 | ||
| 77 | $service = new LocationService($innerServiceMock, $traceableEventDispatcher); |
|
| 78 | $result = $service->copySubtree(...$parameters); |
|
| 79 | ||
| 80 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 81 | ||
| 82 | $this->assertSame($eventLocation, $result); |
|
| 83 | $this->assertSame($calledListeners, [ |
|
| 84 | [LocationEvents::BEFORE_COPY_SUBTREE, 10], |
|
| 85 | [LocationEvents::BEFORE_COPY_SUBTREE, 0], |
|
| 86 | [LocationEvents::COPY_SUBTREE, 0], |
|
| 87 | ]); |
|
| 88 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 89 | } |
|
| 90 | ||
| 91 | public function testCopySubtreeStopPropagationInBeforeEvents() |
|
| 92 | { |
|
| @@ 531-564 (lines=34) @@ | ||
| 528 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 529 | } |
|
| 530 | ||
| 531 | public function testReturnUpdateLocationResultInBeforeEvents() |
|
| 532 | { |
|
| 533 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 534 | LocationEvents::BEFORE_UPDATE_LOCATION, |
|
| 535 | LocationEvents::UPDATE_LOCATION |
|
| 536 | ); |
|
| 537 | ||
| 538 | $parameters = [ |
|
| 539 | $this->createMock(Location::class), |
|
| 540 | $this->createMock(LocationUpdateStruct::class), |
|
| 541 | ]; |
|
| 542 | ||
| 543 | $updatedLocation = $this->createMock(Location::class); |
|
| 544 | $eventUpdatedLocation = $this->createMock(Location::class); |
|
| 545 | $innerServiceMock = $this->createMock(LocationServiceInterface::class); |
|
| 546 | $innerServiceMock->method('updateLocation')->willReturn($updatedLocation); |
|
| 547 | ||
| 548 | $traceableEventDispatcher->addListener(LocationEvents::BEFORE_UPDATE_LOCATION, function (BeforeUpdateLocationEvent $event) use ($eventUpdatedLocation) { |
|
| 549 | $event->setUpdatedLocation($eventUpdatedLocation); |
|
| 550 | }, 10); |
|
| 551 | ||
| 552 | $service = new LocationService($innerServiceMock, $traceableEventDispatcher); |
|
| 553 | $result = $service->updateLocation(...$parameters); |
|
| 554 | ||
| 555 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 556 | ||
| 557 | $this->assertSame($eventUpdatedLocation, $result); |
|
| 558 | $this->assertSame($calledListeners, [ |
|
| 559 | [LocationEvents::BEFORE_UPDATE_LOCATION, 10], |
|
| 560 | [LocationEvents::BEFORE_UPDATE_LOCATION, 0], |
|
| 561 | [LocationEvents::UPDATE_LOCATION, 0], |
|
| 562 | ]); |
|
| 563 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 564 | } |
|
| 565 | ||
| 566 | public function testUpdateLocationStopPropagationInBeforeEvents() |
|
| 567 | { |
|
| @@ 633-666 (lines=34) @@ | ||
| 630 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 631 | } |
|
| 632 | ||
| 633 | public function testReturnCreateLocationResultInBeforeEvents() |
|
| 634 | { |
|
| 635 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 636 | LocationEvents::BEFORE_CREATE_LOCATION, |
|
| 637 | LocationEvents::CREATE_LOCATION |
|
| 638 | ); |
|
| 639 | ||
| 640 | $parameters = [ |
|
| 641 | $this->createMock(ContentInfo::class), |
|
| 642 | $this->createMock(LocationCreateStruct::class), |
|
| 643 | ]; |
|
| 644 | ||
| 645 | $location = $this->createMock(Location::class); |
|
| 646 | $eventLocation = $this->createMock(Location::class); |
|
| 647 | $innerServiceMock = $this->createMock(LocationServiceInterface::class); |
|
| 648 | $innerServiceMock->method('createLocation')->willReturn($location); |
|
| 649 | ||
| 650 | $traceableEventDispatcher->addListener(LocationEvents::BEFORE_CREATE_LOCATION, function (BeforeCreateLocationEvent $event) use ($eventLocation) { |
|
| 651 | $event->setLocation($eventLocation); |
|
| 652 | }, 10); |
|
| 653 | ||
| 654 | $service = new LocationService($innerServiceMock, $traceableEventDispatcher); |
|
| 655 | $result = $service->createLocation(...$parameters); |
|
| 656 | ||
| 657 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 658 | ||
| 659 | $this->assertSame($eventLocation, $result); |
|
| 660 | $this->assertSame($calledListeners, [ |
|
| 661 | [LocationEvents::BEFORE_CREATE_LOCATION, 10], |
|
| 662 | [LocationEvents::BEFORE_CREATE_LOCATION, 0], |
|
| 663 | [LocationEvents::CREATE_LOCATION, 0], |
|
| 664 | ]); |
|
| 665 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 666 | } |
|
| 667 | ||
| 668 | public function testCreateLocationStopPropagationInBeforeEvents() |
|
| 669 | { |
|
| @@ 219-252 (lines=34) @@ | ||
| 216 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 217 | } |
|
| 218 | ||
| 219 | public function testReturnUpdateObjectStateResultInBeforeEvents() |
|
| 220 | { |
|
| 221 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 222 | ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE, |
|
| 223 | ObjectStateEvents::UPDATE_OBJECT_STATE |
|
| 224 | ); |
|
| 225 | ||
| 226 | $parameters = [ |
|
| 227 | $this->createMock(ObjectState::class), |
|
| 228 | $this->createMock(ObjectStateUpdateStruct::class), |
|
| 229 | ]; |
|
| 230 | ||
| 231 | $updatedObjectState = $this->createMock(ObjectState::class); |
|
| 232 | $eventUpdatedObjectState = $this->createMock(ObjectState::class); |
|
| 233 | $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class); |
|
| 234 | $innerServiceMock->method('updateObjectState')->willReturn($updatedObjectState); |
|
| 235 | ||
| 236 | $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE, function (BeforeUpdateObjectStateEvent $event) use ($eventUpdatedObjectState) { |
|
| 237 | $event->setUpdatedObjectState($eventUpdatedObjectState); |
|
| 238 | }, 10); |
|
| 239 | ||
| 240 | $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher); |
|
| 241 | $result = $service->updateObjectState(...$parameters); |
|
| 242 | ||
| 243 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 244 | ||
| 245 | $this->assertSame($eventUpdatedObjectState, $result); |
|
| 246 | $this->assertSame($calledListeners, [ |
|
| 247 | [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE, 10], |
|
| 248 | [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE, 0], |
|
| 249 | [ObjectStateEvents::UPDATE_OBJECT_STATE, 0], |
|
| 250 | ]); |
|
| 251 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 252 | } |
|
| 253 | ||
| 254 | public function testUpdateObjectStateStopPropagationInBeforeEvents() |
|
| 255 | { |
|
| @@ 321-354 (lines=34) @@ | ||
| 318 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 319 | } |
|
| 320 | ||
| 321 | public function testReturnCreateObjectStateResultInBeforeEvents() |
|
| 322 | { |
|
| 323 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 324 | ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE, |
|
| 325 | ObjectStateEvents::CREATE_OBJECT_STATE |
|
| 326 | ); |
|
| 327 | ||
| 328 | $parameters = [ |
|
| 329 | $this->createMock(ObjectStateGroup::class), |
|
| 330 | $this->createMock(ObjectStateCreateStruct::class), |
|
| 331 | ]; |
|
| 332 | ||
| 333 | $objectState = $this->createMock(ObjectState::class); |
|
| 334 | $eventObjectState = $this->createMock(ObjectState::class); |
|
| 335 | $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class); |
|
| 336 | $innerServiceMock->method('createObjectState')->willReturn($objectState); |
|
| 337 | ||
| 338 | $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE, function (BeforeCreateObjectStateEvent $event) use ($eventObjectState) { |
|
| 339 | $event->setObjectState($eventObjectState); |
|
| 340 | }, 10); |
|
| 341 | ||
| 342 | $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher); |
|
| 343 | $result = $service->createObjectState(...$parameters); |
|
| 344 | ||
| 345 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 346 | ||
| 347 | $this->assertSame($eventObjectState, $result); |
|
| 348 | $this->assertSame($calledListeners, [ |
|
| 349 | [ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE, 10], |
|
| 350 | [ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE, 0], |
|
| 351 | [ObjectStateEvents::CREATE_OBJECT_STATE, 0], |
|
| 352 | ]); |
|
| 353 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 354 | } |
|
| 355 | ||
| 356 | public function testCreateObjectStateStopPropagationInBeforeEvents() |
|
| 357 | { |
|
| @@ 423-456 (lines=34) @@ | ||
| 420 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 421 | } |
|
| 422 | ||
| 423 | public function testReturnUpdateObjectStateGroupResultInBeforeEvents() |
|
| 424 | { |
|
| 425 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 426 | ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP, |
|
| 427 | ObjectStateEvents::UPDATE_OBJECT_STATE_GROUP |
|
| 428 | ); |
|
| 429 | ||
| 430 | $parameters = [ |
|
| 431 | $this->createMock(ObjectStateGroup::class), |
|
| 432 | $this->createMock(ObjectStateGroupUpdateStruct::class), |
|
| 433 | ]; |
|
| 434 | ||
| 435 | $updatedObjectStateGroup = $this->createMock(ObjectStateGroup::class); |
|
| 436 | $eventUpdatedObjectStateGroup = $this->createMock(ObjectStateGroup::class); |
|
| 437 | $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class); |
|
| 438 | $innerServiceMock->method('updateObjectStateGroup')->willReturn($updatedObjectStateGroup); |
|
| 439 | ||
| 440 | $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP, function (BeforeUpdateObjectStateGroupEvent $event) use ($eventUpdatedObjectStateGroup) { |
|
| 441 | $event->setUpdatedObjectStateGroup($eventUpdatedObjectStateGroup); |
|
| 442 | }, 10); |
|
| 443 | ||
| 444 | $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher); |
|
| 445 | $result = $service->updateObjectStateGroup(...$parameters); |
|
| 446 | ||
| 447 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 448 | ||
| 449 | $this->assertSame($eventUpdatedObjectStateGroup, $result); |
|
| 450 | $this->assertSame($calledListeners, [ |
|
| 451 | [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP, 10], |
|
| 452 | [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP, 0], |
|
| 453 | [ObjectStateEvents::UPDATE_OBJECT_STATE_GROUP, 0], |
|
| 454 | ]); |
|
| 455 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 456 | } |
|
| 457 | ||
| 458 | public function testUpdateObjectStateGroupStopPropagationInBeforeEvents() |
|
| 459 | { |
|
| @@ 131-164 (lines=34) @@ | ||
| 128 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 129 | } |
|
| 130 | ||
| 131 | public function testReturnUpdateRoleResultInBeforeEvents() |
|
| 132 | { |
|
| 133 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 134 | RoleEvents::BEFORE_UPDATE_ROLE, |
|
| 135 | RoleEvents::UPDATE_ROLE |
|
| 136 | ); |
|
| 137 | ||
| 138 | $parameters = [ |
|
| 139 | $this->createMock(Role::class), |
|
| 140 | $this->createMock(RoleUpdateStruct::class), |
|
| 141 | ]; |
|
| 142 | ||
| 143 | $updatedRole = $this->createMock(Role::class); |
|
| 144 | $eventUpdatedRole = $this->createMock(Role::class); |
|
| 145 | $innerServiceMock = $this->createMock(RoleServiceInterface::class); |
|
| 146 | $innerServiceMock->method('updateRole')->willReturn($updatedRole); |
|
| 147 | ||
| 148 | $traceableEventDispatcher->addListener(RoleEvents::BEFORE_UPDATE_ROLE, function (BeforeUpdateRoleEvent $event) use ($eventUpdatedRole) { |
|
| 149 | $event->setUpdatedRole($eventUpdatedRole); |
|
| 150 | }, 10); |
|
| 151 | ||
| 152 | $service = new RoleService($innerServiceMock, $traceableEventDispatcher); |
|
| 153 | $result = $service->updateRole(...$parameters); |
|
| 154 | ||
| 155 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 156 | ||
| 157 | $this->assertSame($eventUpdatedRole, $result); |
|
| 158 | $this->assertSame($calledListeners, [ |
|
| 159 | [RoleEvents::BEFORE_UPDATE_ROLE, 10], |
|
| 160 | [RoleEvents::BEFORE_UPDATE_ROLE, 0], |
|
| 161 | [RoleEvents::UPDATE_ROLE, 0], |
|
| 162 | ]); |
|
| 163 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 164 | } |
|
| 165 | ||
| 166 | public function testUpdateRoleStopPropagationInBeforeEvents() |
|
| 167 | { |
|
| @@ 351-384 (lines=34) @@ | ||
| 348 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 349 | } |
|
| 350 | ||
| 351 | public function testReturnAddPolicyResultInBeforeEvents() |
|
| 352 | { |
|
| 353 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 354 | RoleEvents::BEFORE_ADD_POLICY, |
|
| 355 | RoleEvents::ADD_POLICY |
|
| 356 | ); |
|
| 357 | ||
| 358 | $parameters = [ |
|
| 359 | $this->createMock(Role::class), |
|
| 360 | $this->createMock(PolicyCreateStruct::class), |
|
| 361 | ]; |
|
| 362 | ||
| 363 | $updatedRole = $this->createMock(Role::class); |
|
| 364 | $eventUpdatedRole = $this->createMock(Role::class); |
|
| 365 | $innerServiceMock = $this->createMock(RoleServiceInterface::class); |
|
| 366 | $innerServiceMock->method('addPolicy')->willReturn($updatedRole); |
|
| 367 | ||
| 368 | $traceableEventDispatcher->addListener(RoleEvents::BEFORE_ADD_POLICY, function (BeforeAddPolicyEvent $event) use ($eventUpdatedRole) { |
|
| 369 | $event->setUpdatedRole($eventUpdatedRole); |
|
| 370 | }, 10); |
|
| 371 | ||
| 372 | $service = new RoleService($innerServiceMock, $traceableEventDispatcher); |
|
| 373 | $result = $service->addPolicy(...$parameters); |
|
| 374 | ||
| 375 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 376 | ||
| 377 | $this->assertSame($eventUpdatedRole, $result); |
|
| 378 | $this->assertSame($calledListeners, [ |
|
| 379 | [RoleEvents::BEFORE_ADD_POLICY, 10], |
|
| 380 | [RoleEvents::BEFORE_ADD_POLICY, 0], |
|
| 381 | [RoleEvents::ADD_POLICY, 0], |
|
| 382 | ]); |
|
| 383 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 384 | } |
|
| 385 | ||
| 386 | public function testAddPolicyStopPropagationInBeforeEvents() |
|
| 387 | { |
|
| @@ 453-486 (lines=34) @@ | ||
| 450 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 451 | } |
|
| 452 | ||
| 453 | public function testReturnUpdateRoleDraftResultInBeforeEvents() |
|
| 454 | { |
|
| 455 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 456 | RoleEvents::BEFORE_UPDATE_ROLE_DRAFT, |
|
| 457 | RoleEvents::UPDATE_ROLE_DRAFT |
|
| 458 | ); |
|
| 459 | ||
| 460 | $parameters = [ |
|
| 461 | $this->createMock(RoleDraft::class), |
|
| 462 | $this->createMock(RoleUpdateStruct::class), |
|
| 463 | ]; |
|
| 464 | ||
| 465 | $updatedRoleDraft = $this->createMock(RoleDraft::class); |
|
| 466 | $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class); |
|
| 467 | $innerServiceMock = $this->createMock(RoleServiceInterface::class); |
|
| 468 | $innerServiceMock->method('updateRoleDraft')->willReturn($updatedRoleDraft); |
|
| 469 | ||
| 470 | $traceableEventDispatcher->addListener(RoleEvents::BEFORE_UPDATE_ROLE_DRAFT, function (BeforeUpdateRoleDraftEvent $event) use ($eventUpdatedRoleDraft) { |
|
| 471 | $event->setUpdatedRoleDraft($eventUpdatedRoleDraft); |
|
| 472 | }, 10); |
|
| 473 | ||
| 474 | $service = new RoleService($innerServiceMock, $traceableEventDispatcher); |
|
| 475 | $result = $service->updateRoleDraft(...$parameters); |
|
| 476 | ||
| 477 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 478 | ||
| 479 | $this->assertSame($eventUpdatedRoleDraft, $result); |
|
| 480 | $this->assertSame($calledListeners, [ |
|
| 481 | [RoleEvents::BEFORE_UPDATE_ROLE_DRAFT, 10], |
|
| 482 | [RoleEvents::BEFORE_UPDATE_ROLE_DRAFT, 0], |
|
| 483 | [RoleEvents::UPDATE_ROLE_DRAFT, 0], |
|
| 484 | ]); |
|
| 485 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 486 | } |
|
| 487 | ||
| 488 | public function testUpdateRoleDraftStopPropagationInBeforeEvents() |
|
| 489 | { |
|
| @@ 676-710 (lines=35) @@ | ||
| 673 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 674 | } |
|
| 675 | ||
| 676 | public function testReturnUpdatePolicyByRoleDraftResultInBeforeEvents() |
|
| 677 | { |
|
| 678 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 679 | RoleEvents::BEFORE_UPDATE_POLICY_BY_ROLE_DRAFT, |
|
| 680 | RoleEvents::UPDATE_POLICY_BY_ROLE_DRAFT |
|
| 681 | ); |
|
| 682 | ||
| 683 | $parameters = [ |
|
| 684 | $this->createMock(RoleDraft::class), |
|
| 685 | $this->createMock(PolicyDraft::class), |
|
| 686 | $this->createMock(PolicyUpdateStruct::class), |
|
| 687 | ]; |
|
| 688 | ||
| 689 | $updatedPolicyDraft = $this->createMock(PolicyDraft::class); |
|
| 690 | $eventUpdatedPolicyDraft = $this->createMock(PolicyDraft::class); |
|
| 691 | $innerServiceMock = $this->createMock(RoleServiceInterface::class); |
|
| 692 | $innerServiceMock->method('updatePolicyByRoleDraft')->willReturn($updatedPolicyDraft); |
|
| 693 | ||
| 694 | $traceableEventDispatcher->addListener(RoleEvents::BEFORE_UPDATE_POLICY_BY_ROLE_DRAFT, function (BeforeUpdatePolicyByRoleDraftEvent $event) use ($eventUpdatedPolicyDraft) { |
|
| 695 | $event->setUpdatedPolicyDraft($eventUpdatedPolicyDraft); |
|
| 696 | }, 10); |
|
| 697 | ||
| 698 | $service = new RoleService($innerServiceMock, $traceableEventDispatcher); |
|
| 699 | $result = $service->updatePolicyByRoleDraft(...$parameters); |
|
| 700 | ||
| 701 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 702 | ||
| 703 | $this->assertSame($eventUpdatedPolicyDraft, $result); |
|
| 704 | $this->assertSame($calledListeners, [ |
|
| 705 | [RoleEvents::BEFORE_UPDATE_POLICY_BY_ROLE_DRAFT, 10], |
|
| 706 | [RoleEvents::BEFORE_UPDATE_POLICY_BY_ROLE_DRAFT, 0], |
|
| 707 | [RoleEvents::UPDATE_POLICY_BY_ROLE_DRAFT, 0], |
|
| 708 | ]); |
|
| 709 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 710 | } |
|
| 711 | ||
| 712 | public function testUpdatePolicyByRoleDraftStopPropagationInBeforeEvents() |
|
| 713 | { |
|
| @@ 879-912 (lines=34) @@ | ||
| 876 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 877 | } |
|
| 878 | ||
| 879 | public function testReturnRemovePolicyByRoleDraftResultInBeforeEvents() |
|
| 880 | { |
|
| 881 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 882 | RoleEvents::BEFORE_REMOVE_POLICY_BY_ROLE_DRAFT, |
|
| 883 | RoleEvents::REMOVE_POLICY_BY_ROLE_DRAFT |
|
| 884 | ); |
|
| 885 | ||
| 886 | $parameters = [ |
|
| 887 | $this->createMock(RoleDraft::class), |
|
| 888 | $this->createMock(PolicyDraft::class), |
|
| 889 | ]; |
|
| 890 | ||
| 891 | $updatedRoleDraft = $this->createMock(RoleDraft::class); |
|
| 892 | $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class); |
|
| 893 | $innerServiceMock = $this->createMock(RoleServiceInterface::class); |
|
| 894 | $innerServiceMock->method('removePolicyByRoleDraft')->willReturn($updatedRoleDraft); |
|
| 895 | ||
| 896 | $traceableEventDispatcher->addListener(RoleEvents::BEFORE_REMOVE_POLICY_BY_ROLE_DRAFT, function (BeforeRemovePolicyByRoleDraftEvent $event) use ($eventUpdatedRoleDraft) { |
|
| 897 | $event->setUpdatedRoleDraft($eventUpdatedRoleDraft); |
|
| 898 | }, 10); |
|
| 899 | ||
| 900 | $service = new RoleService($innerServiceMock, $traceableEventDispatcher); |
|
| 901 | $result = $service->removePolicyByRoleDraft(...$parameters); |
|
| 902 | ||
| 903 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 904 | ||
| 905 | $this->assertSame($eventUpdatedRoleDraft, $result); |
|
| 906 | $this->assertSame($calledListeners, [ |
|
| 907 | [RoleEvents::BEFORE_REMOVE_POLICY_BY_ROLE_DRAFT, 10], |
|
| 908 | [RoleEvents::BEFORE_REMOVE_POLICY_BY_ROLE_DRAFT, 0], |
|
| 909 | [RoleEvents::REMOVE_POLICY_BY_ROLE_DRAFT, 0], |
|
| 910 | ]); |
|
| 911 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 912 | } |
|
| 913 | ||
| 914 | public function testRemovePolicyByRoleDraftStopPropagationInBeforeEvents() |
|
| 915 | { |
|
| @@ 981-1014 (lines=34) @@ | ||
| 978 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 979 | } |
|
| 980 | ||
| 981 | public function testReturnAddPolicyByRoleDraftResultInBeforeEvents() |
|
| 982 | { |
|
| 983 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 984 | RoleEvents::BEFORE_ADD_POLICY_BY_ROLE_DRAFT, |
|
| 985 | RoleEvents::ADD_POLICY_BY_ROLE_DRAFT |
|
| 986 | ); |
|
| 987 | ||
| 988 | $parameters = [ |
|
| 989 | $this->createMock(RoleDraft::class), |
|
| 990 | $this->createMock(PolicyCreateStruct::class), |
|
| 991 | ]; |
|
| 992 | ||
| 993 | $updatedRoleDraft = $this->createMock(RoleDraft::class); |
|
| 994 | $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class); |
|
| 995 | $innerServiceMock = $this->createMock(RoleServiceInterface::class); |
|
| 996 | $innerServiceMock->method('addPolicyByRoleDraft')->willReturn($updatedRoleDraft); |
|
| 997 | ||
| 998 | $traceableEventDispatcher->addListener(RoleEvents::BEFORE_ADD_POLICY_BY_ROLE_DRAFT, function (BeforeAddPolicyByRoleDraftEvent $event) use ($eventUpdatedRoleDraft) { |
|
| 999 | $event->setUpdatedRoleDraft($eventUpdatedRoleDraft); |
|
| 1000 | }, 10); |
|
| 1001 | ||
| 1002 | $service = new RoleService($innerServiceMock, $traceableEventDispatcher); |
|
| 1003 | $result = $service->addPolicyByRoleDraft(...$parameters); |
|
| 1004 | ||
| 1005 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 1006 | ||
| 1007 | $this->assertSame($eventUpdatedRoleDraft, $result); |
|
| 1008 | $this->assertSame($calledListeners, [ |
|
| 1009 | [RoleEvents::BEFORE_ADD_POLICY_BY_ROLE_DRAFT, 10], |
|
| 1010 | [RoleEvents::BEFORE_ADD_POLICY_BY_ROLE_DRAFT, 0], |
|
| 1011 | [RoleEvents::ADD_POLICY_BY_ROLE_DRAFT, 0], |
|
| 1012 | ]); |
|
| 1013 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 1014 | } |
|
| 1015 | ||
| 1016 | public function testAddPolicyByRoleDraftStopPropagationInBeforeEvents() |
|
| 1017 | { |
|
| @@ 1353-1386 (lines=34) @@ | ||
| 1350 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 1351 | } |
|
| 1352 | ||
| 1353 | public function testReturnUpdatePolicyResultInBeforeEvents() |
|
| 1354 | { |
|
| 1355 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 1356 | RoleEvents::BEFORE_UPDATE_POLICY, |
|
| 1357 | RoleEvents::UPDATE_POLICY |
|
| 1358 | ); |
|
| 1359 | ||
| 1360 | $parameters = [ |
|
| 1361 | $this->createMock(Policy::class), |
|
| 1362 | $this->createMock(PolicyUpdateStruct::class), |
|
| 1363 | ]; |
|
| 1364 | ||
| 1365 | $updatedPolicy = $this->createMock(Policy::class); |
|
| 1366 | $eventUpdatedPolicy = $this->createMock(Policy::class); |
|
| 1367 | $innerServiceMock = $this->createMock(RoleServiceInterface::class); |
|
| 1368 | $innerServiceMock->method('updatePolicy')->willReturn($updatedPolicy); |
|
| 1369 | ||
| 1370 | $traceableEventDispatcher->addListener(RoleEvents::BEFORE_UPDATE_POLICY, function (BeforeUpdatePolicyEvent $event) use ($eventUpdatedPolicy) { |
|
| 1371 | $event->setUpdatedPolicy($eventUpdatedPolicy); |
|
| 1372 | }, 10); |
|
| 1373 | ||
| 1374 | $service = new RoleService($innerServiceMock, $traceableEventDispatcher); |
|
| 1375 | $result = $service->updatePolicy(...$parameters); |
|
| 1376 | ||
| 1377 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 1378 | ||
| 1379 | $this->assertSame($eventUpdatedPolicy, $result); |
|
| 1380 | $this->assertSame($calledListeners, [ |
|
| 1381 | [RoleEvents::BEFORE_UPDATE_POLICY, 10], |
|
| 1382 | [RoleEvents::BEFORE_UPDATE_POLICY, 0], |
|
| 1383 | [RoleEvents::UPDATE_POLICY, 0], |
|
| 1384 | ]); |
|
| 1385 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 1386 | } |
|
| 1387 | ||
| 1388 | public function testUpdatePolicyStopPropagationInBeforeEvents() |
|
| 1389 | { |
|
| @@ 113-146 (lines=34) @@ | ||
| 110 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 111 | } |
|
| 112 | ||
| 113 | public function testReturnUpdateSectionResultInBeforeEvents() |
|
| 114 | { |
|
| 115 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 116 | SectionEvents::BEFORE_UPDATE_SECTION, |
|
| 117 | SectionEvents::UPDATE_SECTION |
|
| 118 | ); |
|
| 119 | ||
| 120 | $parameters = [ |
|
| 121 | $this->createMock(Section::class), |
|
| 122 | $this->createMock(SectionUpdateStruct::class), |
|
| 123 | ]; |
|
| 124 | ||
| 125 | $updatedSection = $this->createMock(Section::class); |
|
| 126 | $eventUpdatedSection = $this->createMock(Section::class); |
|
| 127 | $innerServiceMock = $this->createMock(SectionServiceInterface::class); |
|
| 128 | $innerServiceMock->method('updateSection')->willReturn($updatedSection); |
|
| 129 | ||
| 130 | $traceableEventDispatcher->addListener(SectionEvents::BEFORE_UPDATE_SECTION, function (BeforeUpdateSectionEvent $event) use ($eventUpdatedSection) { |
|
| 131 | $event->setUpdatedSection($eventUpdatedSection); |
|
| 132 | }, 10); |
|
| 133 | ||
| 134 | $service = new SectionService($innerServiceMock, $traceableEventDispatcher); |
|
| 135 | $result = $service->updateSection(...$parameters); |
|
| 136 | ||
| 137 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 138 | ||
| 139 | $this->assertSame($eventUpdatedSection, $result); |
|
| 140 | $this->assertSame($calledListeners, [ |
|
| 141 | [SectionEvents::BEFORE_UPDATE_SECTION, 10], |
|
| 142 | [SectionEvents::BEFORE_UPDATE_SECTION, 0], |
|
| 143 | [SectionEvents::UPDATE_SECTION, 0], |
|
| 144 | ]); |
|
| 145 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 146 | } |
|
| 147 | ||
| 148 | public function testUpdateSectionStopPropagationInBeforeEvents() |
|
| 149 | { |
|
| @@ 247-280 (lines=34) @@ | ||
| 244 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 245 | } |
|
| 246 | ||
| 247 | public function testReturnRecoverResultInBeforeEvents() |
|
| 248 | { |
|
| 249 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 250 | TrashEvents::BEFORE_RECOVER, |
|
| 251 | TrashEvents::RECOVER |
|
| 252 | ); |
|
| 253 | ||
| 254 | $parameters = [ |
|
| 255 | $this->createMock(TrashItem::class), |
|
| 256 | $this->createMock(Location::class), |
|
| 257 | ]; |
|
| 258 | ||
| 259 | $location = $this->createMock(Location::class); |
|
| 260 | $eventLocation = $this->createMock(Location::class); |
|
| 261 | $innerServiceMock = $this->createMock(TrashServiceInterface::class); |
|
| 262 | $innerServiceMock->method('recover')->willReturn($location); |
|
| 263 | ||
| 264 | $traceableEventDispatcher->addListener(TrashEvents::BEFORE_RECOVER, function (BeforeRecoverEvent $event) use ($eventLocation) { |
|
| 265 | $event->setLocation($eventLocation); |
|
| 266 | }, 10); |
|
| 267 | ||
| 268 | $service = new TrashService($innerServiceMock, $traceableEventDispatcher); |
|
| 269 | $result = $service->recover(...$parameters); |
|
| 270 | ||
| 271 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 272 | ||
| 273 | $this->assertSame($eventLocation, $result); |
|
| 274 | $this->assertSame($calledListeners, [ |
|
| 275 | [TrashEvents::BEFORE_RECOVER, 10], |
|
| 276 | [TrashEvents::BEFORE_RECOVER, 0], |
|
| 277 | [TrashEvents::RECOVER, 0], |
|
| 278 | ]); |
|
| 279 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 280 | } |
|
| 281 | ||
| 282 | public function testRecoverStopPropagationInBeforeEvents() |
|
| 283 | { |
|
| @@ 47-80 (lines=34) @@ | ||
| 44 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 45 | } |
|
| 46 | ||
| 47 | public function testReturnUpdateUrlResultInBeforeEvents() |
|
| 48 | { |
|
| 49 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 50 | URLEvents::BEFORE_UPDATE_URL, |
|
| 51 | URLEvents::UPDATE_URL |
|
| 52 | ); |
|
| 53 | ||
| 54 | $parameters = [ |
|
| 55 | $this->createMock(URL::class), |
|
| 56 | $this->createMock(URLUpdateStruct::class), |
|
| 57 | ]; |
|
| 58 | ||
| 59 | $updatedUrl = $this->createMock(URL::class); |
|
| 60 | $eventUpdatedUrl = $this->createMock(URL::class); |
|
| 61 | $innerServiceMock = $this->createMock(URLServiceInterface::class); |
|
| 62 | $innerServiceMock->method('updateUrl')->willReturn($updatedUrl); |
|
| 63 | ||
| 64 | $traceableEventDispatcher->addListener(URLEvents::BEFORE_UPDATE_URL, function (BeforeUpdateUrlEvent $event) use ($eventUpdatedUrl) { |
|
| 65 | $event->setUpdatedUrl($eventUpdatedUrl); |
|
| 66 | }, 10); |
|
| 67 | ||
| 68 | $service = new URLService($innerServiceMock, $traceableEventDispatcher); |
|
| 69 | $result = $service->updateUrl(...$parameters); |
|
| 70 | ||
| 71 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 72 | ||
| 73 | $this->assertSame($eventUpdatedUrl, $result); |
|
| 74 | $this->assertSame($calledListeners, [ |
|
| 75 | [URLEvents::BEFORE_UPDATE_URL, 10], |
|
| 76 | [URLEvents::BEFORE_UPDATE_URL, 0], |
|
| 77 | [URLEvents::UPDATE_URL, 0], |
|
| 78 | ]); |
|
| 79 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 80 | } |
|
| 81 | ||
| 82 | public function testUpdateUrlStopPropagationInBeforeEvents() |
|
| 83 | { |
|
| @@ 61-94 (lines=34) @@ | ||
| 58 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 59 | } |
|
| 60 | ||
| 61 | public function testReturnUpdateUserGroupResultInBeforeEvents() |
|
| 62 | { |
|
| 63 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 64 | UserEvents::BEFORE_UPDATE_USER_GROUP, |
|
| 65 | UserEvents::UPDATE_USER_GROUP |
|
| 66 | ); |
|
| 67 | ||
| 68 | $parameters = [ |
|
| 69 | $this->createMock(UserGroup::class), |
|
| 70 | $this->createMock(UserGroupUpdateStruct::class), |
|
| 71 | ]; |
|
| 72 | ||
| 73 | $updatedUserGroup = $this->createMock(UserGroup::class); |
|
| 74 | $eventUpdatedUserGroup = $this->createMock(UserGroup::class); |
|
| 75 | $innerServiceMock = $this->createMock(UserServiceInterface::class); |
|
| 76 | $innerServiceMock->method('updateUserGroup')->willReturn($updatedUserGroup); |
|
| 77 | ||
| 78 | $traceableEventDispatcher->addListener(UserEvents::BEFORE_UPDATE_USER_GROUP, function (BeforeUpdateUserGroupEvent $event) use ($eventUpdatedUserGroup) { |
|
| 79 | $event->setUpdatedUserGroup($eventUpdatedUserGroup); |
|
| 80 | }, 10); |
|
| 81 | ||
| 82 | $service = new UserService($innerServiceMock, $traceableEventDispatcher); |
|
| 83 | $result = $service->updateUserGroup(...$parameters); |
|
| 84 | ||
| 85 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 86 | ||
| 87 | $this->assertSame($eventUpdatedUserGroup, $result); |
|
| 88 | $this->assertSame($calledListeners, [ |
|
| 89 | [UserEvents::BEFORE_UPDATE_USER_GROUP, 10], |
|
| 90 | [UserEvents::BEFORE_UPDATE_USER_GROUP, 0], |
|
| 91 | [UserEvents::UPDATE_USER_GROUP, 0], |
|
| 92 | ]); |
|
| 93 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 94 | } |
|
| 95 | ||
| 96 | public function testUpdateUserGroupStopPropagationInBeforeEvents() |
|
| 97 | { |
|
| @@ 163-196 (lines=34) @@ | ||
| 160 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 161 | } |
|
| 162 | ||
| 163 | public function testReturnUpdateUserResultInBeforeEvents() |
|
| 164 | { |
|
| 165 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 166 | UserEvents::BEFORE_UPDATE_USER, |
|
| 167 | UserEvents::UPDATE_USER |
|
| 168 | ); |
|
| 169 | ||
| 170 | $parameters = [ |
|
| 171 | $this->createMock(User::class), |
|
| 172 | $this->createMock(UserUpdateStruct::class), |
|
| 173 | ]; |
|
| 174 | ||
| 175 | $updatedUser = $this->createMock(User::class); |
|
| 176 | $eventUpdatedUser = $this->createMock(User::class); |
|
| 177 | $innerServiceMock = $this->createMock(UserServiceInterface::class); |
|
| 178 | $innerServiceMock->method('updateUser')->willReturn($updatedUser); |
|
| 179 | ||
| 180 | $traceableEventDispatcher->addListener(UserEvents::BEFORE_UPDATE_USER, function (BeforeUpdateUserEvent $event) use ($eventUpdatedUser) { |
|
| 181 | $event->setUpdatedUser($eventUpdatedUser); |
|
| 182 | }, 10); |
|
| 183 | ||
| 184 | $service = new UserService($innerServiceMock, $traceableEventDispatcher); |
|
| 185 | $result = $service->updateUser(...$parameters); |
|
| 186 | ||
| 187 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 188 | ||
| 189 | $this->assertSame($eventUpdatedUser, $result); |
|
| 190 | $this->assertSame($calledListeners, [ |
|
| 191 | [UserEvents::BEFORE_UPDATE_USER, 10], |
|
| 192 | [UserEvents::BEFORE_UPDATE_USER, 0], |
|
| 193 | [UserEvents::UPDATE_USER, 0], |
|
| 194 | ]); |
|
| 195 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 196 | } |
|
| 197 | ||
| 198 | public function testUpdateUserStopPropagationInBeforeEvents() |
|
| 199 | { |
|
| @@ 742-775 (lines=34) @@ | ||
| 739 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 740 | } |
|
| 741 | ||
| 742 | public function testReturnCreateUserGroupResultInBeforeEvents() |
|
| 743 | { |
|
| 744 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 745 | UserEvents::BEFORE_CREATE_USER_GROUP, |
|
| 746 | UserEvents::CREATE_USER_GROUP |
|
| 747 | ); |
|
| 748 | ||
| 749 | $parameters = [ |
|
| 750 | $this->createMock(UserGroupCreateStruct::class), |
|
| 751 | $this->createMock(UserGroup::class), |
|
| 752 | ]; |
|
| 753 | ||
| 754 | $userGroup = $this->createMock(UserGroup::class); |
|
| 755 | $eventUserGroup = $this->createMock(UserGroup::class); |
|
| 756 | $innerServiceMock = $this->createMock(UserServiceInterface::class); |
|
| 757 | $innerServiceMock->method('createUserGroup')->willReturn($userGroup); |
|
| 758 | ||
| 759 | $traceableEventDispatcher->addListener(UserEvents::BEFORE_CREATE_USER_GROUP, function (BeforeCreateUserGroupEvent $event) use ($eventUserGroup) { |
|
| 760 | $event->setUserGroup($eventUserGroup); |
|
| 761 | }, 10); |
|
| 762 | ||
| 763 | $service = new UserService($innerServiceMock, $traceableEventDispatcher); |
|
| 764 | $result = $service->createUserGroup(...$parameters); |
|
| 765 | ||
| 766 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 767 | ||
| 768 | $this->assertSame($eventUserGroup, $result); |
|
| 769 | $this->assertSame($calledListeners, [ |
|
| 770 | [UserEvents::BEFORE_CREATE_USER_GROUP, 10], |
|
| 771 | [UserEvents::BEFORE_CREATE_USER_GROUP, 0], |
|
| 772 | [UserEvents::CREATE_USER_GROUP, 0], |
|
| 773 | ]); |
|
| 774 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 775 | } |
|
| 776 | ||
| 777 | public function testCreateUserGroupStopPropagationInBeforeEvents() |
|
| 778 | { |
|
| @@ 844-877 (lines=34) @@ | ||
| 841 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 842 | } |
|
| 843 | ||
| 844 | public function testReturnUpdateUserTokenResultInBeforeEvents() |
|
| 845 | { |
|
| 846 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 847 | UserEvents::BEFORE_UPDATE_USER_TOKEN, |
|
| 848 | UserEvents::UPDATE_USER_TOKEN |
|
| 849 | ); |
|
| 850 | ||
| 851 | $parameters = [ |
|
| 852 | $this->createMock(User::class), |
|
| 853 | $this->createMock(UserTokenUpdateStruct::class), |
|
| 854 | ]; |
|
| 855 | ||
| 856 | $updatedUser = $this->createMock(User::class); |
|
| 857 | $eventUpdatedUser = $this->createMock(User::class); |
|
| 858 | $innerServiceMock = $this->createMock(UserServiceInterface::class); |
|
| 859 | $innerServiceMock->method('updateUserToken')->willReturn($updatedUser); |
|
| 860 | ||
| 861 | $traceableEventDispatcher->addListener(UserEvents::BEFORE_UPDATE_USER_TOKEN, function (BeforeUpdateUserTokenEvent $event) use ($eventUpdatedUser) { |
|
| 862 | $event->setUpdatedUser($eventUpdatedUser); |
|
| 863 | }, 10); |
|
| 864 | ||
| 865 | $service = new UserService($innerServiceMock, $traceableEventDispatcher); |
|
| 866 | $result = $service->updateUserToken(...$parameters); |
|
| 867 | ||
| 868 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 869 | ||
| 870 | $this->assertSame($eventUpdatedUser, $result); |
|
| 871 | $this->assertSame($calledListeners, [ |
|
| 872 | [UserEvents::BEFORE_UPDATE_USER_TOKEN, 10], |
|
| 873 | [UserEvents::BEFORE_UPDATE_USER_TOKEN, 0], |
|
| 874 | [UserEvents::UPDATE_USER_TOKEN, 0], |
|
| 875 | ]); |
|
| 876 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 877 | } |
|
| 878 | ||
| 879 | public function testUpdateUserTokenStopPropagationInBeforeEvents() |
|
| 880 | { |
|