Symfony2 tdd development

Can someone provide a standard example for development in Symfony2 using TDD notation? Or share links to interesting materials for developing TDD Symfony2 (except for official documentation :))?

PS Does anyone write block tests for the control part of the MVC template?

+5
source share
1 answer

I just did it for silex , which is a micro structure based on Symfony2. From what I understand, this is very similar. I would recommend it as a primer for Symfony2-world.

I also used TDD to create this application, so I did this:

  • , /
  • , ,
  • ..

testcase ( tests/ExampleTestCase.php) :

<?php
use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\SessionStorage\ArraySessionStorage;

class ExampleTestCase extends WebTestCase
{
    /**
     * Necessary to make our application testable.
     *
     * @return Silex\Application
     */
    public function createApplication()
    {
        return require __DIR__ . '/../bootstrap.php';
    }

    /**
     * Override NativeSessionStorage
     *
     * @return void
     */
    public function setUp()
    {
        parent::setUp();
        $this->app['session.storage'] = $this->app->share(function () {
            return new ArraySessionStorage();
        });
    }

    /**
     * Test / (home)
     *
     * @return void
     */
    public function testHome()
    {
        $client  = $this->createClient();
        $crawler = $client->request('GET', '/');

        $this->assertTrue($client->getResponse()->isOk());
    }
}

my bootstrap.php:

<?php
require_once __DIR__ . '/vendor/silex.phar';

$app = new Silex\Application();

// load session extensions
$app->register(new Silex\Extension\SessionExtension());

$app->get('/home', function() use ($app) {
    return "Hello World";
});
return $app;

web/index.php:

<?php
$app = require './../bootstrap.php';
$app->run();
+10

All Articles