Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps
Trick or Tip - Symfony Edition
-
Upload
dionyshs-tsoumas -
Category
Software
-
view
94 -
download
3
Transcript of Trick or Tip - Symfony Edition
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
Better autoloading
//composer.json "autoload": { "psr-0": { "": "src/" } },
Instead:
"autoload": { "psr-0": { "": "src/" } }, “autoload-dev": { "psr-0": { "": “src/ZoottleBundle/Tests/“ } },
Hide event logs//app/config/dev.yml
monolog: handlers: main: type: stream path: “%kernel.logs_dir%/%kernel.emvironment%.log” level: debug channels: “!event”
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/fastestLike 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