public function testRunningFewerTestsThanTheWorkersIsPossible() { $generator = new TestGenerator(); $generator->generate(1, 1); $proc = $this->invokeParatest($generator->path, array('runner' => 'WrapperRunner', 'processes' => 2)); $this->assertTestsPassed($proc, 1, 1); }
$res = str_replace('{% name %}', $fname, $res); file_put_contents('../Library/NCLNameCaseRuTest' . $fname . $gender . '.php', $res); } private function generateTest($firstRes, $secondRes, $fatherRes) { $tpl = $this->testtemplate; $tpl = str_replace('{% id %}', $this->count, $tpl); $tpl = str_replace('{% second %}', $secondRes[0], $tpl); $tpl = str_replace('{% first %}', $firstRes[0], $tpl); $tpl = str_replace('{% father %}', $fatherRes[0], $tpl); $tpl = str_replace('{% gender %}', $this->gender, $tpl); $tpl = str_replace('{% firstOK %}', implode(',', $firstRes), $tpl); $tpl = str_replace('{% secondOK %}', implode(',', $secondRes), $tpl); $tpl = str_replace('{% fatherOK %}', implode(',', $fatherRes), $tpl); $this->tests .= $tpl; $this->count++; } } $p = new TestGenerator(); $p->generate('Names', 'boy'); $p = new TestGenerator(); $p->generate('Names', 'girl'); $p = new TestGenerator(); $p->generate('Sirnames', 'girl'); $p = new TestGenerator(); $p->generate('Sirnames', 'boy'); $p = new TestGenerator(); $p->generate('Father', 'girl'); $p = new TestGenerator(); $p->generate('Father', 'boy');
$indexSecond = $i % $countSecond; $this->generateTest($secondArr[$indexSecond], $firstArr[$indexFirst]); } return $result; } public function generate() { $this->maintemplate = file_get_contents('Template/NCLNameCaseUaTest.main'); $this->testtemplate = file_get_contents('Template/GenderGenBoth.test'); $this->count = 0; $this->gender = 1; $this->make('boy'); $this->gender = 2; $this->make('girl'); $res = str_replace('{% tests %}', $this->tests, $this->maintemplate); file_put_contents('../Library/GenderDetectUABoth.php', $res); } private function generateTest($sname, $fname) { $tpl = $this->testtemplate; $tpl = str_replace('{% id %}', $this->count, $tpl); $tpl = str_replace('{% name %}', $fname, $tpl); $tpl = str_replace('{% sname %}', $sname, $tpl); $tpl = str_replace('{% gender %}', $this->gender, $tpl); $this->tests .= $tpl; $this->count++; } } $p = new TestGenerator(); $p->generate('Both');
$this->generateTest(trim($row['name'])); } $this->dbTable = 'girl' . strtolower($fnewname); $this->gender = 2; $this->resultArr = mysql_query("SELECT * FROM {$this->dbTable}"); //foreach ($this->resultArr as $key=>$value) //{ //$this->gender=$key+1; while ($row = mysql_fetch_array($this->resultArr)) { $this->generateTest(trim($row['name'])); } //} $res = str_replace('{% tests %}', $this->tests, $this->maintemplate); $res = str_replace('{% name %}', $fname, $res); file_put_contents('../Library/GenderDetectUA' . $fname . '.php', $res); } private function generateTest($name) { $tpl = $this->testtemplate; $tpl = str_replace('{% id %}', $this->count, $tpl); $tpl = str_replace('{% name %}', $name, $tpl); $tpl = str_replace('{% gender %}', $this->gender, $tpl); $this->tests .= $tpl; $this->count++; } } $p = new TestGenerator(); $p->generate('name'); $p = new TestGenerator(); $p->generate('sirname');
$this->generateTest(trim($name)); } //foreach ($this->resultArr as $key=>$value) //{ //$this->gender=$key+1; // foreach ($this->resultArrG as $id => $name) // { // $this->generateTest(trim($name)); // } //} $res = str_replace('{% tests %}', $this->tests, $this->maintemplate); $res = str_replace('{% name %}', $fname, $res); file_put_contents('../Library/NameSplitUA' . $fname . '.php', $res); } private function generateTest($name) { $tpl = $this->testtemplate; $tpl = str_replace('{% id %}', $this->count, $tpl); $tpl = str_replace('{% name %}', $name, $tpl); $tpl = str_replace('{% gender %}', $this->gender, $tpl); $this->tests .= $tpl; $this->count++; } } $p = new TestGenerator(); $p->generate('name'); $p = new TestGenerator(); $p->generate('sirname'); $p = new TestGenerator(); $p->generate('father');
$test_namespace = $namespace . '\\test'; // the use string for the test cases $use = '\\' . $namespace . '\\' . $className; $conf_target_dir = $parser->getTargetDir(); $target_dir = $base_dir . '/' . $conf_target_dir . '/' . $className . '/'; $target_test_dir = $target_dir . '/test/'; checkDirExists($target_dir); checkDirExists($target_test_dir); $operations = $parser->getOperations(); $queries = $parser->getQueries(); $states = $parser->getStates(); $generator = new InterfaceGenerator(); $generator->generate($namespace, $operations, $interfaceName, $target_dir); $generator = new TransitionExceptionGenerator(); $generator->generate($namespace, $target_dir); $generator = new AbstractStateClassGenerator(); $generator->generate($namespace, $operations, $abstractClassName, $interfaceName, $target_dir); $generator = new ClassGenerator(); $generator->generate($namespace, $operations, $states, $className, $interfaceName, $target_dir); $codeGenerator = new StateClassGenerator(); $testGenerator = new TestGenerator(); // namespace of the class to be tested foreach ($states as $state => $data) { echo "Generating {$className} -> {$state}\n"; $codeGenerator->generate($namespace, $data, $state, $abstractClassName, $target_dir); $testGenerator->generate($use, $namespace, $test_namespace, $data, $operations, $queries, $states, $state, $className, $abstractClassName, $target_test_dir); } echo "===========================================\n"; } echo "Done\n"; echo "===========================================\n";
#!/usr/bin/env php <?php if (!file_exists(__DIR__ . '/../vendor/autoload.php')) { die('You need to set up the project dependencies using the following commands:' . PHP_EOL . 'wget https://getcomposer.org/composer.phar' . PHP_EOL . 'php composer.phar install' . PHP_EOL); } require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/autoload.php'; $parser = new SpecificationParser(new SpecificationFilename()); $className = $parser->getClassName(); $abstractClassName = $parser->getAbstractClassName(); $interfaceName = $parser->getInterfaceClassName(); $operations = $parser->getOperations(); $queries = $parser->getQueries(); $states = $parser->getStates(); $generator = new InterfaceGenerator(); $generator->generate($operations, $interfaceName); $generator = new AbstractStateClassGenerator(); $generator->generate($operations, $abstractClassName, $interfaceName); $generator = new ClassGenerator(); $generator->generate($operations, $states, $className, $interfaceName); $codeGenerator = new StateClassGenerator(); $testGenerator = new TestGenerator(); foreach ($states as $state => $data) { $codeGenerator->generate($data, $state, $abstractClassName); $testGenerator->generate($data, $operations, $queries, $states, $state, $className, $abstractClassName); }