Snippets
Sergio de EOM New code cakeunit4phpstorm.php for PHPStorm 8, 9 and 10 valid run PHPUnit 3.7.38 + CakePHP 2.6.x
Created by
Sergio N.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | <?php
// Date: 10-11-2015
// PHPSorm 8, 9 and 10 + PHPUnit
// Clean argument values
$phpStormRunner = null;
$cleanedArgv = array();
foreach ($_SERVER['argv'] as $key => $value) {
if (strpos($value, 'ide-phpunit.php') === false) {
$cleanedArgv[] = $value;
} else {
$phpStormRunner = $value;
}
}
$_SERVER['argv'] = $cleanedArgv;
// Cleanup PhpStorm runner
if (is_null($phpStormRunner)) {
die('Not running in PhpStorm');
}
$phpStormRunnerContents = file_get_contents($phpStormRunner);
$phpStormRunnerContents = str_replace('IDE_PHPUnit_TextUI_Command::main', 'IDE_Cake_PHPUnit_TextUI_Command::main', $phpStormRunnerContents);
$phpStormRunnerContents = str_replace('IDE_Cake_PHPUnit_TextUI_Command::main()', '//IDE_Cake_PHPUnit_TextUI_Command::main()',
$phpStormRunnerContents);
file_put_contents($phpStormRunner, $phpStormRunnerContents);
// Include PhpStorm runner
include($phpStormRunner);
// Let's bake some CakePHP
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
if (!defined('ROOT')) {
define('ROOT', dirname(__FILE__));
}
if (!defined('APP_DIR')) {
define('APP_DIR', 'app');
}
if (!defined('WEBROOT_DIR')) {
define('WEBROOT_DIR', APP_DIR . DS . 'webroot');
}
if (!defined('WWW_ROOT')) {
define('WWW_ROOT', WEBROOT_DIR . DS);
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (function_exists('ini_set')) {
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
}
if (!include('Cake' . DS . 'bootstrap.php')) {
$failed = true;
}
} else {
if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) {
$failed = true;
}
}
if (!empty($failed)) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.",
E_USER_ERROR);
}
if (Configure::read('debug') < 1) {
die(__d('cake_dev', 'Debug setting does not allow access to this url.'));
}
// Do some reconfiguration
Configure::write('Error', array());
Configure::write('Exception', array());
// Bootstrap CakePHP
require_once CAKE . 'TestSuite' . DS . 'CakeTestSuiteDispatcher.php';
require_once CAKE . 'TestSuite' . DS . 'CakeTestSuiteCommand.php';
// Define new runner
class IDE_Cake_PHPUnit_TextUI_Command extends CakeTestSuiteCommand
{
public static function main($exit = true)
{
// Parse CakePHP-specific test runner options
// And remove CakePHP-specific test runner options from ARGV
$cakePhpOptions = array('case' => 'AllTests');
$cleanedArgv = array();
foreach ($_SERVER['argv'] as $key => $value) {
if (strpos($value, '--cake-') !== false) {
$option = explode('=', $value);
$cakePhpOptions[str_replace('--cake-', '', $option[0])] = isset($option[1]) ? $option[1] : 'true';
} else {
$cleanedArgv[] = $value;
}
}
// Run!
$command = new IDE_Cake_PHPUnit_TextUI_Command('CakeTestLoader', $cakePhpOptions);
$command->run($cleanedArgv, $exit);
}
// protected function handleArguments(array $argv)
// {
// parent::handleArguments($argv);
// $this->arguments['listeners'][] = new IDE_PHPUnit_Framework_TestListener();
// $this->arguments['printer'] = new IDE_PHPUnit_TextUI_ResultPrinter();
// }
protected function handleArguments(array $argv)
{
parent::handleArguments($argv);
$printer = null;
if (isset($this->arguments['printer'])) {
$printer = $this->arguments['printer'];
}
$printer = new IDE_PHPUnit_TextUI_ResultPrinter($printer);
$this->arguments['printer'] = $printer;
$this->arguments['listeners'][] = new IDE_PHPUnit_Framework_TestListener($printer);
}
}
IDE_Cake_PHPUnit_TextUI_Command::main();
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.