/** * Load controller mock, as well as related mocks and $_SERVER values which might be needed * in cases where a controller is needed. */ public static function loadControllerMock($serverName = 'localhost', $scriptName = '/index-test.php') { self::$_oldController = Yii::app()->controller; self::$_oldServerVals = $_SERVER; $_SERVER['SCRIPT_FILENAME'] = realpath('../../index-test.php'); $_SERVER['DOCUMENT_ROOT'] = realpath('../..'); $_SERVER['SERVER_NAME'] = $serverName; $_SERVER['SCRIPT_NAME'] = $scriptName; $_SERVER['REQUEST_URI'] = '/index.php/controllerMock/actionMock'; Yii::app()->controller = new ControllerMock('moduleMock', new ModuleMock('moduleMock', null)); Yii::app()->controller->action = new ActionMock(Yii::app()->controller, 'actionMock'); // clear the url property caches so they will get regenerated using the // properties of $_SERVER self::setPrivateProperty('CHttpRequest', '_scriptUrl', null, Yii::app()->request); self::setPrivateProperty('CUrlManager', '_baseUrl', null, Yii::app()->getUrlManager()); }