Silex PHPUnit Functional tests

情到浓时终转凉″ 提交于 2019-12-08 06:40:22

问题


I have a question concerning the functional test in 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")'));
}

This should be the first "test" but every time I run it, the testInitialPage() method runs and I do not get any Errors.

But in testAdd() I get a failure ' No route found for "GET /" '

For me it seems that $app (and routing) does not exist anymore in the second Method "testAdd()"

Does anybody have a hint for me how to set a a right Functional Testing system?


回答1:


There was a failure using the 'app.php' the roue to app.php was wrong.



来源:https://stackoverflow.com/questions/17580005/silex-phpunit-functional-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!