Silex PHPUnit功能测试

时间:2013-07-10 20:10:37

标签: symfony phpunit silex

我对Silex / PHPUnit中的功能测试有疑问。

require_once '/var/www/silex/vendor/autoload.php';

class MyTest extends Silex\WebTestCase{

protected $app;


public function createApplication() {
    $this->app = require 'app.php';
    return $this->app;
}

public function testInitialPage(){

    $client = $this->createClient();
    $crawler = $client->request('GET', '/login');

    $this->assertTrue($client->getResponse()->isOk());
    $this->assertCount(1, $crawler->filter('html:contains("Login")'));
    $this->assertCount(1, $crawler->filter('form'));

    $this->app['session']->set('userid', X);
    $this->app['session']->set('username', 'X');
    $this->app['session']->set('isadmin', true);

    $crawler = $client->request('GET', '/');    
    $this->assertTrue($client->getResponse()->isOk());
    $this->assertCount(1, $crawler->filter('html:contains("Cred")'));
}

    public function testAdd() {
    $client = $this->createClient();
    $crawler = $client->request('GET', '/');

    $this->assertTrue($client->getResponse()->isOk());
    $this->assertCount(1, $crawler->filter('html:contains("Cred")'));
}

这应该是第一个“测试”,但每次运行它时,testInitialPage()方法都会运行,我不会遇到任何错误。

但在testAdd()我失败了' No route found for "GET /" '

对我来说,似乎$ app(和路由)在第二种方法"testAdd()"中不再存在

有人提示我如何设置正确的功能测试系统吗?

1 个答案:

答案 0 :(得分:0)

使用' app.php'到app.php的路由错了。