Silex PHPUnit功能测试 [英] Silex PHPUnit Functional tests

查看:84
本文介绍了Silex PHPUnit功能测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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")'));
}

这应该是第一个测试",但是每次运行它时,都会运行testInitialPage()方法,并且不会出现任何错误.

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

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

对我来说,第二个方法"testAdd()"

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?

推荐答案

使用"app.php"失败,导致app.php的路径错误.

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

这篇关于Silex PHPUnit功能测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