Sadece Symfony2 tabanlı bir mikro çerçeve olan silex için yaptım. Anladığım kadarıyla çok benzer. Symfony2 dünyasına bir primer için tavsiye ederim.
Ben de bu uygulama oluşturmak için TDD kullanılan yaptım yani ne oldu:
- benim bootstrap rotayı uygulamaya Sonra
- rota/işlemi doğrulamak için ilk testini yazdı
- Sonra ben hayata
- görüntülenmesi gereken şey benim test ör, karşı iddialar eklendi benim kodunda ve benzeri
bir (tests/ExampleTestCase.php
olarak) örnek testcase şuna benzer:
<?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());
}
}
benim
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;
Benim web/index.php
:
<?php
$app = require './../bootstrap.php';
$app->run();