Last active
December 19, 2015 05:59
-
-
Save overnin/5907845 to your computer and use it in GitHub Desktop.
Example of refactoring to support testing in test database
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
//in ProgramsController | |
... | |
function constructClasses() | |
{ | |
parent::constructClasses(); | |
$this->_instanciateVumiRabbitMQ(); | |
$this->_instanciateMongoModel("vusion"); //this is hard coded at the moment also so no worry about that | |
} | |
protected function _instantciateMongoModel(vusionDB) | |
{ | |
$this->Shortcode = new Shorcode(vusionDB) | |
} | |
... | |
//in TestProgramController | |
... | |
class TestProgramsController extends ProgramsController | |
{ | |
public $autoRender = false; | |
public function redirect($url, $status = null, $exit = true) | |
{ | |
$this->redirectUrl = $url; | |
} | |
protected function _instanciateVumiRabbitMQ() { | |
} | |
protected function _instanciateMongoModel(vusionDB) //u overwrite this function form the ProgramsController | |
{ | |
$this->Shortcode = new Shortcode("testvusiondb") //hard code here the name of the test database | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// in the ProgramsController i have
function constructClasses()
{
parent::constructClasses();
}
protected function _instanciateMongoModel($vusionDB){
$this->ShortCode = new ShortCode(array('database' => $vusionDB));
}
// In the ProgramsControllerTest i have
class TestProgramsController extends ProgramsController
{
}
public function testIndex_filter()
{
$shortcode1 = array(
'country' => 'uganda',
'shortcode' => 8282,
'international-prefix' => 256
);
// the stack trace is below
Undefined property: ProgramsControllerTestCase::$ShortCode
Test case: ProgramsControllerTestCase(testIndex_filter)
Stack trace:
/home/jared/Development/vusion-frontend/app/Test/Case/Controller/ProgramsControllerTest.php : 194
ProgramsControllerTestCase::testIndex_filter
/opt/lampp/lib/php/PHPUnit/Framework/TestCase.php : 969
/opt/lampp/lib/php/PHPUnit/Framework/TestCase.php : 824
/opt/lampp/lib/php/PHPUnit/Framework/TestResult.php : 648
/opt/lampp/lib/php/PHPUnit/Framework/TestCase.php : 769
/home/jared/Development/vusion-frontend/lib/Cake/TestSuite/CakeTestCase.php : 78
/opt/lampp/lib/php/PHPUnit/Framework/TestSuite.php : 775
/opt/lampp/lib/php/PHPUnit/Framework/TestSuite.php : 745
/opt/lampp/lib/php/PHPUnit/TextUI/TestRunner.php : 346
/home/jared/Development/vusion-frontend/lib/Cake/TestSuite/CakeTestRunner.php : 56
/home/jared/Development/vusion-frontend/lib/Cake/TestSuite/CakeTestSuiteCommand.php : 110
/home/jared/Development/vusion-frontend/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php : 250
/home/jared/Development/vusion-frontend/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php : 98
/home/jared/Development/vusion-frontend/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php : 115
/home/jared/Development/vusion-frontend/app/webroot/test.php : 92