PHPUnit的几个问题

PHPUnit的几个问题,phpunit,kohana,Phpunit,Kohana,我有两个控制器。它们的第一个路径是controller/news.php,第二个路径是controller/admin/news.php。我有每个控制器的路由 对于controller/admin/news.php,我有 Route::set('news-admin', 'admin/news(/)', array('start' => '\d+')) ->defaults(array( 'directory' => 'admin', '

我有两个控制器。它们的第一个路径是controller/news.php,第二个路径是controller/admin/news.php。我有每个控制器的路由

对于controller/admin/news.php,我有

Route::set('news-admin', 'admin/news(/)', array('start' => '\d+'))
    ->defaults(array(
        'directory' => 'admin',
        'controller' => 'news',
        'action' => 'index',
        'start' => 0,
    ));
对于controller/news.php:

Route::set('news', 'news(/)', array('start' => '\d+'))
    ->defaults(array(
        'controller' => 'news',
        'action' => 'index',
        'start' => 0,
    ));
当我使用浏览器时,一切正常。当我打电话给

$response=Request::factory('/news')->execute()

在单元测试中路由,测试运行。但是当我打电话给

$response=Request::factory('admin/news')->execute()

我只收到下一条信息

PHPUnit 3.7.8 by Sebastian Bergmann. 
Configuration read from /home/mydir/Projects/www/kohsite/application/tests/phpunit.xml
经过几次实验,我明白了我无法测试路由是否包含放置在子文件夹中的控制器的“目录”

下面我展示了我的phpunit.xml

<phpunit bootstrap="bootstrap.php" colors="true">
    <testsuite name="ApplicationTestSuite">
      <directory>./classes</directory>
    </testsuite>
    <filter>
        <whitelist>
            <directory suffix=".php">../tests</directory>
            <exclude>
                <directory suffix="*">../cache</directory>
                <directory suffix="*">../config</directory>
                <directory suffix="*">../logs</directory>
                <directory suffix=".php">../views</directory>
                <file>../bootstrap.php</file>
            </exclude>
        </whitelist>
    </filter>
</phpunit>

/班
../测试
../cache
../config
../logs
../视图
../bootstrap.php

我假设您使用的是Kohana 3.x?我不知道你如何设置你的应用程序,但当我设计一个网站,管理控制器,我通常会创建一个管理控制器,是不是在一个子文件夹。默认路由可以处理到的任何请求

如果我想有一个专门用于管理新闻的控制器,我会创建一个名为“admin”的文件夹,并按如下方式设置控制器定义:

class Controller_Admin_News extends Controller_Admin {
Route::set('admin_news', 'admin/news(/<action>(/<id>))')
    ->defaults(array(
        'controller' => 'admin_news',
        'action'     => 'index'
    ));
然后,我会在bootstrap.php中编写一条如下所示的路由:

class Controller_Admin_News extends Controller_Admin {
Route::set('admin_news', 'admin/news(/<action>(/<id>))')
    ->defaults(array(
        'controller' => 'admin_news',
        'action'     => 'index'
    ));
Route::set('admin_news','admin/news(/(/)'))
->默认值(数组)(
“控制器”=>“管理新闻”,
'操作'=>'索引'
));

试着像那样设置你的应用程序,看看它是否有用。

当然,我正在使用Kohana 3.2。我有控制器

class Controller_Admin_News extends Controller_Admin_Common