cacheStorageMock = $this->getMockBuilder(CacheInterface::class) ->getMockForAbstractClass(); $this->logMock = $this->getMockBuilder(Log::class) ->getMock(); $this->sessionMock = $this->getMockBuilder(Session::class) ->disableOriginalConstructor() ->setMethods(['getUser', 'getId']) ->getMock(); $this->viewerLoggerMock = $this->getMockBuilder(Logger::class) ->disableOriginalConstructor() ->getMock(); $this->productMetadataMock = $this->getMockBuilder(ProductMetadataInterface::class) ->disableOriginalConstructor() ->getMock(); $objectManager = new ObjectManager($this); $this->canViewNotification = $objectManager->getObject( CanViewNotification::class, [ 'viewerLogger' => $this->viewerLoggerMock, 'session' => $this->sessionMock, 'productMetadata' => $this->productMetadataMock, 'cacheStorage' => $this->cacheStorageMock, ] ); } public function testIsVisibleLoadDataFromCache() { $this->sessionMock->expects($this->once()) ->method('getUser') ->willReturn($this->sessionMock); $this->sessionMock->expects($this->once()) ->method('getId') ->willReturn(1); $this->cacheStorageMock->expects($this->once()) ->method('load') ->with('release-notification-popup-1') ->willReturn("0"); $this->assertEquals(false, $this->canViewNotification->isVisible([])); } /** * @param bool $expected * @param string $version * @param string|null $lastViewVersion * @dataProvider isVisibleProvider */ public function testIsVisible($expected, $version, $lastViewVersion) { $this->cacheStorageMock->expects($this->once()) ->method('load') ->with('release-notification-popup-1') ->willReturn(false); $this->sessionMock->expects($this->once()) ->method('getUser') ->willReturn($this->sessionMock); $this->sessionMock->expects($this->once()) ->method('getId') ->willReturn(1); $this->productMetadataMock->expects($this->once()) ->method('getVersion') ->willReturn($version); $this->logMock->expects($this->once()) ->method('getLastViewVersion') ->willReturn($lastViewVersion); $this->viewerLoggerMock->expects($this->once()) ->method('get') ->with(1) ->willReturn($this->logMock); $this->cacheStorageMock->expects($this->once()) ->method('save') ->with(false, 'release-notification-popup-1'); $this->assertEquals($expected, $this->canViewNotification->isVisible([])); } /** * @return array */ public function isVisibleProvider() { return [ [false, '2.2.1-dev', '999.999.999-alpha'], [true, '2.2.1-dev', '2.0.0'], [true, '2.2.1-dev', null], [false, '2.2.1-dev', '2.2.1'], [true, '2.2.1-dev', '2.2.0'], [true, '2.3.0', '2.2.0'], [false, '2.2.2', '2.2.2'], ]; } }