Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 2c4b5b0

Browse files
author
Volodymyr Kublytskyi
authored
MAGETWO-83373: Fix for issue 9633 500 error on setup wizard with memcache #11608
2 parents b1e5c25 + eb221a9 commit 2c4b5b0

File tree

3 files changed

+54
-34
lines changed

3 files changed

+54
-34
lines changed

dev/tests/integration/testsuite/Magento/Framework/Session/ConfigTest.php

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ protected function setUp()
3636
$sessionManager->writeClose();
3737
}
3838
$this->deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
39-
40-
$this->deploymentConfigMock->expects($this->at(0))
41-
->method('get')
42-
->with(Config::PARAM_SESSION_SAVE_PATH)
43-
->will($this->returnValue(null));
44-
$this->deploymentConfigMock->expects($this->at(1))
39+
$this->deploymentConfigMock
4540
->method('get')
46-
->with(Config::PARAM_SESSION_CACHE_LIMITER)
47-
->will($this->returnValue($this->_cacheLimiter));
41+
->willReturnCallback(function ($configPath) {
42+
switch ($configPath) {
43+
case Config::PARAM_SESSION_SAVE_METHOD:
44+
return 'files';
45+
case Config::PARAM_SESSION_CACHE_LIMITER:
46+
return $this->_cacheLimiter;
47+
default:
48+
return null;
49+
}
50+
});
4851

4952
$this->_model = $this->_objectManager->create(
5053
\Magento\Framework\Session\Config::class,
@@ -83,15 +86,6 @@ public function testDefaultConfiguration()
8386
$this->assertEquals($this->_model->getSavePath(), $this->_model->getOption('save_path'));
8487
}
8588

86-
/**
87-
* Unable to add integration tests for testGetLifetimePathNonDefault
88-
*
89-
* Error: Cannot modify header information - headers already sent
90-
*/
91-
public function testGetLifetimePathNonDefault()
92-
{
93-
}
94-
9589
public function testSetOptionsInvalidValue()
9690
{
9791
$preValue = $this->_model->getOptions();
@@ -280,16 +274,27 @@ public function testConstructorSavePath($existing, $given, $expected)
280274
$this->markTestSkipped('Cannot set session.save_path with ini_set');
281275
}
282276

283-
$this->deploymentConfigMock->expects($this->at(0))
277+
$deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
278+
$deploymentConfigMock
284279
->method('get')
285-
->with(Config::PARAM_SESSION_SAVE_PATH)
286-
->will($this->returnValue($given));
287-
288-
$this->_model = $this->_objectManager->create(
280+
->willReturnCallback(function ($configPath) use ($given) {
281+
switch ($configPath) {
282+
case Config::PARAM_SESSION_SAVE_METHOD:
283+
return 'files';
284+
case Config::PARAM_SESSION_CACHE_LIMITER:
285+
return $this->_cacheLimiter;
286+
case Config::PARAM_SESSION_SAVE_PATH:
287+
return $given;
288+
default:
289+
return null;
290+
}
291+
});
292+
293+
$model = $this->_objectManager->create(
289294
\Magento\Framework\Session\Config::class,
290-
['deploymentConfig' => $this->deploymentConfigMock]
295+
['deploymentConfig' => $deploymentConfigMock]
291296
);
292-
$this->assertEquals($expected, $this->_model->getOption('save_path'));
297+
$this->assertEquals($expected, $model->getOption('save_path'));
293298

294299
if ($sessionSavePath != ini_get('session.save_path')) {
295300
ini_set('session.save_path', $sessionSavePath);

lib/internal/Magento/Framework/Session/Config.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ public function __construct(
134134
$this->setSavePath($savePath);
135135
}
136136

137+
/**
138+
* Session save handler - memcache, files, etc
139+
*/
140+
$saveHandler = $deploymentConfig->get(self::PARAM_SESSION_SAVE_METHOD);
141+
if ($saveHandler) {
142+
$this->setOption('session.save_handler', $saveHandler);
143+
}
144+
137145
/**
138146
* Session cache limiter
139147
*/

lib/internal/Magento/Framework/Session/Test/Unit/ConfigTest.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -350,33 +350,36 @@ public function constructorDataProvider()
350350
true,
351351
true,
352352
[
353-
'session.cache_limiter' => 'files',
353+
'session.cache_limiter' => 'private_no_expire',
354354
'session.cookie_lifetime' => 7200,
355355
'session.cookie_path' => '/',
356356
'session.cookie_domain' => 'init.host',
357357
'session.cookie_httponly' => false,
358358
'session.cookie_secure' => false,
359+
'session.save_handler' => 'files'
359360
],
360361
],
361362
'all invalid' => [
362363
true,
363364
false,
364365
[
365-
'session.cache_limiter' => 'files',
366+
'session.cache_limiter' => 'private_no_expire',
366367
'session.cookie_httponly' => false,
367368
'session.cookie_secure' => false,
369+
'session.save_handler' => 'files'
368370
],
369371
],
370372
'invalid_valid' => [
371373
false,
372374
true,
373375
[
374-
'session.cache_limiter' => 'files',
376+
'session.cache_limiter' => 'private_no_expire',
375377
'session.cookie_lifetime' => 3600,
376378
'session.cookie_path' => '/',
377379
'session.cookie_domain' => 'init.host',
378380
'session.cookie_httponly' => false,
379381
'session.cookie_secure' => false,
382+
'session.save_handler' => 'files'
380383
],
381384
],
382385
];
@@ -429,14 +432,18 @@ protected function getModel($validator)
429432
->will($this->returnValue($dirMock));
430433

431434
$deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
432-
$deploymentConfigMock->expects($this->at(0))
435+
$deploymentConfigMock
433436
->method('get')
434-
->with(Config::PARAM_SESSION_SAVE_PATH)
435-
->will($this->returnValue(null));
436-
$deploymentConfigMock->expects($this->at(1))
437-
->method('get')
438-
->with(Config::PARAM_SESSION_CACHE_LIMITER)
439-
->will($this->returnValue('files'));
437+
->willReturnCallback(function ($configPath) {
438+
switch ($configPath) {
439+
case Config::PARAM_SESSION_SAVE_METHOD:
440+
return 'files';
441+
case Config::PARAM_SESSION_CACHE_LIMITER:
442+
return 'private_no_expire';
443+
default:
444+
return null;
445+
}
446+
});
440447

441448
$this->config = $this->helper->getObject(
442449
\Magento\Framework\Session\Config::class,

0 commit comments

Comments
 (0)