Login with Google
Frankenstests logo

Marcos' damn questions

Prove yourself with terrorific questions about Symfony2

1.- Which of these sentences are true about 'Symfony Framework'?
2.- What minimum version of PHP do you need to run Symfony Installer?
3.- Can you install a specific Symfony version with the Symfony Installer?
4.- Can you run a web server inside Symfony?
5.- How can you tackle the writing permissions challenge in the cache directory?
6.- In composer.json you have a package with spec 1.*. In your composer.lock, version 1.2.4 is set. There is a version 1.3.0 available of that package. Which of the following sentenes are true?
7.- What can you tell me about Symfony Distributions?
8.- What content-type header would you put in your Response if the content is a json?
9.- How can I return a Json file?
10.- How can I render t.html.twig from my controller?
11.- Assuming there are no other controllers, what would http://localhost:8000/hello return?
// src/AppBundle/Controller/HelloController.php

namespace AppBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class HelloController
{
/**
* @Route("/hello/{name}", name="hello")
*/
public function indexAction($name)
{

return new Response('Hello '.$name.'!');
}
}
12.- Given this controller, what will the output of http://localhost/hello/Mortadelo be?
// src/AppBundle/Controller/HelloController.php

namespace AppBundle\Controller;

use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class HelloController
{
/**
* @Route("/hello/{name}", name="hello")
*/
public function indexAction($name)
{
$text = "Name is ".$name;

return $text;
}
}
13.- Given this controller, what will the output of http://localhost/hello/Mortadelo/Filemon be?
// src/AppBundle/Controller/HelloController.php

// ...
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class HelloController
{
/**
* @Route("/hello/{firstName}/{lastName}", name="hello")
*/
public function indexAction($lastName, $firstName)
{

return new Response('Hello '.$firstName.', '.$lastName.'!');
}
}
14.- Given this controller, what will the output of http://localhost/hello/Mortadelo/Filemon be?
// src/AppBundle/Controller/HelloController.php

// ...
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class HelloController
{
/**
* @Route("/hello/{firstName}/{lastName}", name="hello")
*/
public function indexAction($lastName, $firstName, $company)
{

return new Response('Hello '.$firstName.', '.$lastName.'!');
}
}
15.- Given this controller, what will the output of http://localhost/hello/Mortadelo/Filemon be?
// src/AppBundle/Controller/HelloController.php
// ...

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class HelloController
{
/**
* @Route("/hello/{firstName}/{lastName}", name="hello")
*/
public function indexAction($lastName)
{

return new Response('Hello '.$lastName.'!');
}
}
16.- Given this controller, what will the output of http://localhost/hello/Mortadelo?lastName=Filemon be?
// src/AppBundle/Controller/HelloController.php
// ...

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class HelloController
{
/**
* @Route("/hello/{firstName}", name="hello")
*/
public function indexAction($firstName, Request $request)
{

$lastName = $request->request->get('lastName');

return new Response('Hello '.$firstName.', '.$lastName.'!');
}
}
17.- A request falls in this controller. What would happen?

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class HelloController
{

public function indexAction()
{

return $this->render('template.html.twig');
}
}
18.- A request falls in this controller. What would happen?
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class HelloController extends Controller
{

public function indexAction()
{

return $this->render('template.html.twig');
}
}
19.- A request falls in this controller. What would happen, assuming 'homepage' is a valid route name?
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class HelloController extends Controller
{

public function indexAction()
{

return $this->redirect($this->generateUrl('homepage'));
}
}
20.- Inside a controller, I can call any service with the $this->get(<service>) shortcut. But how can I know all available services in my Symfony application?
21.- How can you return a 404 error from a Controller?
22.- How can you return a 500 error from a Controller?
23.- How can Twig error pages be customized?
24.- What's up with this code?
$request->getSession()->getFlashBag()->add(
'terrible_notice',
'You ran out of milk!'
);
25.- What's true about this code?
$response = new Response(json_encode(array('name' => $name)));
$response->headers->set('Content-Type', 'application/json');
26.- How can you determine a request is an Ajax request?
27.- How can you access to a request from a controller that extends de Controller Symfony class
28.- How can you know the accepted languages a browser accpets in a request?
29.- Can you render a template without writing a custom controller?
30.- What does this code on execution in a Controller?
public function indexAction($name)
{
$response = $this->forward('AppBundle:Something:fancy', array(
'name' => $name,
'color' => 'green',
));
// ... further modify the response or return it directly
return $response;
}
31.- You have a Controller defined as service this way. What would you do to render a template?
# app/config/services.yml
services:
app.hello_controller:
class: AppBundle\Controller\HelloController
32.- What's true about this route?
// ...

