我有两个控制器。它们的第一个路径是controller/news.php,第二个是controller/admin/news.php。我有每个控制器的路线。
对于控制器/管理员/news.php 我有
Route::set('news-admin', 'admin/news(/)', array('start' => '\d+'))
->defaults(array(
'directory' => 'admin',
'controller' => 'news',
'action' => 'index',
'start' => 0,
));
对于控制器/news.php:
Route::set('news', 'news(/)', array('start' => '\d+'))
->defaults(array(
'controller' => 'news',
'action' => 'index',
'start' => 0,
));
当我使用浏览器时,一切正常。当我打电话给
$response = Request::factory('/news')->execute()
在 unittest 中路由,测试运行。但是当我打电话给
$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>