public function testShouldRevertToOriginalStaticMethodBodyWhenRequested() { $mutationInstance = new OperatorAddition(2); $testeeInstance = new Testee(); $testeeInstance->setFileName($this->root . '/runkit/Math2.php')->setClassName('RunkitTest_Math2')->setMethodName('add')->setArguments('$op1,$op2')->setTokens(array(array(335, 'return', 7), array(309, '$op1', 7), '+', array(309, '$op2', 7), ';')); $mutant = new Mutant($testeeInstance, $mutationInstance); $runkit = new Runkit(); $runkit->applyMutation($mutant); $runkit->reverseMutation($mutant); $this->assertEquals(2, \RunkitTest_Math2::add(1, 1)); }
/** * Uses an instance of PHPUnit_TextUI_Command to execute the PHPUnit * tests and simulates any Mutagenesis supported command line options suitable * for PHPUnit. At present, we merely dissect a generic 'options' string * equivelant to anything typed into a console after a normal 'phpunit' * command. The adapter captures the TextUI output for further processing. * * To prevent duplication of output from stdout, PHPUnit is hard * configured to write to stderrm(stdin is used in proc_open call) * * @param array $arguments Mutagenesis arguments to pass to PHPUnit * @param string|null $mutation * @param string|null $bootstrap * * @return void * * @throws \Exception */ public static function main($arguments, $mutation = null, $bootstrap = null) { $arguments = unserialize($arguments); /** * Grab the Runkit extension utility and apply the mutation if needed */ if (!is_null($mutation)) { $mutation = unserialize($mutation); if (!empty($mutation)) { if (!is_null($bootstrap)) { require_once $bootstrap; } if (!in_array('runkit', get_loaded_extensions())) { throw new \Exception('Runkit extension is not loaded. Unfortunately, runkit' . ' is essential for Mutagenesis. Please see the manual or' . ' README which explains how to install an updated runkit' . ' extension suitable for Mutagenesis and PHP 5.3.'); } $runkit = new Runkit(); $runkit->applyMutation($mutation); } } /** * Switch working directory to tests and execute the test suite */ $originalWorkingDirectory = getcwd(); if (isset($arguments['tests'])) { chdir($arguments['tests']); } $command = new \PHPUnit_TextUI_Command(); if (empty($arguments['clioptions'])) { $arguments['clioptions'] = array(); } $command->run($arguments['clioptions'], false); chdir($originalWorkingDirectory); }