Skip to content

Instantly share code, notes, and snippets.

@martinsson
Created July 3, 2011 10:24
Show Gist options
  • Save martinsson/1062129 to your computer and use it in GitHub Desktop.
Save martinsson/1062129 to your computer and use it in GitHub Desktop.
Test setup for Symfony actions
<span>
<?php echo "Good evening, ".$name?>
</span>
<?php
class myActions extends sfActions {
public function initialize($context, $moduleName, $actionName) {
parent::initialize($context, $moduleName, $actionName);
}
public function executeHelloWorld(sfWebRequest $request) {
$this->helloMessage = "Hello ".$request->getParameter('name');
}
public function executeGoodEvening(sfWebRequest $request) {
sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
$greetingParameters =
array('name' => $request->getParameter('name'));
return $this->renderText(
get_partial('example/goodEvening', $greetingParameters));
}
}
<?php
class ActionTest extends PHPUnit_Framework_TestCase {
protected $action;
public function setUp() {
$debug = true;
$configuration = ProjectConfiguration::
getApplicationConfiguration('frontend', 'test', $debug);
$sfContext = sfContext::createInstance($configuration);
$this->action = new myActions($sfContext, null, null);
}
/** @test */
public function iCanTestNormalActionsThroughTheVarHolder() {
$request = new sfWebRequest(new sfEventDispatcher(),
array('name' => 'Brian'));
$this->action->executeHelloWorld($request);
assertThat($this->action->getVar('helloMessage'),
equalTo('Hello Brian'));
}
/** @test */
public function iCanTestAjaxActionsByTheReturnValue() {
$request = new sfWebRequest(new sfEventDispatcher(),
array('name' => 'John'));
$this->action->executeGoodEvening($request);
$eveningGreeting = $this->action->
getResponse()->getContent();
assertThat($eveningGreeting,
containsString('Good evening, John'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment