88 lines
4.4 KiB
YAML
88 lines
4.4 KiB
YAML
|
name: MockArraySessionStorage
|
||
|
class_comment: '# * MockArraySessionStorage mocks the session for unit tests.
|
||
|
|
||
|
# *
|
||
|
|
||
|
# * No PHP session is actually started since a session can be initialized
|
||
|
|
||
|
# * and shutdown only once per PHP execution cycle.
|
||
|
|
||
|
# *
|
||
|
|
||
|
# * When doing functional testing, you should use MockFileSessionStorage instead.
|
||
|
|
||
|
# *
|
||
|
|
||
|
# * @author Fabien Potencier <fabien@symfony.com>
|
||
|
|
||
|
# * @author Bulat Shakirzyanov <mallluhuct@gmail.com>
|
||
|
|
||
|
# * @author Drak <drak@zikula.org>'
|
||
|
dependencies:
|
||
|
- name: SessionBagInterface
|
||
|
type: class
|
||
|
source: Symfony\Component\HttpFoundation\Session\SessionBagInterface
|
||
|
properties: []
|
||
|
methods:
|
||
|
- name: getMetadataBag
|
||
|
visibility: public
|
||
|
parameters: []
|
||
|
comment: "# * MockArraySessionStorage mocks the session for unit tests.\n# *\n#\
|
||
|
\ * No PHP session is actually started since a session can be initialized\n# *\
|
||
|
\ and shutdown only once per PHP execution cycle.\n# *\n# * When doing functional\
|
||
|
\ testing, you should use MockFileSessionStorage instead.\n# *\n# * @author Fabien\
|
||
|
\ Potencier <fabien@symfony.com>\n# * @author Bulat Shakirzyanov <mallluhuct@gmail.com>\n\
|
||
|
# * @author Drak <drak@zikula.org>\n# */\n# class MockArraySessionStorage implements\
|
||
|
\ SessionStorageInterface\n# {\n# protected string $id = '';\n# protected bool\
|
||
|
\ $started = false;\n# protected bool $closed = false;\n# protected array $data\
|
||
|
\ = [];\n# protected MetadataBag $metadataBag;\n# \n# /**\n# * @var SessionBagInterface[]\n\
|
||
|
# */\n# protected array $bags = [];\n# \n# public function __construct(\n# protected\
|
||
|
\ string $name = 'MOCKSESSID',\n# ?MetadataBag $metaBag = null,\n# ) {\n# $this->setMetadataBag($metaBag);\n\
|
||
|
# }\n# \n# public function setSessionData(array $array): void\n# {\n# $this->data\
|
||
|
\ = $array;\n# }\n# \n# public function start(): bool\n# {\n# if ($this->started)\
|
||
|
\ {\n# return true;\n# }\n# \n# if (!$this->id) {\n# $this->id = $this->generateId();\n\
|
||
|
# }\n# \n# $this->loadSession();\n# \n# return true;\n# }\n# \n# public function\
|
||
|
\ regenerate(bool $destroy = false, ?int $lifetime = null): bool\n# {\n# if (!$this->started)\
|
||
|
\ {\n# $this->start();\n# }\n# \n# $this->metadataBag->stampNew($lifetime);\n\
|
||
|
# $this->id = $this->generateId();\n# \n# return true;\n# }\n# \n# public function\
|
||
|
\ getId(): string\n# {\n# return $this->id;\n# }\n# \n# public function setId(string\
|
||
|
\ $id): void\n# {\n# if ($this->started) {\n# throw new \\LogicException('Cannot\
|
||
|
\ set session ID after the session has started.');\n# }\n# \n# $this->id = $id;\n\
|
||
|
# }\n# \n# public function getName(): string\n# {\n# return $this->name;\n# }\n\
|
||
|
# \n# public function setName(string $name): void\n# {\n# $this->name = $name;\n\
|
||
|
# }\n# \n# public function save(): void\n# {\n# if (!$this->started || $this->closed)\
|
||
|
\ {\n# throw new \\RuntimeException('Trying to save a session that was not started\
|
||
|
\ yet or was already closed.');\n# }\n# // nothing to do since we don't persist\
|
||
|
\ the session data\n# $this->closed = false;\n# $this->started = false;\n# }\n\
|
||
|
# \n# public function clear(): void\n# {\n# // clear out the bags\n# foreach ($this->bags\
|
||
|
\ as $bag) {\n# $bag->clear();\n# }\n# \n# // clear out the session\n# $this->data\
|
||
|
\ = [];\n# \n# // reconnect the bags to the session\n# $this->loadSession();\n\
|
||
|
# }\n# \n# public function registerBag(SessionBagInterface $bag): void\n# {\n\
|
||
|
# $this->bags[$bag->getName()] = $bag;\n# }\n# \n# public function getBag(string\
|
||
|
\ $name): SessionBagInterface\n# {\n# if (!isset($this->bags[$name])) {\n# throw\
|
||
|
\ new \\InvalidArgumentException(\\sprintf('The SessionBagInterface \"%s\" is\
|
||
|
\ not registered.', $name));\n# }\n# \n# if (!$this->started) {\n# $this->start();\n\
|
||
|
# }\n# \n# return $this->bags[$name];\n# }\n# \n# public function isStarted():\
|
||
|
\ bool\n# {\n# return $this->started;\n# }\n# \n# public function setMetadataBag(?MetadataBag\
|
||
|
\ $bag): void\n# {\n# $this->metadataBag = $bag ?? new MetadataBag();\n# }\n#\
|
||
|
\ \n# /**\n# * Gets the MetadataBag."
|
||
|
- name: generateId
|
||
|
visibility: protected
|
||
|
parameters: []
|
||
|
comment: '# * Generates a session ID.
|
||
|
|
||
|
# *
|
||
|
|
||
|
# * This doesn''t need to be particularly cryptographically secure since this
|
||
|
is just
|
||
|
|
||
|
# * a mock.'
|
||
|
- name: loadSession
|
||
|
visibility: protected
|
||
|
parameters: []
|
||
|
comment: null
|
||
|
traits:
|
||
|
- Symfony\Component\HttpFoundation\Session\SessionBagInterface
|
||
|
interfaces:
|
||
|
- SessionStorageInterface
|