Ale*_*kin 5 tdd phpunit symfony
有谁能提供一个使用TDD表示法在Symfony2中进行开发的标准示例?或者分享有关TDD Symfony2开发的有趣材料的链接(官方文档:))?
PS是否有人为MVC模式的控制器部分编写单元测试?
Til*_*ill 10
我刚刚为silex做了这个,它是一个基于Symfony2的微框架.据我所知,它非常相似.我推荐它作为Symfony2世界的入门书.
我还使用TDD来创建这个应用程序,所以我做的是:
示例testcase(in 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());
}
}
Run Code Online (Sandbox Code Playgroud)
我的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;
Run Code Online (Sandbox Code Playgroud)
我的web/index.php:
<?php
$app = require './../bootstrap.php';
$app->run();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1897 次 |
| 最近记录: |