coreParametersHelper = $this->createMock(CoreParametersHelper::class); $this->pathsHelper = $this->createMock(PathsHelper::class); $this->widgetDetailEventFactory = $this->createMock(WidgetDetailEventFactory::class); $this->filesystem = $this->createMock(Filesystem::class); $this->session = $this->createMock(Session::class); $requestStack = $this->createMock(RequestStack::class); $requestStack->method('getSession') ->willReturn($this->session); $this->model = new DashboardModel( $this->coreParametersHelper, $this->pathsHelper, $this->widgetDetailEventFactory, $this->filesystem, $requestStack, $this->createMock(EntityManagerInterface::class), $this->createMock(CorePermissions::class), $this->createMock(EventDispatcherInterface::class), $this->createMock(UrlGeneratorInterface::class), $this->createMock(Translator::class), $this->createMock(UserHelper::class), $this->createMock(LoggerInterface::class) ); } public function testGetDefaultFilterFromSession(): void { $dateFromStr = '-1 month'; $dateFrom = new \DateTime($dateFromStr); $dateTo = new \DateTime('23:59:59'); // till end of the 'to' date selected $this->coreParametersHelper->expects(self::once()) ->method('get') ->with('default_daterange_filter', $dateFromStr) ->willReturn($dateFromStr); $this->session->expects($this->exactly(2)) ->method('get') ->willReturnOnConsecutiveCalls( $dateFrom->format(\DateTimeInterface::ATOM), $dateTo->format(\DateTimeInterface::ATOM) ); $filter = $this->model->getDefaultFilter(); Assert::assertSame( $dateFrom->format(\DateTimeInterface::ATOM), $filter['dateFrom']->format(\DateTimeInterface::ATOM) ); Assert::assertSame( $dateTo->format(\DateTimeInterface::ATOM), $filter['dateTo']->format(\DateTimeInterface::ATOM) ); } }