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!