Skip to content

Commit

Permalink
Separate controllers per feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Jul 31, 2014
1 parent c166470 commit a329d76
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 44 deletions.
8 changes: 4 additions & 4 deletions Tests/Functional/EventListener/TagSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public function testAnnotationTagsAreSet()
{
$client = static::createClient();

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

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

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

public function testErrorIsNotInvalidated()
Expand All @@ -56,7 +56,7 @@ public function testErrorIsNotInvalidated()
->shouldReceive('flush')->once()
;

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

public function testConfigurationTagsAreSet()
Expand Down
49 changes: 49 additions & 0 deletions Tests/Functional/Fixtures/Controller/TagController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the FOSHttpCacheBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use FOS\HttpCacheBundle\Configuration\Tag;

class TagController extends Controller
{
/**
* @Tag("all-items")
* @Tag("item-123")
*/
public function listAction()
{
return new Response('All items including 123');
}

/**
* @Tag(expression="'item-'~id")
*/
public function itemAction(Request $request, $id)
{
if (!$request->isMethodSafe()) {
$this->container->get('fos_http_cache.cache_manager')->invalidateTags(array('all-items'));
}

return new Response('Item ' . $id . ' invalidated');
}

/**
* @Tag("items")
*/
public function errorAction()
{
return new Response('Forbidden', 403);
}
}
31 changes: 0 additions & 31 deletions Tests/Functional/Fixtures/Controller/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,10 @@
namespace FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use FOS\HttpCacheBundle\Configuration\Tag;

class TestController extends Controller
{
/**
* @Tag("all-items")
* @Tag("item-123")
*/
public function listAction()
{
return new Response('All items including 123');
}

/**
* @Tag(expression="'item-'~id")
*/
public function itemAction(Request $request, $id)
{
if (!$request->isMethodSafe()) {
$this->container->get('fos_http_cache.cache_manager')->invalidateTags(array('all-items'));
}

return new Response('Item ' . $id . ' invalidated');
}

/**
* @Tag("items")
*/
public function errorAction()
{
return new Response('Forbidden', 403);
}

public function contentAction($id = null)
{
return new Response('content ' . $id);
Expand Down
18 changes: 9 additions & 9 deletions Tests/Functional/Fixtures/app/config/routing.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
test_list:
pattern: /test/list
defaults: { _controller: FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller\TestController::listAction }
tag_list:
pattern: /tag/list
defaults: { _controller: FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller\TagController::listAction }
methods: [GET]

test_error:
pattern: /test/error
defaults: { _controller: FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller\TestController::errorAction }
tag_error:
pattern: /tag/error
defaults: { _controller: FOS\HttpCacheBundle\Tests\Functional\Fixtures\Controller\TagController::errorAction }

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

test_cached:
Expand Down

0 comments on commit a329d76

Please sign in to comment.