/** * Creates an instance of Grader if not already created */ private static function initializeGrader() { if (is_null(self::$grader)) { // Create new grader self::$grader = new Grader(); } // Set practice mode OFF by default self::$practice = false; }
/** * Creates a run to the given problem * * @param type $problemData * @param type $contestant */ public static function createRunToProblem($problemData, $contestant) { $r = self::createRequestCommon($problemData, null, $contestant); // Call API RunController::$grader = new GraderMock(); $response = RunController::apiCreate($r); // Clean up unset($_REQUEST); return array('request' => $r, 'contestant' => $contestant, 'response' => $response); }
/** * Detours the Grader calls. * Problem: Submiting a new run invokes the Grader::grade() function which makes * a HTTP call to official grader using CURL. This call will fail if grader is * not turned on. We are not testing the Grader functionallity itself, we are * only validating that we populate the DB correctly and that we make a call * to the function Grader::grade(), without executing the contents. * * Solution: We create a phpunit mock of the Grader class. We create a fake * object Grader with the function grade() which will always return true * and expects to be excecuted once. * */ public function detourGraderCalls($times = null) { if (is_null($times)) { $times = $this->once(); } // Create a fake Grader object which will always return true (see // next line) $graderMock = $this->getMock('Grader', array('Grade')); // Set expectations: $graderMock->expects($times)->method('Grade')->will($this->returnValue(true)); // Detour all Grader::grade() calls to our mock RunController::$grader = $graderMock; ProblemController::$grader = $graderMock; }