【问题标题】:Silex PHPUnit Functional testsSilex PHPUnit 功能测试
【发布时间】:2013-07-08 22:27:13
【问题描述】:

我有一个关于 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()"中似乎不再存在$app(和路由)

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

【问题讨论】:

    标签: symfony phpunit silex


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-02-21
      • 2015-06-08
      • 2014-06-09
      • 2020-02-11
      • 2015-06-10
      • 1970-01-01
      • 2020-12-22
      • 2021-07-21
      • 1970-01-01
      相关资源
      最近更新 更多