/** * Create and load the definition of a mock class * for instance method invocations only. * * @param string $className * @param string $nameOfTheMethodToPassThrough * If not empty string, it tells this instance to pass calls to * this method to the real object of the class being mocked * and continue to mock other methods. * If it is empty, it tells this instance to mock all methods. * * @return \Box\TestScribe\Mock\MockClass * @throws \DI\NotFoundException */ public function createAndLoadMockClass($className, $nameOfTheMethodToPassThrough) { $mockClass = $this->mockClassFactory->create($className, false, $nameOfTheMethodToPassThrough); $mockObjectName = $mockClass->getMockObjectName(); // Use my own implementation of mock objects which will // intercept protected methods. $mockClassName = $this->classBuilder->create($mockObjectName, $className, $nameOfTheMethodToPassThrough); $mockClass->setMockClassName($mockClassName); return $mockClass; }
public function testHierarchyMethodMerge() { list($ns, $classes, $map) = ClassBuilder::i()->register(' class Foo { /** :big = true; */ public function pants() {} } class Bar extends Foo { /** :whoop = true; */ public function pants() {} } '); $hierarchy = $this->parser->parseHierarchy($map['Bar']); $expected = ['big' => true, 'whoop' => true]; $this->assertEquals($expected, $hierarchy->methods['pants']); }
$Output .= $this->Tab(2) . "}\n"; $Output .= "\n"; } $Output .= "\n"; $Output .= $this->Tab(1) . "}\n"; $Output .= "\n"; /* $FileName = 'ClassBuilder/' . $this->ClassName . '.txt'; $FilePath = 'http://www.card2u.com.my/' . $FileName; $File = fopen($FileName, 'w') or die("Error opening file!"); fwrite($File, $Output); fclose($File) or die("Error closing file!"); */ $this->Output = $Output; $this->FilePath = $FilePath; } function Tab($Num) { $Output = ''; for ($i = 1; $i <= $Num; $i++) { $Output .= ' '; } return $Output; } } $x = new ClassBuilder("QuestionSet"); $x->SetVariables(array('_single_choice', '_multiple_choice', '_completion', '_true_or_false', '_cloze_test', '_simple_answer', '_short_answer', '_integration')); // $x->SetMethods(array("Method1", "Method2")); $x->GenerateClass(); echo $x->GetOutput(); flush();
array_walk($fields, function (&$item, $key) { $item = "{$item} = :{$item}"; }); $contents[] = ""; $contents[] = "\tfunction update() {"; $contents[] = "\t\t\$stmt = \$this->conn->prepare("; $contents[] = "\t\t\t'UPDATE {$table} SET"; $contents[] = "\t\t\t\t" . implode(", ", $fields); $contents[] = "\t\t\t\tWHERE id = :id;"; $contents[] = "\t\t\t);'"; $contents[] = "\t\t);"; foreach ($this->fields as $field) { $contents[] = "\t\t\$stmt->bindValue(':{$field}', \$this->{$field}, \\PDO::PARAM_STR);"; } $contents[] = "\t\t\$stmt->bindValue(':id', \$this->id, \\PDO::PARAM_INT);"; $contents[] = ""; $contents[] = "\t\treturn \$stmt;"; $contents[] = "\t}"; $contents[] = ""; $contents[] = "\tfunction load(\$row) {"; foreach ($this->fields as $field) { $contents[] = "\t\t\$this->{$field} \t\t= \$row['{$table}__{$field}'];"; } $contents[] = "\t}"; $contents[] = "}"; print_r($contents); file_put_contents("{$path}/{$this->name}.php", implode("\n", $contents)); } } $builder = new ClassBuilder($argv); $builder->run();