スキップしてメイン コンテンツに移動

投稿

ラベル(Symfony 1.4)が付いた投稿を表示しています

PHP Symfony 1.4 Action plus View Rendering PHPUnit Test

Symfony 1.4 Action plus View Rendering PHPUnit Test I wrote test case for executing action and rendering view test. However testing action plus final rendering result is quite not easy because you need to understand how Symfony 1.4 framework handles web request and rendering model to view internally. I have investigated in the framework a bit and found a solution. Please see the test case example in the next section. Code <?php $basePath = dirname(__FILE__).'/../../../../apps/your_app_name/modules/'; $modulePaths = glob($basePath.'*', GLOB_ONLYDIR); foreach($modulePaths as $modulePath) { require_once $modulePath.'/actions/actions.class.php'; } class ActionsTest extends PHPUnit_Framework_TestCase { public function testActions() { // create stub web request $request = $this->createStubfWebRequest(); // action you would like to test. // you should pass module and action name refelctively $actions = new TargetActions($this

Symfony 1.4 Accessing Context

Symfony 1.4 is already a legacy framework. But I think a lot of web system still running on it. In this post, I will show you some quick tips for accessing infromation by using sfContext . sfContext provides almost everything you want access. But you should not use context everywhere too much because sfContext is a kind of global objeect and if a lot of codes depends on context, your code will be hard to be tested or maintained, I think. Basic You can access sfContext by following code. sfContext::getInstance(); In sfFilter, you can access sfContext by the following code. $this->getContext(); What Kind of Fields You can access? Routing name $context->getRouting()->getCurrentRouteName(); User $context->getUser(); Request $context->getRequest(); Response $context->getResponse(); Controller $context->getController(); Logger sfContext::getInstance()->getLogger(); Advanced Use Check if http request is secure (e.g. https request). $co