function MockSessionTrait::createSessionMock
Same name in other branches
- 4.0.x modules/stream_wrapper_example/tests/src/Traits/MockSessionTrait.php \Drupal\Tests\stream_wrapper_example\Traits\MockSessionTrait::createSessionMock()
Create a mock session object.
Return value
\Symfony\Component\HttpFoundation\RequestStack|\Prophecy\Prophecy\ProphecyInterface A test double, or mock, of a RequestStack object that can be used to return a mock Session object.
2 calls to MockSessionTrait::createSessionMock()
- SessionHelperTest::setUp in modules/
stream_wrapper_example/ tests/ src/ Unit/ SessionHelperTest.php - StreamWrapperTest::setUp in modules/
stream_wrapper_example/ tests/ src/ Kernel/ StreamWrapperTest.php
File
-
modules/
stream_wrapper_example/ tests/ src/ Traits/ MockSessionTrait.php, line 40
Class
- MockSessionTrait
- A trait to expose a mock session type to PHPUnit tests.
Namespace
Drupal\Tests\stream_wrapper_example\TraitsCode
protected function createSessionMock() {
$this->sessionStore = [];
$session = $this->prophesize(SessionInterface::class);
$test = $this;
$session->get('stream_wrapper_example', [])
->will(function ($args) use ($test) {
return $test->getSessionStore();
});
$session->set('stream_wrapper_example', Argument::any())
->will(function ($args) use ($test) {
$test->setSessionStore($args[1]);
});
$session->remove('stream_wrapper_example')
->will(function ($args) use ($test) {
$test->resetSessionStore();
});
$request = $this->prophesize(Request::class);
$request->getSession()
->willReturn($session->reveal());
$request_stack = $this->prophesize(RequestStack::class);
$request_stack->getCurrentRequest()
->willReturn($request->reveal());
return $this->requestStack = $request_stack->reveal();
}