8000 Created failing test for 33084 · symfony/symfony@1cb0b1b · GitHub
[go: up one dir, main page]

Skip to content

Commit 1cb0b1b

Browse files
committed
Created failing test for 33084
1 parent e44a3f5 commit 1cb0b1b

File tree

4 files changed

+67
-0
lines changed

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+
/**
14+
* @var FlashBagInterface
15+
*/
16+
private $flashBag;
17+
18+
/**
19+
* @var RouterInterface
20+
*/
21+
private $router;
22+
23+
public function __construct(
24+
FlashBagInterface $flashBag,
25+
RouterInterface $router
26+
) {
27+
$this->flashBag = $flashBag;
28+
$this->router = $router;
29+
}
30+
31+
public function setFlashAction(Request $request, $message)
32+
{
33+
$this->flashBag->add('notice', $message);
34+
return new RedirectResponse($this->router->generate('session_showflash'));
35+
}
36+
}

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

Lines 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

Lines 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

Lines 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