Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigGeneratorTest.php
Go to the documentation of this file.
1 <?php
2 /***
3  * Copyright © Magento, Inc. All rights reserved.
4  * See COPYING.txt for license details.
5  */
7 
14 
15 class ConfigGeneratorTest extends \PHPUnit\Framework\TestCase
16 {
20  private $deploymentConfigMock;
21 
25  private $model;
26 
30  private $configDataMock;
31 
32  public function setUp()
33  {
34  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
35 
36  $this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
37  ->disableOriginalConstructor()
38  ->getMock();
39 
40  $this->configDataMock = $this->getMockBuilder(ConfigData::class)
41  ->disableOriginalConstructor()
42  ->setMethods(['set'])
43  ->getMock();
44 
45  $configDataFactoryMock = $this->getMockBuilder(ConfigDataFactory::class)
46  ->disableOriginalConstructor()
47  ->setMethods(['create'])
48  ->getMock();
49 
50  $configDataFactoryMock->method('create')
51  ->willReturn($this->configDataMock);
52 
53  $this->model = $objectManager->getObject(
54  ConfigGenerator::class,
55  [
56  'deploymentConfig' => $this->deploymentConfigMock,
57  'configDataFactory' => $configDataFactoryMock,
58  ]
59  );
60  }
61 
62  public function testCreateXFrameConfig()
63  {
64  $this->deploymentConfigMock->expects($this->atLeastOnce())
65  ->method('get')
67  ->willReturn(null);
68 
69  $this->configDataMock
70  ->expects($this->once())
71  ->method('set')
73 
74  $this->model->createXFrameConfig();
75  }
76 
77  public function testCreateCacheHostsConfig()
78  {
79  $data = [ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS => 'localhost:8080, website.com, 120.0.0.1:90'];
80  $expectedData = [
81  0 => [
82  'host' => 'localhost',
83  'port' => '8080',
84  ],
85  1 => [
86  'host' => 'website.com',
87  ],
88  2 => [
89  'host' => '120.0.0.1',
90  'port' => '90',
91  ],
92  ];
93 
94  $this->configDataMock
95  ->expects($this->once())
96  ->method('set')
98 
99  $this->model->createCacheHostsConfig($data);
100  }
101 
102  public function testCreateModeConfig()
103  {
104  $this->deploymentConfigMock->expects($this->once())
105  ->method('get')
106  ->with(State::PARAM_MODE)
107  ->willReturn(null);
108 
109  $this->configDataMock
110  ->expects($this->once())
111  ->method('set')
113 
114  $this->model->createModeConfig();
115  }
116 
118  {
119  $this->deploymentConfigMock->expects($this->once())
120  ->method('get')
121  ->with(State::PARAM_MODE)
122  ->willReturn(State::MODE_PRODUCTION);
123  $configData = $this->model->createModeConfig();
124  $this->assertSame([], $configData->getData());
125  }
126 
127  public function testCreateCryptKeyConfig()
128  {
129  $key = 'my-new-key';
131 
132  $this->deploymentConfigMock
133  ->method('get')
135  ->willReturn(null);
136 
137  $this->configDataMock
138  ->expects($this->once())
139  ->method('set')
141 
142  $this->model->createCryptConfig($data);
143  }
144 }
$objectManager
Definition: bootstrap.php:17