SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
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!

Contenu connexe

Tendances

Apache Camel
Apache CamelApache Camel
Apache Camel
helggeist
 
How to deploy node to production
How to deploy node to productionHow to deploy node to production
How to deploy node to production
Sean Hess
 
How to build and distribute CLI tool in 15 minutes with Golang
How to build and distribute CLI tool in 15 minutes with GolangHow to build and distribute CLI tool in 15 minutes with Golang
How to build and distribute CLI tool in 15 minutes with Golang
Kohei Kimura
 
Design patterns as power of programing
Design patterns as power of programingDesign patterns as power of programing
Design patterns as power of programing
Lukas Lesniewski
 

Tendances (19)

Apache Camel for Devclub.eu
Apache Camel for Devclub.euApache Camel for Devclub.eu
Apache Camel for Devclub.eu
 
Write php deploy everywhere
Write php deploy everywhereWrite php deploy everywhere
Write php deploy everywhere
 
Apache Camel
Apache CamelApache Camel
Apache Camel
 
Write book in markdown
Write book in markdownWrite book in markdown
Write book in markdown
 
How to deploy node to production
How to deploy node to productionHow to deploy node to production
How to deploy node to production
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Ansible roles done right
Ansible roles done rightAnsible roles done right
Ansible roles done right
 
How to build and distribute CLI tool in 15 minutes with Golang
How to build and distribute CLI tool in 15 minutes with GolangHow to build and distribute CLI tool in 15 minutes with Golang
How to build and distribute CLI tool in 15 minutes with Golang
 
Ansible intro
Ansible introAnsible intro
Ansible intro
 
Design patterns as power of programing
Design patterns as power of programingDesign patterns as power of programing
Design patterns as power of programing
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
 
Palestra VCR
Palestra VCRPalestra VCR
Palestra VCR
 
Licão 14 debug script
Licão 14 debug scriptLicão 14 debug script
Licão 14 debug script
 
Going All-In With Go For CLI Apps
Going All-In With Go For CLI AppsGoing All-In With Go For CLI Apps
Going All-In With Go For CLI Apps
 
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
 
Ansible, Simplicity, and the Zen of Python
Ansible, Simplicity, and the Zen of PythonAnsible, Simplicity, and the Zen of Python
Ansible, Simplicity, and the Zen of Python
 
Ansible 202 - sysarmy
Ansible 202 - sysarmyAnsible 202 - sysarmy
Ansible 202 - sysarmy
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
 

Similaire à Trick or Tip - Symfony Edition

PM : code faster
PM : code fasterPM : code faster
PM : code faster
PHPPRO
 
Node.js basics
Node.js basicsNode.js basics
Node.js basics
Ben Lin
 

Similaire à Trick or Tip - Symfony Edition (20)

Composer
ComposerComposer
Composer
 
php & performance
 php & performance php & performance
php & performance
 
Android tools for testers
Android tools for testersAndroid tools for testers
Android tools for testers
 
Composer: putting dependencies on the score
Composer: putting dependencies on the scoreComposer: putting dependencies on the score
Composer: putting dependencies on the score
 
Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11
 
PM : code faster
PM : code fasterPM : code faster
PM : code faster
 
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environments
 
Composer Helpdesk
Composer HelpdeskComposer Helpdesk
Composer Helpdesk
 
Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made Easy
 
Node.js basics
Node.js basicsNode.js basics
Node.js basics
 
Drone 1.0 Feature
Drone 1.0 FeatureDrone 1.0 Feature
Drone 1.0 Feature
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Getting instantly up and running with Docker and Symfony
Getting instantly up and running with Docker and SymfonyGetting instantly up and running with Docker and Symfony
Getting instantly up and running with Docker and Symfony
 
Debugging webOS applications
Debugging webOS applicationsDebugging webOS applications
Debugging webOS applications
 
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configuration
 
Introduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command lineIntroduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command line
 

Dernier

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Dernier (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 

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!