Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ed42313

Browse filesBrowse files
committed
Created failing test for 33084
1 parent e44a3f5 commit ed42313
Copy full SHA for ed42313

File tree

4 files changed

+67
-0
lines changed
Filter options

4 files changed

+67
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
4+
5+
use Symfony\Component\HttpFoundation\RedirectResponse;
6+
use Symfony\Component\HttpFoundation\Request;
7+
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
8+
use Symfony\Component\Routing\RouterInterface;
9+
10+
class InjectedFlashbagSessionController
11+
{
12+
/**
13+
* @var FlashBagInterface
14+
*/
15+
private $flashBag;
16+
17+
/**
18+
* @var RouterInterface
19+
*/
20+
private $router;
21+
22+
public function __construct(
23+
FlashBagInterface $flashBag,
24+
RouterInterface $router
25+
) {
26+
$this->flashBag = $flashBag;
27+
$this->router = $router;
28+
}
29+
30+
public function setFlashAction(Request $request, $message)
31+
{
32+
$this->flashBag->add('notice', $message);
33+
34+
return new RedirectResponse($this->router->generate('session_showflash'));
35+
}
36+
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ session_setflash:
1818
path: /session_setflash/{message}
1919
defaults: { _controller: TestBundle:Session:setFlash}
2020

21+
injected_flashbag_session_setflash:
22+
path: injected_flashbag/session_setflash/{message}
23+
defaults: { _controller: TestBundle:InjectedFlashbagSession:setFlash}
24+
2125
session_showflash:
2226
path: /session_showflash
2327
defaults: { _controller: TestBundle:Session:showFlash}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,29 @@ public function testFlash($config, $insulate)
6969
$this->assertStringContainsString('No flash was set.', $crawler->text());
7070
}
7171

72+
/**
73+
* Tests flash messages work when flashbag service is injected to the constructor.
74+
*
75+
* @dataProvider getConfigs
76+
*/
77+
public function testFlashOnInjectedFlashbag($config, $insulate)
78+
{
79+
$client = $this->createClient(['test_case' => 'Session', 'root_config' => $config]);
80+
if ($insulate) {
81+
$client->insulate();
82+
}
83+
84+
// set flash
85+
$client->request('GET', '/injected_flashbag/session_setflash/Hello%20world.');
86+
87+
// check flash displays on redirect
88+
$this->assertStringContainsString('Hello world.', $client->followRedirect()->text());
89+
90+
// check flash is gone
91+
$crawler = $client->request('GET', '/session_showflash');
92+
$this->assertStringContainsString('No flash was set.', $crawler->text());
93+
}
94+
7295
/**
7396
* See if two separate insulated clients can run without
7497
* polluting each other's session data.

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Session/config.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Session/config.yml
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ services:
55
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SubRequestController:
66
tags:
77
- { name: controller.service_arguments, action: indexAction, argument: handler, id: fragment.handler }
8+
9+
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\InjectedFlashbagSessionController:
10+
autowire: true
11+
tags: ['controller.service_arguments']

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.