Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:04
Show Gist options
  • Save rightfold/53e91ae15dac2f1059ba to your computer and use it in GitHub Desktop.
Save rightfold/53e91ae15dac2f1059ba to your computer and use it in GitHub Desktop.
<?php
public static function generateTestCaseClass(Specification $specification) {
$testCaseName = 'RapidTest_PHPUnit_TestCase_' . uniqid();
$code = "class $testCaseName extends \\PHPUnit_Framework_TestCase {\n";
foreach ($specification->getProperties() as $property) {
$testName = 'test_' . uniqid();
self::$__properties[$testName] = $property;
$code .= " public function $testName() {\n";
$code .= ' $property = ' . __CLASS__ . "::\$__properties['$testName'];\n";
$code .= " \$property();\n";
$code .= " }\n";
}
$code .= "}\n";
eval($code);
return new \ReflectionClass($testCaseName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment