1

我有一个关于 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()"

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

4

1 回答 1

0

使用 'app.php' 失败,到 app.php 的路径是错误的。

于 2013-07-10T20:27:51.197 回答