Mutagenesis\Utility\Runkit::applyMutation PHP Méthode

applyMutation() public méthode

Apply a mutation to the relevant file
public applyMutation ( array $mutation )
$mutation array
    public function applyMutation(array $mutation)
    {
        require_once $mutation['mutation']->getFilename();
        $newBlock = $mutation['mutation']->mutate($mutation['tokens'], $mutation['index']);
        $this->_methodPreserveCode = md5($mutation['method']);
        if (runkit_method_rename($mutation['class'], $mutation['method'], $mutation['method'] . $this->_methodPreserveCode) == false) {
            throw new \Exception('runkit_method_rename() failed from ' . $mutation['class'] . '::' . $mutation['method'] . ' to ' . $mutation['class'] . '::' . $mutation['method'] . $this->_methodPreserveCode . ' (mutation application)');
        }
        if (runkit_method_add($mutation['class'], $mutation['method'], $mutation['args'], $newBlock, $this->getMethodFlags($mutation)) == false) {
            throw new \Exception('runkit_method_add() failed when replacing original ' . $mutation['class'] . '::' . $mutation['method'] . '(' . var_export($mutation['args']) . ') with a mutation of' . ' type ' . get_class($mutation['mutation']) . ' using the' . ' following (mutated) source code from ' . $mutation['mutation']->getFilename() . ':' . PHP_EOL . $newBlock);
        }
    }

Usage Example

Exemple #1
0
 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));
 }
All Usage Examples Of Mutagenesis\Utility\Runkit::applyMutation