function test_addDefault_object() { $rvm = new ReturnValuesManager('classe'); $rvm->setReturnValue('metodo', 'primo', 1)->setReturnObjectDefault('metodo', 'pdefault'); FakeObjectGenerator::generate($rvm, new CodeGenerator(null)); //echo FakeObjectGenerator::returnedCode();die(); $classe = "class classe{\n//timing\n private static \$times = array();\n//Costants\n//Magic methods\n public function __call(\$name, \$arguments) {\n return null;\n }\n public function __callStatic(\$name, \$arguments) {\n return null;\n }\n//Methods\npublic function __construct()\n{ \$rvm_pdefault = new ReturnValuesManager('pdefault');\n FakeObjectGenerator::generate(\$rvm_pdefault, new CodeGenerator(null));\n}\n function metodo(){\n if(isset(self::\$times['metodo'])){\n self::\$times['metodo']++;\n }\n else{\n self::\$times['metodo'] = 1;\n }\nswitch (self::\$times['metodo']){\n case 1:\n return 'primo';\n break;\n default: return new pdefault();\n }\n }\n}"; $this->assertEqual(FakeObjectGenerator::returnedCode(), $classe); $test_deault = new classe(); $this->assertEqual($test_deault->metodo(), 'primo'); $this->assertIsA($test_deault->metodo(), 'pdefault'); $this->assertIsA($test_deault->metodo(), 'pdefault'); }
function test_returnJustGeneratedClassWithInputParameter_at_with_object_input() { $rvm = new ReturnValuesManager('Instance2'); FakeObjectGenerator::generate($rvm, new CodeGenerator(null)); $rvm = new ReturnValuesManager('test_333'); $rvm->setInputParameterForMethod('prova_metodo', array('ciao', 'faccia', 1, 2, 3, 5, 'class:Instance2'), 2)->setInputParameterForMethod('prova_metodo', array(6, 7, 8, 'class:Instance2'), 3); FakeObjectGenerator::generate($rvm, new CodeGenerator(null)); $classe = "class test_333{\n//timing\n private static \$times = array();\n//Costants\n//Magic methods\n public function __call(\$name, \$arguments) {\n return null;\n }\n public function __callStatic(\$name, \$arguments) {\n return null;\n }\n//Methods\n function prova_metodo(){\n if(isset(self::\$times['prova_metodo'])){\n self::\$times['prova_metodo']++;\n }\n else{\n self::\$times['prova_metodo'] = 1;\n }\nswitch (self::\$times['prova_metodo']){\n case 2:\n \$input = array('0'=>'ciao','1'=>'faccia','2'=>1,'3'=>2,'4'=>3,'5'=>5,'6'=>'class:Instance2');\n \$args = func_get_args();\n \$index = 0;\n foreach (\$args as \$arg)\n {\n if(is_object(\$arg))\n {\n \$args[\$index] = 'class:'.get_class(\$arg);\n }\n \$index++;\n }\n \$diff = array_diff(\$input,\$args);\n if(!empty(\$diff)){ throw new Exception(\"Invalid input parameters. [method prova_metodo] [input \".\$args.\"] [case 2]\");}\n return null;\n break;\n case 3:\n \$input = array('0'=>6,'1'=>7,'2'=>8,'3'=>'class:Instance2');\n \$args = func_get_args();\n \$index = 0;\n foreach (\$args as \$arg)\n {\n if(is_object(\$arg))\n {\n \$args[\$index] = 'class:'.get_class(\$arg);\n }\n \$index++;\n }\n \$diff = array_diff(\$input,\$args);\n if(!empty(\$diff)){ throw new Exception(\"Invalid input parameters. [method prova_metodo] [input \".\$args.\"] [case 3]\");}\n return null;\n break;\n default: return null;\n }\n }\n}"; $this->assertEqual($classe, FakeObjectGenerator::returnedCode()); $oggetto = new test_333(); $this->assertNull($oggetto->prova_metodo('ciao')); $this->assertNull($oggetto->prova_metodo('ciao', 'faccia', 1, 2, 3, 5, new Instance2())); $this->expectException('Exception'); $oggetto->prova_metodo(new Instance2()); }
function test_timingConfigurationOnlyOncePerMethod_without_methods_list() { $rvm = new ReturnValuesManager('test_99'); $rvm_array = new ReturnValuesManager('test_101'); $rvm->setReturnObject('prova_metodo', 'test_101', 1)->setReturnObjectsArray('prova_metodo', array($rvm_array, $rvm_array), 2); FakeObjectGenerator::generate($rvm, new CodeGenerator(null)); $classe = "class test_99{\n//timing\n private static \$times = array();\n//Costants\n//Magic methods\n public function __call(\$name, \$arguments) {\n return null;\n }\n public function __callStatic(\$name, \$arguments) {\n return null;\n }\n//Methods\n function prova_metodo(){\n if(isset(self::\$times['prova_metodo'])){\n self::\$times['prova_metodo']++;\n }\n else{\n self::\$times['prova_metodo'] = 1;\n }\nswitch (self::\$times['prova_metodo']){\n case 1:\n \$rvm_test_101 = new ReturnValuesManager('test_101');\n if(self::\$times['prova_metodo'] == 1){\n FakeObjectGenerator::generate(\$rvm_test_101, new CodeGenerator(null));\n }\n \$mocktest_101 = new test_101();\n return new test_101();\n break;\n case 2:\n \$rvm_test_101 = new ReturnValuesManager('test_101');\n if(self::\$times['prova_metodo'] == 1){\n FakeObjectGenerator::generate(\$rvm_test_101, new CodeGenerator(null));\n }\n \$mocktest_101 = new test_101();\n return array(\$mocktest_101,\$mocktest_101);\n break;\n default: return null;\n }\n }\n}"; $this->assertEqual($classe, FakeObjectGenerator::returnedCode()); $oggetto = new test_99(); $this->assertIsA($oggetto->prova_metodo(), test_101); $array = $oggetto->prova_metodo(); $this->assertIsA($array[0], test_101); $this->assertIsA($array[1], test_101); }