Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PreprocessorStrategyTest.php
Go to the documentation of this file.
1 <?php
7 
16 
23 class PreprocessorStrategyTest extends \PHPUnit\Framework\TestCase
24 {
28  private $preprocessorStrategy;
29 
33  private $frontendCompilationMock;
34 
38  private $alternativeSourceMock;
39 
43  private $scopeConfigMock;
44 
48  private $stateMock;
49 
53  private $objectMangerMock;
54 
58  protected function setUp()
59  {
60  $this->alternativeSourceMock = $this->getMockBuilder(AlternativeSourceInterface::class)
61  ->getMockForAbstractClass();
62  $this->frontendCompilationMock = $this->getMockBuilder(FrontendCompilation::class)
63  ->disableOriginalConstructor()
64  ->getMock();
65  $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
66  ->getMockForAbstractClass();
67  $this->stateMock = $this->getMockBuilder(State::class)
68  ->disableOriginalConstructor()
69  ->getMock();
70  $this->objectMangerMock = $this->getMockBuilder(\Magento\Framework\App\ObjectManager::class)
71  ->disableOriginalConstructor()
72  ->getMock();
73 
74  $this->preprocessorStrategy = (new ObjectManager($this))->getObject(PreprocessorStrategy::class, [
75  'alternativeSource' => $this->alternativeSourceMock,
76  'frontendCompilation' => $this->frontendCompilationMock,
77  'scopeConfig' => $this->scopeConfigMock,
78  'state' => $this->stateMock,
79  ]);
80  }
81 
86  {
87  $chainMock = $this->getChainMock();
88 
89  $this->scopeConfigMock->expects(self::once())
90  ->method('getValue')
93  $this->frontendCompilationMock->expects(self::once())
94  ->method('process')
95  ->with($chainMock);
96  $this->alternativeSourceMock->expects(self::never())
97  ->method('process');
98  $this->stateMock->expects($this->atLeastOnce())
99  ->method('getMode')
100  ->willReturn(State::MODE_DEVELOPER);
101 
102  $this->preprocessorStrategy->process($chainMock);
103  }
104 
106  {
107  $chainMock = $this->getChainMock();
108 
109  $this->scopeConfigMock->expects(self::once())
110  ->method('getValue')
113  $this->frontendCompilationMock->expects(self::once())
114  ->method('process')
115  ->with($chainMock);
116  $this->alternativeSourceMock->expects(self::never())
117  ->method('process');
118  $this->stateMock->expects($this->once())
119  ->method('getMode')
120  ->willReturn(State::MODE_DEFAULT);
121 
122  \Magento\Framework\App\ObjectManager::setInstance($this->objectMangerMock);
123 
124  $this->preprocessorStrategy->process($chainMock);
125  }
126 
131  {
132  $chainMock = $this->getChainMock();
133 
134  $this->scopeConfigMock->expects($this->never())
135  ->method('getValue')
137  ->willReturn('off');
138  $this->alternativeSourceMock->expects(self::once())
139  ->method('process')
140  ->with($chainMock);
141  $this->frontendCompilationMock->expects(self::never())
142  ->method('process');
143  $this->stateMock->expects($this->atLeastOnce())
144  ->method('getMode')
145  ->willReturn(State::MODE_PRODUCTION);
146 
147  $this->preprocessorStrategy->process($chainMock);
148  }
149 
153  private function getChainMock()
154  {
155  $chainMock = $this->getMockBuilder(Chain::class)
156  ->disableOriginalConstructor()
157  ->getMock();
158 
159  return $chainMock;
160  }
161 }
static setInstance(\Magento\Framework\ObjectManagerInterface $objectManager)