Created
July 3, 2011 10:24
-
-
Save martinsson/1062129 to your computer and use it in GitHub Desktop.
Test setup for Symfony actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span> | |
<?php echo "Good evening, ".$name?> | |
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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