scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); $this->requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class); $this->serializerMock = $this->createMock(Json::class); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->designExceptions = $this->objectManagerHelper->getObject( \Magento\Framework\View\DesignExceptions::class, [ 'scopeConfig' => $this->scopeConfigMock, 'exceptionConfigPath' => $this->exceptionConfigPath, 'scopeType' => $this->scopeType, 'serializer' => $this->serializerMock, ] ); } /** * @param string $userAgent * @param bool $configValue * @param int $callNum * @param bool|string $result * @param array $expressions * @dataProvider getThemeByRequestDataProvider */ public function testGetThemeByRequest($userAgent, $configValue, $callNum, $result, $expressions = []) { $this->requestMock->expects($this->once()) ->method('getServer') ->with($this->equalTo('HTTP_USER_AGENT')) ->will($this->returnValue($userAgent)); if ($userAgent) { $this->scopeConfigMock->expects($this->once()) ->method('getValue') ->with($this->equalTo($this->exceptionConfigPath), $this->equalTo($this->scopeType)) ->will($this->returnValue($configValue)); } $this->serializerMock->expects($this->exactly($callNum)) ->method('unserialize') ->with($configValue) ->willReturn($expressions); $this->assertSame($result, $this->designExceptions->getThemeByRequest($this->requestMock)); } /** * @return array */ public function getThemeByRequestDataProvider() { return [ [false, null, 0, false], ['iphone', null, 0, false], ['iphone', 'serializedExpressions1', 1, false], ['iphone', 'serializedExpressions2', 1, 'matched', [['regexp' => '/iphone/', 'value' => 'matched']]], ['explorer', 'serializedExpressions3', 1, false, [['regexp' => '/iphone/', 'value' => 'matched']]], ]; } }