protected function format($raw_php_string, $expected_formatted_php_string) { // parse $parser = new Parser(); $stmts = $parser->parsePHPString($raw_php_string); // validate $validator = new Validator(); $is_valid = $validator->validate($stmts); PHPUnit::assertTrue($is_valid, "Found unexpected error: " . implode(", ", $validator->getErrors())); // format $formatter = new Formatter(); $actual_formatted_php_string = $formatter->format($stmts); PHPUnit::assertEquals($expected_formatted_php_string, $actual_formatted_php_string); }
protected function execute($php_string, $test_vars, $expected_result, $type = 'float') { // parse $parser = new Parser(); $stmts = $parser->parsePHPString($php_string); // validate $validator = new Validator(); $is_valid = $validator->validate($stmts); PHPUnit::assertTrue($is_valid, "Found unexpected error: " . implode(", ", $validator->getErrors())); // execute $executor = new Executor(); $actual_result = $executor->execute($php_string, $test_vars, $type); PHPUnit::assertEquals($expected_result, $actual_result); }
protected function validate($php_string, $expected_error) { $parser = new Parser(); $stmts = $parser->parsePHPString($php_string); $validator = new Validator(); $is_valid = $validator->validate($stmts); if ($expected_error === null) { PHPUnit::assertTrue($is_valid, "Found unexpected error: " . implode(", ", $validator->getErrors())); return; } // make sure error matches PHPUnit::assertFalse($is_valid, "Validator was valid, but expected error " . $expected_error); PHPUnit::assertContains($expected_error, implode(" | ", $validator->getErrors()), "Expected error not found in validator errors."); }