/**
* @Route("/blog/{slug}", name="blog_show")
*/
public function showAction($slug)
{
// ...
}
33.- Routing file is found in app/config/routing.yml when you install the Standard Edition. Can you change it afterwards?
34.- Given this route and controller definition, what's true about them?
/**
* @Route("/blog/{page}", defaults={"page" = 1})
*/
public function indexAction($page = 2)
{
// ...
}
35.- Given this route and controller definitions, what's true about them?
// src/AppBundle/Controller/BlogController.php
// ...
class BlogController extends Controller
{
/**
* @Route("/blog/{page}", defaults={"page" = 1})
*/
public function indexAction($page)
{
// ...
}
/**
* @Route("/blog/{slug}")
*/
public function showAction($slug)
{
// ..
}
}
36.- Given this route and controller definitions are the only ones in the application, what's true about them?
// src/AppBundle/Controller/MainController.php
// ...
class MainController extends Controller
{
/**
* @Route("/{_locale}", defaults={"_locale": "en"}, requirements={
* "_locale": "en|fr"
* })
*/
public function homepageAction($_locale)
{
}
}
37.- What's the way to import a external routing file?
38.- Given this route and controller definition, what's true about them?
// src/AppBundle/Controller/MainController.php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
// ...

class MainController extends Controller
{
/**
* @Route("/news")
* @Method("GET")
*/
public function newsGetAction()
{
// ... display your news
}
/**
* @Route("/news")
* @Method({"POST"})
*/
public function newsPostAction()
{
// ... display and process a contact form
}
}
39.- Given this routing configuration, which of the answers are true?
homepage:
path: /
defaults: { _controller: AcmeDemoBundle:Main:homepage }

mobile_homepage:
path: /
host: "{subdomain}.example.com"
defaults:
_controller: AcmeDemoBundle:Main:mobileHomepage
subdomain: m
requirements:
subdomain: m|mobile
40.- Given this routing configuration, which of the answers are true?
// src/AppBundle/Controller/ArticleController.php

// ...
class ArticleController extends Controller
{
/**
* @Route(
* "/articles/{_locale}/{year}/{title}.{_format}",
* defaults={"_format": "html"},
* name = 'app_news',
* requirements={
* "_locale": "en|fr",
* "_format": "html|rss",
* "year": "\d+"
* }
* )
*/
public function showAction($_locale, $year, $title, $_route = 'my_route', $_controller)
{
}
}
41.- What's the output of php app/console router:debug
42.- I want to add routes that are located in a file in AppBundle/Resources/config/Routing/products/detail.yml, from another already loaded routes yaml file. How can I do it?
43.- Given this request, http://localhost:8000/product/{slug}, I want to know what controller will be executed, how can I know it?
44.- Given this request, http://localhost:8000/product/el-quijote, matching the route /product/{slug}, what would the value of $this->getRequest()->query->get('slug') be?
45.- According to the code below, what would the value of $url be?
/**
/* @Route("/blog/{slug}", name="blog_post")
*/
public function showAction($slug)
{

$url = $this->get('router')->generate('blog_post', array(
'slug' => 'el-quijote',
'page' => 2
));
}
46.- According to the code below, what would the value of $url be for the request http://localhost:8000/app_dev.php/blog/el-quijote ?
/**
/* @Route("/blog/{slug}", defaults = {'slug' : 'hamlet' }, name="blog_post")
*/
public function showAction($slug)
{

$url = $this->get('router')->generate('blog_post', array(
'slug' => 'el-quijote'
), true);
}
47.- What would be the value of $var after requesting http://localhost/blog ?
namespace AppBundle\Controller;

class BlogController extends Controller
{

/**
/* @Route("/blog/{slug}", defaults = {'slug' : 'hamlet' }, name="blog_post")
*/
public function showAction($slug)
{
$var = $this->get('router')->match('/blog/my-blog-post');
}

}
48.- What would be the value of $var after requesting http://localhost/blog/my-blog-post ?
namespace AppBundle\Controller;

