Inside the Controller public
function
listAction(Request
$request) {
//
load
tasks
from
db
return
new
Response(
$this-‐>templating-‐>render(
'list.php',
array(
'urlGenerator'
=>
$router-‐>getGenerator(),
'tasks'
=>
$tasks
)
)
); }
Let the kernel handle it. $dispatcher
=
new
EventDispatcher(); $dispatcher-‐>addSubscriber(
new
RouterListener($router-‐>getMatcher()) ); $resolver
=
new
MyControllerResolver($controller); $kernel
=
new
HttpKernel($dispatcher,
$resolver); $request
=
Request::createFromGlobals(); $response
=
$kernel-‐>handle($request); $response-‐>send();
Controller Resolver? interface
ControllerResolverInterface {
public
function
getController(Request
$request);
public
function
getArguments(Request
$request,
$controller); }
Base Test use
Symfony\Component\HttpKernel\Client; class
FunctionalTestCase
extends
\PHPUnit_Framework_TestCase {
protected
static
function
createClient()
{
$kernel
=
//
somehow
create
a
kernel
return
new
Client($kernel);
} }
A Test Case class
IndexPageTest
extends
FunctionalTestCase {
public
function
testList()
{
$client
=
static::createClient();
$crawler
=
$client-‐>request('GET',
'/');
$this-‐>assertEquals(200,
$client-‐>getResponse()-‐>getStatusCode());
$this-‐>assertCount(1,
$crawler-‐>filter('h1:contains("My
Todos
List")'));
} }
Commands use
Symfony\Component\Console\Command\Command; class
AddTaskCommand
extends
Command {
public
function
configure()
{
$this-‐>setName('todo:add');
$this-‐>setDescription('Add
a
new
task
to
your
todo
list');
$this-‐>addArgument('title',
InputArgument::OPTIONAL,
'The
task
title');
}
//
... }
Execution public
function
execute(InputInterface
$input,
OutputInterface
$output) {
$dialog
=
$this-‐>getHelperSet()-‐>get('dialog');
$title
=
$dialog-‐>ask(
$output,
'What
do
you
have
to
do?
'
);
if
($title)
{
//
do
stuff
$output-‐>writeln('Task
created.');
}
else
{
$output-‐>writeln('No
input
given!');
} }