starter
starter

Reputation: 169

Several troubles with PHPUnit

I have two controllers. First path of them is controller/news.php, second is controller/admin/news.php. I have routes for each controller.

For the controller/admin/news.php I have

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

For the controller/news.php:

Route::set('news', 'news(/)', array('start' => '\d+'))
    ->defaults(array(
        'controller' => 'news',
        'action' => 'index',
        'start' => 0,
    ));

When I use a browser all work OK. When I call the

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

route in an unittest , test runs. But when I call the

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

I get only the next message

PHPUnit 3.7.8 by Sebastian Bergmann. 
Configuration read from /home/mydir/Projects/www/kohsite/application/tests/phpunit.xml

After several experiments I understood that I can't test route contains a "directory" for controllers placed into subfolders.

Below I've shown my 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>

Upvotes: 0

Views: 210

Answers (2)

starter
starter

Reputation: 169

Sure, I'm using Kohana 3.2. I have controller

class Controller_Admin_News extends Controller_Admin_Common

Upvotes: 0

pogeybait
pogeybait

Reputation: 3145

I assume you are using Kohana 3.x? Im not sure how you have your application setup but when I design a site that has admin controllers I usually create an admin controller that is not in a sub-folder. The default route can handle any requests to the http://domain.com/<controller>/<action>/<id > such as http://domain.com/admin/index.

If I wanted to have a controller specifically for the admin news I would create a folder named "admin", and setup the controller definition like this:

class Controller_Admin_News extends Controller_Admin {

I would then write a route in my bootstrap.php that looks like this:

Route::set('admin_news', 'admin/news(/<action>(/<id>))')
    ->defaults(array(
        'controller' => 'admin_news',
        'action'     => 'index'
    ));

Try setting up your app like that and see if it helps.

Upvotes: 1

Related Questions