Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/122'
Browse files Browse the repository at this point in the history
Close #122
  • Loading branch information
michalbundyra committed Sep 19, 2019
2 parents 5009f30 + d0ee910 commit 9d7d39c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#122](https://github.com/zendframework/zend-session/pull/122) fixes
type check for configuration of session storage. Allows input to be
an instance of ArrayAccess or an array.

## 2.8.6 - 2019-08-11

Expand Down
7 changes: 3 additions & 4 deletions src/Storage/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,16 @@ protected static function createSessionArrayStorage($type, array $options)
{
$input = null;
if (isset($options['input'])) {
if (null !== $options['input']
&& ! is_array($options['input'])
$input = $options['input'];
if (! is_array($input)
&& ! $input instanceof ArrayAccess
) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects the "input" option to be null, an array, or to implement ArrayAccess; received "%s"',
$type,
(is_object($options['input']) ? get_class($options['input']) : gettype($options['input']))
is_object($input) ? get_class($input) : gettype($input)
));
}
$input = $options['input'];
}

return new $type($input);
Expand Down
26 changes: 26 additions & 0 deletions test/Service/StorageFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ZendTest\Session\Service;

use ArrayObject;
use PHPUnit\Framework\TestCase;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
Expand Down Expand Up @@ -68,6 +69,16 @@ public function sessionStorageConfig()
],
],
], SessionArrayStorage::class],
'session-array-storage-arrayobject' => [[
'session_storage' => [
'type' => 'SessionArrayStorage',
'options' => [
'input' => new ArrayObject([
'foo' => 'bar',
]),
],
],
], SessionArrayStorage::class],
'session-array-storage-fqcn' => [[
'session_storage' => [
'type' => SessionArrayStorage::class,
Expand All @@ -93,6 +104,21 @@ public function testUsesConfigurationToCreateStorage($config, $class)
$this->assertEquals($config['session_storage']['options']['input'], $test);
}

public function testConfigurationWithoutInputIsValid()
{
$this->services->setService('config', [
'session_storage' => [
'type' => SessionArrayStorage::class,
'options' => [],
],
]);

$storage = $this->services->get(StorageInterface::class);

$this->assertInstanceOf(SessionArrayStorage::class, $storage);
$this->assertSame([], $storage->toArray());
}

public function invalidSessionStorageConfig()
{
return [
Expand Down

0 comments on commit 9d7d39c

Please sign in to comment.