function ModuleBuilderModuleGenerationTestCase::assertWellFormedPHP in Module Builder 8.3
Assert a string is correctly-formed PHP.
Parameters
$string: The text of PHP to check. This is expected to begin with a '<?php' tag.
$message = NULL: The assertion message.
1 call to ModuleBuilderModuleGenerationTestCase::assertWellFormedPHP()
- ModuleBuilderModuleGenerationTestCase::testModuleGeneration in tests/
module_builder.test - Test generating module code.
File
- tests/
module_builder.test, line 202 - Contains tests for the Module builder module.
Class
- ModuleBuilderModuleGenerationTestCase
- Test case for Module Builder module generation.
Code
function assertWellFormedPHP($code, $message = NULL) {
if (!isset($message)) {
$message = "String evaluates as correct PHP.";
}
// Code passed to eval() should not have an opening PHP tag, which our
// module code does. However, we can close a PHP tag at the start and then
// our opening tag is acceptable.
// It should be safe to eval as all of the functions will be prefixed with
// the module name (unless something has gone horribly wrong, in which case
// case the test should fail anyway.)
$eval = eval('?>' . $code);
// eval() returns FALSE if there is a parse error.
$this
->assertIdentical($eval, NULL, $message);
}