1
votes

I'm having some trouble starting automated tests with Yii, PHPUnit and Selenium I've set up Selenium and PHPUnit and when i run phpunit . I get this error:

    Warning: include(PHPUnit_Extensions_Story_TestCase.php): failed to open stream: No such 
file or directory in path_to/framework/YiiBase.php on line 427

    Warning: include(): Failed opening 'PHPUnit_Extensions_Story_TestCase.php' for inclusion 
(include_path='.:') in path_to/framework/YiiBase.php on line 427
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: The path to the driver executable    
must be set by the phantomjs.binary.path capability/system property/PATH variable; for more 
information, see https://github.com/ariya/phantomjs/wiki. The latest version can be downloaded 
from http://phantomjs.org/download.html

I have Selenium RC running in background. I also have PHPunit folder inside tests folder, with Story and selenium extensions.

My code looks looks like this

define('TEST_BASE_URL','http://some_local_url/');
class WebTestCase extends PHPUnit_Extensions_Selenium2TestCase
{
    /**
     * Sets up before each test method runs.
     * This mainly sets the base URL for the test application.
     */
    protected function setUp()
    {
        parent::setUp();

        $this->setHost('localhost');

        $this->setPort(4444);
        $this->setBrowserUrl(TEST_BASE_URL);
    }
}

class SiteTest extends WebTestCase
{
    public function testIndex()
    {
        $this->open('');
        $this->assertTextPresent('Welcome');
    }
}
2
Could you include your index-test.php, or the entry script for some_local_url? - topher
Do I need a index-test.php? Might be the problem?! What should go in it? - João Dias

2 Answers

1
votes

Turns out that Selenium server needs phantomjs (thank you captain obvious), to run correctly. I simply put the server .jar file in the same folder as phantomjs binary and the tests were running correctly afterwards.

0
votes

It looks like you haven't configured the path to the framework in your test entry script (index-test.php by default) properly. You should also set your config file here. Without this your tests run with the same settings (databases, sessions) as your application.

This is the content of index-test.php for the demo blog : https://github.com/yiisoft/yii/blob/master/demos/blog/index-test.php

<?php
/**
 * This is the bootstrap file for test application.
 * This file should be removed when the application is deployed for production.
 */

// change the following paths if necessary
$yii=dirname(__FILE__).'/../../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/test.php';

// remove the following line when in production mode
// defined('YII_DEBUG') or define('YII_DEBUG',true);

require_once($yii);
Yii::createWebApplication($config)->run();