class BlogController extends Controller
{

/**
/* @Route("/blog/{slug}", defaults = {'slug' : 'hamlet' }, name="blog_post")
*/
public function showAction($slug)
{
$var = $this->get('router')->match('/blog');
}

}
49.- Given this controller and route definition, what expression would generate an absolute url in a Twig template?
namespace AppBundle\Controller;

class BlogController extends Controller
{

/**
/* @Route("/blog/{slug}", name="blog_post")
*/
public function showAction($slug)
{
// ...
}

}
50.- What of these sentences are true about Twig?
51.- What's the output of this Twig code assuming navigation has 20 items and 10 satisfies the condition
{% for item in navigation if navigation is defined %}



{% endfor %}
52.- What of these sentences are true about Twig Caching System in Symfony?
53.- Consider these two Twig templates, what would be the output of index.html.twig render for AppBundle?

Template 1 -

{# src/AppBundle/Resources/views/base.html.twig #}




{% block title %}Test Application{% endblock %}




{% block body %}{% endblock %}




Template 2 -

{# src/AppBundle/Resources/views/blog/index.html.twig #}
{% extends 'AppBundle::base.html.twig' %}
{% block title %}My cool blog posts | {{ parent() }}{% endblock %}
54.- Consider these two Twig templates, what would be the output of index.html.twig render for AppBundle?

Template 1 -

{# src/AppBundle/Resources/views/base.html.twig #}




{% block title %}Test Application{% endblock %}




{% block body %}{% endblock %}




Template 2 -

{# src/AppBundle/Resources/views/blog/index.html.twig #}
{% extends '@AppBundle/base.html.twig' %}
{% block title %}My cool blog posts{% endblock %}
55.- You have these two Twig templates, what $this->render('AppBundle::index.html.twig') will render?
Template 1 -

{# app/Resources/AppBundle/views/index.html.twig #}




{% block title %}Test Application{% endblock %}



{% block body %}

Hello!

{% endblock %}




Template 2 -

{# src/AppBundle/Resources/views/index.html.twig #}




{% block title %}Test Application{% endblock %}



{% block body %}

Hello!

{% endblock %}



56.- You have these two Twig templates, what $this->render('AppBundle::index.json.twig') will render?

{# src/AppBundle/Resources/views/index.html.json #}




{% block title %}Test Application{% endblock %}



{% block body %}

Hello!

{% endblock %}



57.- Whats the correct syntax for the include helper?
58.- Considering you have these two Twig templates. Would this work?
Template 1 -

{# app/Resources/views/article/list.html.twig #}
{% extends 'layout.html.twig' %}
{% block body %}

Recent Articles


{% for article in articles %}
{{ include('article/article_details.html.twig') }}
{% endfor %}
{% endblock %}

Template 2 -

{# app/Resources/views/article/article_details.html.twig #}

{{ article.title }}





{{ article.body }}


59.- Would you consider rendering a template calling a controller from a Twig template?
60.- Symfony supports asyncronous content includes with hinclude.js. What's true about it?
61.- What's Assetic intended for?
62.- Consider this Twig template piece. Assuming Assetic is correctly installed, what sentences are true?
{% block stylesheets %}
{% stylesheets '@FOSCommentBundle/Resources/assets/css/comments.css'
'/media/css/all.css'
'/custom/css/*'%}

{% endstylesheets %}
{% endblock %}
63.- What's the purpose of the {{ asset() }} function
64.- Consider this assetic configuration
# app/config/config.yml
assetic:
filters:
coffee:
bin: /usr/bin/coffee
node: /usr/bin/node
node_paths: [/usr/lib/node_modules/]
apply_to: "\.coffee$"
65.- Which template variables are global and accesible from any Twig template?
66.- Consider this configuration. Which of the answers are true?
# app/config/config.yml
framework:
# ...
templating:
engines: ['twig', 'php']
67.- Given this Twig code, if an user sets his name to <script>alert('hello!')</script>, what will the output be?

Hello {{ name }}
68.- In what way can you access the 'data-foo' array index for the array foo in Twig?
69.- What's the order of all steps accessing a variable property "bar" in Twig when doing foo.bar?
70.- Consider this twig configuration. Which of the answers are true?
# Twig Configuration
twig:
strict_variables: "%kernel.debug%"
71.- What's true about this Twig code?
{# app/Resources/views/article/recent_list.html.twig #}
{{ dump(articles) }}
{% for article in articles %}

{{ article.title }}

{% endfor %}
72.- What will be the output of the command php app/console twig:lint app/Resources/views
73.- Consider this Twig Extension configuration setup, how can invoke it?

//src/AppBundle/Twig/SayYeahExtension.php
namespace AppBundle\Twig;

class SayYeahExtension extends \Twig_Extension
{

public function getFilters()
{
return array(
new \Twig_SimpleFilter('say_yeah', array($this, 'sayIt'))
);
}

public function sayIt($text)
{
return $text." Yeah!";
}

public function getName()
{
return "sayYeah";
}
}


\# app/config/services.yml
services:
say_whatever.gromenaguer:
class: AppBundle\Twig\SayYeahExtension
public: false
tags:
- { name: twig.extension }
74.- What would be the output of php app/console config:dump-reference framework
75.- How can I know the available bundles int the current Symfony installation
76.- What diferenciates each enviroment in Symfony?
77.- At which point is the Symfony configuration loaded?
78.- What is true about a Symfony Bundle?
79.- If a Bundle lives in src/Acme/AwesomeBundle/, what should be the main class name following the naming convention?
80.- Given a bundle named SecurityEnhancedBundle, what is its alias name?
81.- What of these directories are conventions and are created with php app/console generate:bundle command?
82.- Does the php app/console generate:bundle register a bundle in your Symfony app?
83.- What's the directory by default for your functional and unit tests?
84.- Where is the default configuration file for PHPUnit that comes with Symfony Standard Edition located?
85.- Consider this Unit Test. Would it work?
//src/AppBundle/Tests/Utils/SyllableSeparatorTest.php
namespace AppBundle\Tests\Utils;

use AppBundle\Utils\SyllableSeparator;

class SyllableSeparatorTest {

public function testTildes() {

$tests = array ('bíceps' => 1,
'imágen' => 0,
'ataúd' => 1,
'estáis' => 1);

$i = 0;
foreach ($tests as $word => $result) {

$analyzer = new SyllableSeparator($word);

$this->assertEquals($result, $analyzer->llevaTilde());

$analyzer = null;
$i++;
}
}
}
86.- What should be the default directory for a functional test?
87.- Consider this Functional Test. Would it work?
//src/AppBundle/Tests/Utils/SyllableSeparatorTest.php
namespace AppBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();

$crawler = $client->request('GET', '/');

$this->assertEquals(200, $client->getResponse()->getStatusCode());
$this->assertContains('Lleva tilde esta palabra', $crawler->filter('div.container h1')->text());
}
}
88.- Does a Functional Test bootstrap the kernel of your application
89.- What's the output of this code?

$client = static::createClient();
90.- What's the output of this code?

$client = static::createClient();
$crawler = $client->request('GET', '/post/hello-world');
91.- What formats can Symfony's Crawler parse and work with?
92.- What methods can you use to filter a Crawler object?
93.- What's the result of this piece of code?

$link = $crawler->filter('a:contains("Greet")');
94.- What's the result of this piece of code?

$this->assertContains(
'Hello World',
$client->getResponse()->getContent()
);
95.- Can you access the container form a Functional test class?
96.- What's the output of this Crawler method?

$crawler->attr('class');
97.- What's the output of this Crawler method?

$info = $crawler->extract(array('_text', 'href'));
98.- What's the output of this Crawler code snippet?

$data = $crawler->each(function ($node, $i) {
return $node->attr('href');
});
99.- What's wrong with this code?
$link = $crawler->selectLink('Click here');
$client->click($link);
100.- Consider this Crawler code, which of the sentences are true?
$buttonCrawlerNode = $crawler->selectButton('submit');

$form = $buttonCrawlerNode->form(array(
'name' => 'Frank',
), POST);

$client->submit($form, array(
'name' => 'Peter'
));
101.- How long are Standard Minor Versions maintained?
102.- How long are Log Term Versions supported?
103.- How often are Symfony versions released?
104.- What was the first Symfony LTS version?
105.- What's the development time for each Symfony release?
106.- What's true about abstract classes?
107.- Can abstract properties be defined?
108.- What's the purpose of the final keyword?
109.- What's true about visibility in PHP?
110.- What can you include within a PHP Namespace?
111.- Can you use PHP global function names in another namespace?
112.- Can interface constants be overriden?
113.- Can you access an interface constant?