File tree Expand file tree Collapse file tree 7 files changed +83
-14
lines changed Expand file tree Collapse file tree 7 files changed +83
-14
lines changed Original file line number Diff line number Diff line change 1
1
imports :
2
2
- { resource: parameters.yml }
3
3
- { resource: security.yml }
4
+ - { resource: services.yml }
4
5
5
6
framework :
6
7
# esi: ~
Original file line number Diff line number Diff line change 2
2
- { resource: config_dev.yml }
3
3
4
4
framework :
5
- test : ~
5
+ test : true
6
6
session :
7
7
storage_id : session.storage.mock_file
8
8
profiler :
Original file line number Diff line number Diff line change 1
- app :
2
- resource : @AppBundle/Controller/
3
- type : annotation
1
+ example :
2
+ pattern : /app/issue
3
+ defaults :
4
+ _controller : example_controller:issueAction
Original file line number Diff line number Diff line change
1
+ services :
2
+ example_transport :
3
+ class : Example
4
+ factory_class : Example
5
+ factory_method : fromSession
6
+ arguments :
7
+ - @session
8
+
9
+ example_controller :
10
+ class : AppBundle\Controller\DefaultController
11
+ arguments :
12
+ - @example_transport
13
+ tags :
14
+ - { name: kernel.event_subscriber }
Original file line number Diff line number Diff line change 3
3
namespace AppBundle \Controller ;
4
4
5
5
use Sensio \Bundle \FrameworkExtraBundle \Configuration \Route ;
6
- use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
6
+ use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
7
+ use Symfony \Component \HttpFoundation \Response ;
8
+ use Symfony \Component \HttpKernel \KernelEvents ;
7
9
8
- class DefaultController extends Controller
10
+ class DefaultController implements EventSubscriberInterface
9
11
{
10
- /**
11
- * @Route("/app/example", name="homepage")
12
- */
13
- public function indexAction ()
12
+ private $ example ;
13
+
14
+ public function __construct (\Example $ example )
15
+ {
16
+ $ this ->example = $ example ;
17
+ }
18
+
19
+ public function issueAction ()
20
+ {
21
+ return new Response ($ this ->example ->getUuid (), Response::HTTP_OK );
22
+ }
23
+
24
+ public function onKernelRequest ()
25
+ {
26
+ // This is just given to have the services created early enough.
27
+ }
28
+
29
+ public static function getSubscribedEvents ()
14
30
{
15
- return $ this ->render ('default/index.html.twig ' );
31
+ return array (
32
+ KernelEvents::REQUEST => array ('onKernelRequest ' , -2048 ),
33
+ );
16
34
}
17
35
}
Original file line number Diff line number Diff line change 6
6
7
7
class DefaultControllerTest extends WebTestCase
8
8
{
9
- public function testIndex ()
9
+ public function testIssue ()
10
10
{
11
11
$ client = static ::createClient ();
12
12
13
- $ crawler = $ client ->request ('GET ' , '/ ' );
13
+ $ crawler = $ client ->request ('GET ' , '/app/issue ' );
14
+ $ response = $ client ->getResponse ();
14
15
15
- $ this ->assertTrue ($ crawler ->filter ('html:contains("Homepage") ' )->count () > 0 );
16
+ $ expected = $ response ->getContent ();
17
+ static ::assertNotEmpty ($ expected );
18
+
19
+ $ crawler = $ client ->request ('GET ' , '/app/issue ' );
20
+ $ response = $ client ->getResponse ();
21
+
22
+ $ uuid = $ response ->getContent ();
23
+ static ::assertNotEmpty ($ uuid );
24
+ static ::assertEquals ($ expected , $ uuid );
16
25
}
17
26
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Symfony \Component \HttpFoundation \Session \SessionInterface ;
4
+
5
+ class Example
6
+ {
7
+ private $ uuid ;
8
+
9
+ public function __construct ()
10
+ {
11
+ $ this ->uuid = mt_rand ();
12
+ }
13
+
14
+ public function getUuid ()
15
+ {
16
+ return $ this ->uuid ;
17
+ }
18
+
19
+ public static function fromSession (SessionInterface $ session )
20
+ {
21
+ $ data = $ session ->get ('example_transport ' , new static ());
22
+ $ session ->set ('example_transport ' , $ data );
23
+
24
+ return $ data ;
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments