class AuthTest extends CWebTestCase{
public function testLogin(){
$this->open('login');
$this->assertTextPresent('success');
}
}
when run as phpunit functional:
wfooxd@wfooxd-vb:~/www/sgserver/protected/tests$ phpunit functional/AuthTest.php
PHPUnit @package_version@ by Sebastian Bergmann.
Configuration read from /home/wfooxd/www/sgserver/protected/tests/phpunit.xml
E
Time: 0 seconds, Memory: 8.25Mb
There was 1 error:
1) AuthTest::testLogin
Current URL: OR Server Exception: sessionId should not be null; has this session been started yet?
setBrowserUrl() needs to be called before start().
/usr/share/php/phpunit/phpunit.php:46
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
setBrowserUrl is (in yii) by default called in WebTestCase (protected/tests) and your test case should extend WebTestCase, not CWebTestCase.
If you don’t feel like having some common settings in WebTestCase, you can call setBrowserUrl in setUp() function in each test case, but that will lead to copy-paste kind of code reusability which is not good.
You probably didn’t set TEST_BASE_URL, so your WebTestCase.php file should look like:
<?php
define('TEST_BASE_URL','http://localhost/app/index-test.php/');
class WebTestCase extends CWebTestCase
{
/**
* Sets up before each test method runs.
* This mainly sets the base URL for the test application.
*/
protected function setUp()
{
parent::setUp();
$this->setBrowserUrl(TEST_BASE_URL);
}
}
?>
and then our function test case need to extend WebTestCase.