Question

I've configured kohana (3.2) unittest module as described here. So I have:

APPPATH/tests/
    phpunit.xml
    sampletest.php

And last lines index.php file:

require APPPATH.'bootstrap'.EXT;
if ( ! defined('SUPPRESS_REQUEST'))
    Request::factory()->execute()->send_headers();

So the first problem is that in CLI next error appears:

ErrorException [ 8 ]: Undefined index: SERVER_NAME ~ SYSPATH/classes/kohana/url.php [ 79 ]

This happens because of E_STRICT enabled. So when I turn off E_STRICT nothing happens. I mean there's no output for phpunit in CLI, just empty line.

And the second problem is that web access doesn't work at all (http://localhost/unittest). 404 error occurs. Maybe I should create some Route or anything?


Mac OS 10.7.4
Apache 1.3.41
PHPUnit 3.6.11
Kohana 3.2.0
Was it helpful?

Solution

Web access doesn't work because in Kohana versions 3.*, the web interface is no longer present for the unittest module. The only way to run the tests out of the box is to do so via the CLI.

This can normally be done by doing the following.

  1. Open terminal
  2. change the directory to the tests directory for your application
  3. run 'phpunit'

In addition, the tutorial is a bit out of date. A revision to unittest setup in Kohana 3.2 was suggested in: Suppressing the request when running PHPUnit with Kohana 3.2

Since it is running from the CLI, access to HTTP environment variables are not available.

Even though they are not available you can set them prior to operation by configuring them in your phpunit.xml file, according to PHPUnit documentation Configuration Appendix:

Setting PHP INI settings, Constants and Global Variables

The element and its children can be used to configure PHP settings, constants, and global variables. It can also be used to prepend the include_path.

<php>
    <includePath>.</includePath>
    <ini name="foo" value="bar"/>
    <const name="foo" value="bar"/>
    <var name="foo" value="bar"/>
    <env name="foo" value="bar"/>
    <post name="foo" value="bar"/>
    <get name="foo" value="bar"/>
    <cookie name="foo" value="bar"/>
    <server name="foo" value="bar"/>
    <files name="foo" value="bar"/>
    <request name="foo" value="bar"/>
</php>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top