Skip to content

Commit 4b322c8

Browse files
author
Dale Sikkema
committed
MAGETWO-31851: [GITHUB] Failed to set ini option "session.save_path" to value #792
1 parent 9c19d10 commit 4b322c8

File tree

3 files changed

+65
-11
lines changed

3 files changed

+65
-11
lines changed

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

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
2626
*/
2727
protected $_objectManager;
2828

29+
/**
30+
* @var string Default value for session.save_path setting
31+
*/
32+
protected $defaultSavePath;
33+
34+
/**
35+
* @var \Magento\Framework\App\DeploymentConfig | \PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
protected $deploymentConfigMock;
38+
2939
protected function setUp()
3040
{
3141
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
@@ -34,24 +44,27 @@ protected function setUp()
3444
if ($sessionManager->isSessionExists()) {
3545
$sessionManager->writeClose();
3646
}
37-
$deploymentConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
38-
$deploymentConfigMock->expects($this->at(0))
47+
$this->deploymentConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
48+
$this->deploymentConfigMock->expects($this->at(0))
3949
->method('get')
4050
->with(Config::PARAM_SESSION_SAVE_METHOD, 'files')
4151
->will($this->returnValue('files'));
42-
$deploymentConfigMock->expects($this->at(1))
52+
$this->deploymentConfigMock->expects($this->at(1))
4353
->method('get')
4454
->with(Config::PARAM_SESSION_SAVE_PATH)
4555
->will($this->returnValue(null));
46-
$deploymentConfigMock->expects($this->at(2))
56+
$this->deploymentConfigMock->expects($this->at(2))
4757
->method('get')
4858
->with(Config::PARAM_SESSION_CACHE_LIMITER)
4959
->will($this->returnValue($this->_cacheLimiter));
5060

5161
$this->_model = $this->_objectManager->create(
5262
'Magento\Framework\Session\Config',
53-
['deploymentConfig' => $deploymentConfigMock]
63+
['deploymentConfig' => $this->deploymentConfigMock]
5464
);
65+
$this->defaultSavePath = $this->_objectManager
66+
->get('Magento\Framework\Filesystem\DirectoryList')
67+
->getPath(DirectoryList::SESSION);
5568
}
5669

5770
protected function tearDown()
@@ -282,4 +295,47 @@ public function testSetSavePath()
282295
$this->_model->setSavePath('some_save_path');
283296
$this->assertEquals($this->_model->getOption('save_path'), 'some_save_path');
284297
}
298+
299+
/**
300+
* @dataProvider savePathDataProvider
301+
*/
302+
public function testConstructorSavePath($existing, $given, $expected)
303+
{
304+
$sessionSavePath = ini_get('session.save_path');
305+
if ($expected === 'default') {
306+
$expected = $this->defaultSavePath . '/';
307+
}
308+
$setup = ini_set('session.save_path', $existing);
309+
if ($setup === false) {
310+
$this->markTestSkipped('Cannot set session.save_path with ini_set');
311+
}
312+
313+
$this->deploymentConfigMock->expects($this->at(1))
314+
->method('get')
315+
->with(Config::PARAM_SESSION_SAVE_PATH)
316+
->will($this->returnValue($given));
317+
318+
$this->_model = $this->_objectManager->create(
319+
'Magento\Framework\Session\Config',
320+
['deploymentConfig' => $this->deploymentConfigMock]
321+
);
322+
$this->assertEquals($expected, $this->_model->getOption('save_path'));
323+
324+
if ($sessionSavePath != ini_get('session.save_path')) {
325+
ini_set('session.save_path', $sessionSavePath);
326+
}
327+
}
328+
329+
public function savePathDataProvider()
330+
{
331+
// preset value (null = not set), input value (null = not set), expected value
332+
$savePathGiven = 'explicit_save_path';
333+
$presetPath = 'preset_save_path';
334+
return [
335+
[null, $savePathGiven, $savePathGiven],
336+
[null, null, 'default'],
337+
[$presetPath, $savePathGiven, $savePathGiven],
338+
[$presetPath, null, $presetPath],
339+
];
340+
}
285341
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ public function constructorDataProvider()
363363
true,
364364
[
365365
'session.save_handler' => 'files',
366-
'session.save_path' => null,
367366
'session.cache_limiter' => 'files',
368367
'session.cookie_lifetime' => 7200,
369368
'session.cookie_path' => '/',
@@ -376,7 +375,6 @@ public function constructorDataProvider()
376375
false,
377376
[
378377
'session.save_handler' => 'files',
379-
'session.save_path' => null,
380378
'session.cache_limiter' => 'files',
381379
'session.cookie_httponly' => false,
382380
],
@@ -386,7 +384,6 @@ public function constructorDataProvider()
386384
true,
387385
[
388386
'session.save_handler' => 'files',
389-
'session.save_path' => null,
390387
'session.cache_limiter' => 'files',
391388
'session.cookie_lifetime' => 3600,
392389
'session.cookie_path' => '/',

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,14 @@ public function __construct(
135135

136136
$this->setSaveHandler($saveMethod === 'db' ? 'user' : $saveMethod);
137137

138-
if (!$savePath) {
138+
if (!$savePath && !ini_get('session.save_path')) {
139139
$sessionDir = $filesystem->getDirectoryWrite(DirectoryList::SESSION);
140140
$savePath = $sessionDir->getAbsolutePath();
141141
$sessionDir->create();
142142
}
143-
$this->setSavePath($savePath);
144-
143+
if ($savePath) {
144+
$this->setSavePath($savePath);
145+
}
145146
if ($cacheLimiter) {
146147
$this->setOption('session.cache_limiter', $cacheLimiter);
147148
}

0 commit comments

Comments
 (0)