Skip to content

Commit a329d76

Browse files
committed
Separate controllers per feature
1 parent c166470 commit a329d76

File tree

4 files changed

+62
-44
lines changed

4 files changed

+62
-44
lines changed

Tests/Functional/EventListener/TagSubscriberTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public function testAnnotationTagsAreSet()
1919
{
2020
$client = static::createClient();
2121

22-
$client->request('GET', '/test/list');
22+
$client->request('GET', '/tag/list');
2323
$response = $client->getResponse();
2424
$this->assertEquals('all-items,item-123', $response->headers->get('X-Cache-Tags'));
2525

26-
$client->request('GET', '/test/123');
26+
$client->request('GET', '/tag/123');
2727
$response = $client->getResponse();
2828
$this->assertEquals('item-123', $response->headers->get('X-Cache-Tags'));
2929
}
@@ -41,7 +41,7 @@ public function testAnnotationTagsAreInvalidated()
4141
->shouldReceive('flush')->once()
4242
;
4343

44-
$client->request('POST', '/test/123');
44+
$client->request('POST', '/tag/123');
4545
}
4646

4747
public function testErrorIsNotInvalidated()
@@ -56,7 +56,7 @@ public function testErrorIsNotInvalidated()
5656
->shouldReceive('flush')->once()
5757
;
5858

59-
$client->request('POST', '/test/error');
59+
$client->request('POST', '/tag/error');
6060
}
6161

6262
public function testConfigurationTagsAreSet()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSHttpCacheBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller;
13+
14+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpFoundation\Response;
17+
use FOS\HttpCacheBundle\Configuration\Tag;
18+
19+
class TagController extends Controller
20+
{
21+
/**
22+
* @Tag("all-items")
23+
* @Tag("item-123")
24+
*/
25+
public function listAction()
26+
{
27+
return new Response('All items including 123');
28+
}
29+
30+
/**
31+
* @Tag(expression="'item-'~id")
32+
*/
33+
public function itemAction(Request $request, $id)
34+
{
35+
if (!$request->isMethodSafe()) {
36+
$this->container->get('fos_http_cache.cache_manager')->invalidateTags(array('all-items'));
37+
}
38+
39+
return new Response('Item ' . $id . ' invalidated');
40+
}
41+
42+
/**
43+
* @Tag("items")
44+
*/
45+
public function errorAction()
46+
{
47+
return new Response('Forbidden', 403);
48+
}
49+
}

Tests/Functional/Fixtures/Controller/TestController.php

-31
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,10 @@
1212
namespace FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller;
1313

1414
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
15-
use Symfony\Component\HttpFoundation\Request;
1615
use Symfony\Component\HttpFoundation\Response;
17-
use FOS\HttpCacheBundle\Configuration\Tag;
1816

1917
class TestController extends Controller
2018
{
21-
/**
22-
* @Tag("all-items")
23-
* @Tag("item-123")
24-
*/
25-
public function listAction()
26-
{
27-
return new Response('All items including 123');
28-
}
29-
30-
/**
31-
* @Tag(expression="'item-'~id")
32-
*/
33-
public function itemAction(Request $request, $id)
34-
{
35-
if (!$request->isMethodSafe()) {
36-
$this->container->get('fos_http_cache.cache_manager')->invalidateTags(array('all-items'));
37-
}
38-
39-
return new Response('Item ' . $id . ' invalidated');
40-
}
41-
42-
/**
43-
* @Tag("items")
44-
*/
45-
public function errorAction()
46-
{
47-
return new Response('Forbidden', 403);
48-
}
49-
5019
public function contentAction($id = null)
5120
{
5221
return new Response('content ' . $id);

Tests/Functional/Fixtures/app/config/routing.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
test_list:
2-
pattern: /test/list
3-
defaults: { _controller: FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller\TestController::listAction }
1+
tag_list:
2+
pattern: /tag/list
3+
defaults: { _controller: FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller\TagController::listAction }
44
methods: [GET]
55

6-
test_error:
7-
pattern: /test/error
8-
defaults: { _controller: FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller\TestController::errorAction }
6+
tag_error:
7+
pattern: /tag/error
8+
defaults: { _controller: FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller\TagController::errorAction }
99

10-
test_one:
11-
pattern: /test/{id}
12-
defaults: { _controller: FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller\TestController::itemAction }
10+
tag_one:
11+
pattern: /tag/{id}
12+
defaults: { _controller: FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller\TagController::itemAction }
1313
methods: [GET,POST]
1414

1515
test_cached:

0 commit comments

Comments
 (0)