2013-07-10 94 views
1

我有一個關於Silex/PHPUnit中的功能測試的問題。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 /" '

對我來說似乎$應用程序(和路由)不會在第二種方法存在了"testAdd()"

是否有人有我一個提示如何設置一個正確的功能測試系統?

回答

0

使用app.php'roue到app.php是錯誤的。