/** * @test */ public function eventIsNotDispatchedToUnregisteredSubscriber() { $testEvent = $this->getMock(EventInterface::class); $testEvent->expects(static::never())->method('getEventName')->willReturn('event.name'); $testSubscriber = $this->getMockBuilder(EventSubscriberInterface::class)->setMethods(['onEventName', 'getSubscribedEvents', 'getNotifications'])->getMock(); $testSubscriber->expects(static::never())->method('getSubscribedEvents')->willReturn(['event.name' => 'onEventName']); $testSubscriber->expects(static::never())->method('onEventName')->with(static::equalTo($testEvent)); $eventBus = new SimpleEventBus(); /** @var EventSubscriberInterface $testSubscriber */ $eventBus->register($testSubscriber); $eventBus->deregister($testSubscriber); }
/** * @test */ public function userServicePasswordUpdatePublishesEvent() { $repositoryMock = $this->getUserRepositoryMock(); $roleRepositoryMock = $this->getRoleRepositoryMock(); $uuidGeneratorMock = $this->getUuidGeneratorMock(); $repositoryMock->expects(static::once())->method('findById')->willReturn(static::getUserForRepositoryMock()); $userEventSubscriber = new UserEventSubscriber(); $eventBus = new SimpleEventBus(); $eventBus->register($userEventSubscriber); /** @var RepositoryInterface $repositoryMock */ $unitOfWork = new SimpleUnitOfWork($repositoryMock, $eventBus); /** @var UuidGeneratorInterface $uuidGeneratorMock */ /** @var RoleRepositoryInterface $roleRepositoryMock */ $userService = new UserService($unitOfWork, $roleRepositoryMock, $uuidGeneratorMock); $userService->updateUserPassword($this->getUserUpdatePasswordCommand()); static::assertEquals(['0' => ['user.password.update' => ['uuid' => 'de305d54-75b4-431b-adb2-eb6b9e546013']]], $userEventSubscriber->getNotifications()); }