SlideShare a Scribd company logo
Trick -or- Tip
Symfony edition
Dionysis Tsoumas
Backend developer at Zoottle
Today’s Agenda
• Better commands
• Better autoloading
• Better logs
• Better security
and my favourite
Better Testing :)
Better Console Commands
Typical:
php app/console doctrine:schema:update —force —env=dev —no-debug
Better:
php app/console d:s:u —f
or even better..
dev d:s:u —f
where alias dev='php app/console --env=dev --no-debug'
Better autoloading
//composer.json
"autoload": {
"psr-0": { "": "src/" }
},
Instead:
"autoload": {
"psr-0": { "": "src/" }
},
“autoload-dev": {
"psr-0": { "": “src/ZoottleBundle/Tests/“ }
},
Of course don’t forget :
composer dump-autoload —optimize
Better logs
Hide event logs
//app/config/dev.yml
monolog:
handlers:
main:
type: stream
path: “%kernel.logs_dir%/%kernel.emvironment%.log”
level: debug
channels: “!event”
Secure Ajax Requests :)
Step 1: Create a simple
Twig extension
And an even
simpler service
Step 2: Use it on your ajax calls $.ajax({
async: true,
method: "POST",
url: "{{ path('geoip') }}",
data: "token={{ csrf_token() }}",
…
Step 3: Validate within your controller
public function customerHasCreditCardAction(Request $request)
{
if ($request->isXmlHttpRequest() && $this->get("ens_peewee.csrf_validator")->isValid()) {
$braintree = $this->get(“ens_peewee.braintree");
… do awesome stuff …
is valid?is ajax request?
• When smoke testing
Quick functional tests
• Or when your application is decoupled enough that performance really matters
“Smoke testing is a precondition to unit and other forms of testing: if the smoke test fails there's no point in even
starting up a unit test”
- some cool developer said
$client = static::createClient(array(), array('HTTP_HOST' => "panel.zoottle.dev"));
$this->assertEquals(200, $client->getResponse()->getStatusCode());
This is slow!
Instead:
protected function setUp(){
$this->app = new AppKernel(‘test’, false);
$this->app->boot();
}
public function testUrl($url){
$request = new Request::create($url, ‘GET’);
$response = $this->app->handle($request);
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
http://gnugat.github.io/2014/11/15/sf2-quick-functional-tests.html
But I need speed!
https://github.com/liuggio/fastest
Like Parallel — but it supports functional tests
#composer.json
"require-dev": {
"liuggio/fastest": "dev-master"
}
However it does not work with code coverage :’(
find src/ “*Test.php” | vendor/bin/fastest “vendor/bin/phpunit -c app/ {};”
Voila! Multiple threads for your tests
Tip: use system variables to deal with multiple databases
ex: getenv('ENV_TEST_CHANNEL_READABLE'); //eg. test_2
Questions?
How about helping Flash on his next
presentation? Find a topic that you like
and propose it for our next meetup, in
early summer!

More Related Content

PDF
Phoenix Servers with Docker and Nginx
PDF
Write php deploy everywhere tek11
PDF
Ansible for beginners ...?
PDF
Web development automatisation for fun and profit (Artem Daniliants)
PDF
Create your own composer package
PDF
Haibu: dev deployment is fast and easy again
PDF
Introducing Ansible
PDF
May The Nodejs Be With You
Phoenix Servers with Docker and Nginx
Write php deploy everywhere tek11
Ansible for beginners ...?
Web development automatisation for fun and profit (Artem Daniliants)
Create your own composer package
Haibu: dev deployment is fast and easy again
Introducing Ansible
May The Nodejs Be With You

What's hot (19)

PPT
Apache Camel for Devclub.eu
KEY
Write php deploy everywhere
PPT
Apache Camel
PPT
Write book in markdown
PDF
How to deploy node to production
PPTX
Using Ansible Dynamic Inventory with Amazon EC2
PPTX
Ansible presentation
PDF
Ansible roles done right
PDF
How to build and distribute CLI tool in 15 minutes with Golang
PPTX
Design patterns as power of programing
PDF
Ansible - Swiss Army Knife Orchestration
ZIP
Palestra VCR
PPTX
Licão 14 debug script
PDF
Going All-In With Go For CLI Apps
PDF
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
PDF
Ansible, Simplicity, and the Zen of Python
PDF
Ansible 202 - sysarmy
PDF
#OktoCampus - Workshop : An introduction to Ansible
Apache Camel for Devclub.eu
Write php deploy everywhere
Apache Camel
Write book in markdown
How to deploy node to production
Using Ansible Dynamic Inventory with Amazon EC2
Ansible presentation
Ansible roles done right
How to build and distribute CLI tool in 15 minutes with Golang
Design patterns as power of programing
Ansible - Swiss Army Knife Orchestration
Palestra VCR
Licão 14 debug script
Going All-In With Go For CLI Apps
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
Ansible, Simplicity, and the Zen of Python
Ansible 202 - sysarmy
#OktoCampus - Workshop : An introduction to Ansible
Ad

Similar to Trick or Tip - Symfony Edition (19)

PDF
Symfony tips and tricks
PDF
Desymfony 2011 - Habemus Bundles
PDF
Symfony metabook 2.0
PPTX
SymfonyCon 2015 - A symphony of developers
PDF
Symfony4 - Deep dive
PDF
Hands-on with the Symfony2 Framework
PDF
Symfony2 - from the trenches
PDF
Build powerfull and smart web applications with Symfony2
PDF
The Naked Bundle - Tryout
PDF
Optimizing Symfony Application Performance
PDF
Symfony tips and tricks
PDF
symfony on action - WebTech 207
KEY
Phpne august-2012-symfony-components-friends
PDF
Symfony War Stories
PDF
Symfony2 from the Trenches
PDF
Symfony: Your Next Microframework (SymfonyCon 2015)
PDF
Improve your web and app development with the Symfony3 framework.
PPTX
Models in symfony
PDF
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
Symfony tips and tricks
Desymfony 2011 - Habemus Bundles
Symfony metabook 2.0
SymfonyCon 2015 - A symphony of developers
Symfony4 - Deep dive
Hands-on with the Symfony2 Framework
Symfony2 - from the trenches
Build powerfull and smart web applications with Symfony2
The Naked Bundle - Tryout
Optimizing Symfony Application Performance
Symfony tips and tricks
symfony on action - WebTech 207
Phpne august-2012-symfony-components-friends
Symfony War Stories
Symfony2 from the Trenches
Symfony: Your Next Microframework (SymfonyCon 2015)
Improve your web and app development with the Symfony3 framework.
Models in symfony
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
Ad

Recently uploaded (20)

PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Nekopoi APK 2025 free lastest update
PPTX
history of c programming in notes for students .pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Transform Your Business with a Software ERP System
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Introduction to Artificial Intelligence
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
wealthsignaloriginal-com-DS-text-... (1).pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Upgrade and Innovation Strategies for SAP ERP Customers
Nekopoi APK 2025 free lastest update
history of c programming in notes for students .pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Design an Analysis of Algorithms II-SECS-1021-03
L1 - Introduction to python Backend.pptx
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Design an Analysis of Algorithms I-SECS-1021-03
How to Choose the Right IT Partner for Your Business in Malaysia
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Transform Your Business with a Software ERP System
VVF-Customer-Presentation2025-Ver1.9.pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Introduction to Artificial Intelligence
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Operating system designcfffgfgggggggvggggggggg
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool

Trick or Tip - Symfony Edition

  • 1. Trick -or- Tip Symfony edition Dionysis Tsoumas Backend developer at Zoottle
  • 2. Today’s Agenda • Better commands • Better autoloading • Better logs • Better security and my favourite Better Testing :)
  • 3. Better Console Commands Typical: php app/console doctrine:schema:update —force —env=dev —no-debug Better: php app/console d:s:u —f
  • 4. or even better.. dev d:s:u —f where alias dev='php app/console --env=dev --no-debug'
  • 5. Better autoloading //composer.json "autoload": { "psr-0": { "": "src/" } }, Instead: "autoload": { "psr-0": { "": "src/" } }, “autoload-dev": { "psr-0": { "": “src/ZoottleBundle/Tests/“ } },
  • 6. Of course don’t forget : composer dump-autoload —optimize
  • 8. Hide event logs //app/config/dev.yml monolog: handlers: main: type: stream path: “%kernel.logs_dir%/%kernel.emvironment%.log” level: debug channels: “!event”
  • 9. Secure Ajax Requests :) Step 1: Create a simple Twig extension And an even simpler service
  • 10. Step 2: Use it on your ajax calls $.ajax({ async: true, method: "POST", url: "{{ path('geoip') }}", data: "token={{ csrf_token() }}", … Step 3: Validate within your controller public function customerHasCreditCardAction(Request $request) { if ($request->isXmlHttpRequest() && $this->get("ens_peewee.csrf_validator")->isValid()) { $braintree = $this->get(“ens_peewee.braintree"); … do awesome stuff … is valid?is ajax request?
  • 11. • When smoke testing Quick functional tests • Or when your application is decoupled enough that performance really matters “Smoke testing is a precondition to unit and other forms of testing: if the smoke test fails there's no point in even starting up a unit test” - some cool developer said
  • 12. $client = static::createClient(array(), array('HTTP_HOST' => "panel.zoottle.dev")); $this->assertEquals(200, $client->getResponse()->getStatusCode()); This is slow! Instead: protected function setUp(){ $this->app = new AppKernel(‘test’, false); $this->app->boot(); } public function testUrl($url){ $request = new Request::create($url, ‘GET’); $response = $this->app->handle($request); $this->assertEquals(200, $client->getResponse()->getStatusCode()); } http://gnugat.github.io/2014/11/15/sf2-quick-functional-tests.html
  • 13. But I need speed! https://github.com/liuggio/fastest Like Parallel — but it supports functional tests #composer.json "require-dev": { "liuggio/fastest": "dev-master" }
  • 14. However it does not work with code coverage :’( find src/ “*Test.php” | vendor/bin/fastest “vendor/bin/phpunit -c app/ {};” Voila! Multiple threads for your tests Tip: use system variables to deal with multiple databases ex: getenv('ENV_TEST_CHANNEL_READABLE'); //eg. test_2
  • 15. Questions? How about helping Flash on his next presentation? Find a topic that you like and propose it for our next meetup, in early summer!