Пример #1
0
    function test_ReturnValuesManger_setConstants()
    {
        $rvm = new ReturnValuesManager('classe_con_costanti');
        $rvm->setConstant('NAME', 'name');
        $rvm->setConstant('DB', 'db');
        $rvm->setConstant('PIPPO', 'pippo');
        $this->assertTrue(is_array($rvm->getConstants()), '->getConstants() return an array');
        $constants = $rvm->getConstants();
        $this->assertTrue(isset($constants['NAME']), '->getConstants() has set the right value');
        $this->assertEqual($constants['NAME'], 'name', '->getConstants() return the right value for costant');
        $this->assertTrue(isset($constants['DB']), '->getConstants() has set the right value');
        $this->assertEqual($constants['DB'], 'db', '->getConstants() return the right value for costant');
        $this->assertTrue(isset($constants['PIPPO']), '->getConstants() has set the right value');
        $this->assertEqual($constants['PIPPO'], 'pippo', '->getConstants() return the right value for costant');
        $this->assertEqual($rvm->returnCodeForReturnValueManager($rvm), '        $rvm_classe_con_costanti = new ReturnValuesManager(\'classe_con_costanti\');
        $rvm_classe_con_costanti->setConstant(NAME, name);
        $rvm_classe_con_costanti->setConstant(DB, db);
        $rvm_classe_con_costanti->setConstant(PIPPO, pippo);
');
    }
Пример #2
0
 function test_returnCodeForReturnValueManager_one_two_level_with_parameter_and_redeclaring_class()
 {
     $rm1 = new ReturnValuesManager('test_1');
     $rm2 = new ReturnValuesMAnager('test_2');
     $rm3 = new ReturnValuesManager('test_3');
     $rm5 = new ReturnValuesMAnager('test_5');
     $rvm = new ReturnValuesManager('test_4');
     $rvm->setInputParameterForMethod('metodo_1', array('ciao', 1, 2, 3))->setInputParameterForMethod('metodo_2', array('a', 'b', 'd'), 1)->setInputParameterForMethod('metodo_2', array(1, 2, 3), 2)->setReturnException('metodo_3', 'Exception', 'Eccezione ritornata')->setReturnException('metodo_4', 'Exception', 'Eccezione at', 2)->setReturnObject('metodo_5', 'oggetto_nuovo')->setReturnValue('metodo_7', 'ritorno')->setReturnValue('metodo_8', false, 1)->setReturnValuesArray('metodo_9', array('a', 1, false, true, 33))->setReturnValuesArray('metodo_10', array('b', 1, false, false, 4), 3)->setReturnObjectsArray('metodo_6', array($rm1, $rm2))->setReturnObjectsArray('metodo_11', array($rm3, $rm5), 3);
     $rvm5 = $rvm->getReturnValue('metodo_5');
     $rvm5->setReturnObject('metodo_23', 'oggetto_nuovo_2');
     //echo $rvm->returnCodeForReturnValueManager($rvm);
     $classe = "        \$rvm_test_4 = new ReturnValuesManager('test_4');\n        \$rvm_test_4->setInputParameterForMethod('metodo_1', array('0'=>'ciao','1'=>1,'2'=>2,'3'=>3));\n        \$rvm_test_4->setInputParameterForMethod('metodo_2', array('0'=>'a','1'=>'b','2'=>'d'), 1);\n        \$rvm_test_4->setInputParameterForMethod('metodo_2', array('0'=>1,'1'=>2,'2'=>3), 2);\n        \$rvm_test_4->setReturnException('metodo_3', 'Exception', 'Eccezione ritornata');\n        \$rvm_test_4->setReturnException('metodo_4', 'Exception', 'Eccezione at', 2);\n        \$rvm_test_4->setReturnObject('metodo_5','oggetto_nuovo');\n        \$rvm_oggetto_nuovo = \$rvm_test_4->getReturnValue('metodo_5');\n        \$rvm_oggetto_nuovo->setReturnObject('metodo_23','oggetto_nuovo_2');\n        \$rvm_test_4->setReturnValue('metodo_7', 'ritorno');\n        \$rvm_test_4->setReturnValue('metodo_8', false, 1);\n        \$rvm_test_4->setReturnValuesArray('metodo_9', array('0'=>'a','1'=>1,'2'=>false,'3'=>true,'4'=>33));\n        \$rvm_test_4->setReturnValuesArray('metodo_10', array('0'=>'b','1'=>1,'2'=>false,'3'=>false,'4'=>4), 3);\n        \$rvm_test_1 = new ReturnValuesManager('test_1');\n        \$rvm_test_2 = new ReturnValuesManager('test_2');\n        \$rvm_test_4->setReturnObjectsArray('metodo_6',array(\$rvm_test_1,\$rvm_test_2));\n        \$rvm_test_3 = new ReturnValuesManager('test_3');\n        \$rvm_test_5 = new ReturnValuesManager('test_5');\n        \$rvm_test_4->setReturnObjectsArray('metodo_11',array(\$rvm_test_3,\$rvm_test_5), 3);\n";
     $this->assertEqual($classe, $rvm->returnCodeForReturnValueManager($rvm));
 }
Пример #3
0
 /**
  * Generate the code for an object that has to be return from a method of my redefined class.
  * This implicates a new class definition where needed (see returnCodeForReturnValueManager method of ReturnValuesManager)
  *
  * @param ReturnValuesManager $rm
  * @param string $method
  * @return string
  */
 public function generateCodeForNewInnerObjects($rm, $method)
 {
     $returnCode = $rm->returnCodeForReturnValueManager($rm);
     $returnCode .= "        if(self::\$times['" . $method . "'] == 1){\n";
     $returnCode .= "        FakeObjectGenerator::generate(\$rvm_" . $rm->getClassName();
     $returnCode .= ", new CodeGenerator(";
     $returnCode .= !is_null($this->pathToList) ? "'" . $this->pathToList . "'));\n" : "null));\n";
     $returnCode .= "        }\n";
     $returnCode .= "        \$mock" . strtolower($rm->getClassName()) . " = new " . $rm->getClassName() . "();\n";
     return $returnCode;
 }