mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2025-10-14 00:44:23 -05:00
Begin Refactor
This commit is contained in:
27
vendor/gabordemooij/redbean/testing/cli/plugins/myhooks.php
vendored
Normal file
27
vendor/gabordemooij/redbean/testing/cli/plugins/myhooks.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use \R as R;
|
||||
require 'RedUNIT/CUBRID.php';
|
||||
//Load the CUBRID query writer
|
||||
require('../RedBeanPHP/QueryWriter/CUBRID.php');
|
||||
|
||||
//Define extra test packages from the hook
|
||||
$extraTestsFromHook = array(
|
||||
'CUBRID/Setget',
|
||||
'CUBRID/Writer'
|
||||
);
|
||||
|
||||
//Create a connection for this database
|
||||
$ini['CUBRID'] = array(
|
||||
'host' => 'localhost',
|
||||
'schema' => 'cubase',
|
||||
'user' => 'dba',
|
||||
'pass' => ''
|
||||
);
|
||||
|
||||
$colorMap[ 'CUBRID' ] = '0;35';
|
||||
|
||||
$dsn = "cubrid:host={$ini['CUBRID']['host']};port=33000;dbname={$ini['CUBRID']['schema']}";
|
||||
R::addDatabase( 'CUBRID', $dsn, $ini['CUBRID']['user'], $ini['CUBRID']['pass'], FALSE );
|
||||
R::selectDatabase( 'CUBRID' );
|
||||
R::exec( 'AUTOCOMMIT IS ON' );
|
96
vendor/gabordemooij/redbean/testing/cli/runperf.php
vendored
Normal file
96
vendor/gabordemooij/redbean/testing/cli/runperf.php
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
chdir( '..' );
|
||||
|
||||
require 'testcontainer/rb.phar';
|
||||
|
||||
//load core classes
|
||||
require 'RedUNIT.php';
|
||||
require 'RedUNIT/Base.php';
|
||||
require 'RedUNIT/Base/Performance.php';
|
||||
|
||||
error_reporting( E_ALL );
|
||||
|
||||
//Load configuration file
|
||||
if ( file_exists( 'config/test.ini' ) ) {
|
||||
$ini = parse_ini_file( "config/test.ini", TRUE );
|
||||
} else {
|
||||
die( 'Cant find configuration file.' );
|
||||
}
|
||||
|
||||
//Configure the databases
|
||||
if ( isset( $ini['mysql'] ) ) {
|
||||
$dsn = "mysql:host={$ini['mysql']['host']};dbname={$ini['mysql']['schema']}";
|
||||
|
||||
R::addDatabase( 'mysql', $dsn, $ini['mysql']['user'], $ini['mysql']['pass'], FALSE );
|
||||
|
||||
R::selectDatabase( 'mysql' );
|
||||
|
||||
R::exec( ' SET GLOBAL sql_mode="" ' );
|
||||
}
|
||||
|
||||
if ( isset( $ini['pgsql'] ) ) {
|
||||
$dsn = "pgsql:host={$ini['pgsql']['host']};dbname={$ini['pgsql']['schema']}";
|
||||
|
||||
R::addDatabase( 'pgsql', $dsn, $ini['pgsql']['user'], $ini['pgsql']['pass'], FALSE );
|
||||
}
|
||||
|
||||
if ( isset( $ini['sqlite'] ) ) {
|
||||
R::addDatabase( 'sqlite', 'sqlite:' . $ini['sqlite']['file'], NULL, NULL, FALSE );
|
||||
R::selectDatabase( 'sqlite' );
|
||||
}
|
||||
|
||||
|
||||
// Function to activate a driver
|
||||
function activate_driver( $d )
|
||||
{
|
||||
R::selectDatabase( $d );
|
||||
}
|
||||
$test = new \RedUNIT\Base\Performance();
|
||||
|
||||
$drivers = $test->getTargetDrivers();
|
||||
|
||||
foreach ( $drivers as $driver ) {
|
||||
|
||||
if ( !isset( $ini[$driver] ) ) continue;
|
||||
if ( !isset( $_SERVER['argv'][1])) die('Missing parameter. Usage: php runperf.php <testname> <TIMES> ');
|
||||
|
||||
$method = $_SERVER['argv'][1];
|
||||
|
||||
if ($method === 'setup') {
|
||||
|
||||
echo 'Setup...'.PHP_EOL;
|
||||
|
||||
$test->$method();
|
||||
|
||||
echo 'READY'.PHP_EOL;
|
||||
|
||||
} else {
|
||||
|
||||
$times = 100;
|
||||
if (isset($_SERVER['argv'][2])) {
|
||||
$times = (int) $_SERVER['argv'][2];
|
||||
}
|
||||
|
||||
echo "Performing test: $method with driver $driver ".PHP_EOL;
|
||||
|
||||
for ($j=0; $j<$times; $j++) {
|
||||
|
||||
$t1 = microtime( TRUE );
|
||||
|
||||
$test->$method();
|
||||
|
||||
$t2 = microtime( TRUE );
|
||||
|
||||
$d[] = ($t2 - $t1);
|
||||
|
||||
}
|
||||
|
||||
$s = array_sum($d);
|
||||
$a = ($s / $times);
|
||||
$mx = max($d);
|
||||
$mn = min($d);
|
||||
|
||||
echo PHP_EOL."AVG: $a, MAX: $mx, MIN: $mn, TOTAL: $s, TIMES: $times ".PHP_EOL;
|
||||
}
|
||||
}
|
351
vendor/gabordemooij/redbean/testing/cli/runtests.php
vendored
Normal file
351
vendor/gabordemooij/redbean/testing/cli/runtests.php
vendored
Normal file
@@ -0,0 +1,351 @@
|
||||
<?php
|
||||
|
||||
function redunit_error_handler($errno,$errstr,$errfile,$errline) {
|
||||
$err = "REDUNITERROR: $errno,$errstr,$errfile,$errline";
|
||||
/* ignore certain errors like deprecated notices that have already been checked in main code */
|
||||
if (strpos($err,'PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT') !== FALSE) {
|
||||
return FALSE;
|
||||
}
|
||||
echo $err;
|
||||
throw new \Exception($err);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
chdir( '..' );
|
||||
$xdebugSupported = (function_exists('xdebug_start_code_coverage'));
|
||||
|
||||
if ($xdebugSupported) xdebug_start_code_coverage( XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE );
|
||||
require 'testcontainer/rb.php';
|
||||
|
||||
//load core classes
|
||||
require 'RedUNIT.php';
|
||||
error_reporting( E_ALL );
|
||||
|
||||
//Load configuration file
|
||||
if ( file_exists( 'config/test.ini' ) ) {
|
||||
$ini = parse_ini_file( "config/test.ini", TRUE );
|
||||
$travis = FALSE;
|
||||
} elseif ( file_exists( 'config/test-travis.ini' ) ) {
|
||||
$ini = parse_ini_file( "config/test-travis.ini", TRUE );
|
||||
$travis = TRUE;
|
||||
} else {
|
||||
die( 'Cant find configuration file.' );
|
||||
}
|
||||
|
||||
echo '*** RedUNIT ***'.PHP_EOL;
|
||||
echo 'Welcome to RedUNIT Unit testing framework for RedBeanPHP.'.PHP_EOL;
|
||||
echo PHP_EOL;
|
||||
|
||||
echo sprintf('PHP version: %s', phpversion());
|
||||
echo PHP_EOL;
|
||||
|
||||
/**
|
||||
* Define some globals.
|
||||
*/
|
||||
global $pdo;
|
||||
global $currentDriver;
|
||||
|
||||
//Load basic functions and classes
|
||||
require_once( 'helpers/functions.php' );
|
||||
require_once( 'helpers/classes.php' );
|
||||
|
||||
//Load main classes
|
||||
require_once( 'RedUNIT/Base.php' );
|
||||
require_once( 'RedUNIT/Blackhole.php' );
|
||||
require_once( 'RedUNIT/Mysql.php' );
|
||||
require_once( 'RedUNIT/Postgres.php' );
|
||||
require_once( 'RedUNIT/Sqlite.php' );
|
||||
require_once( 'RedUNIT/CUBRID.php' );
|
||||
require_once( 'RedUNIT/Pretest.php' );
|
||||
|
||||
$extraTestsFromHook = array();
|
||||
$hookPath = '';
|
||||
|
||||
$colorMap = array(
|
||||
'mysql' => '0;31',
|
||||
'pgsql' => '0;32',
|
||||
'sqlite' => '0;34',
|
||||
'CUBRID' => '0;35',
|
||||
);
|
||||
|
||||
@include 'cli/test_hook.php';
|
||||
|
||||
//Configure the databases
|
||||
if ( isset( $ini['mysql'] ) ) {
|
||||
$dsn = "mysql:host={$ini['mysql']['host']};dbname={$ini['mysql']['schema']}";
|
||||
|
||||
R::addDatabase( 'mysql', $dsn, $ini['mysql']['user'], $ini['mysql']['pass'], FALSE );
|
||||
R::addDatabase( 'mysqlc', $dsn, $ini['mysql']['user'], $ini['mysql']['pass'], FALSE );
|
||||
R::addDatabase( 'mysqlc2', $dsn, $ini['mysql']['user'], $ini['mysql']['pass'], FALSE );
|
||||
|
||||
R::selectDatabase( 'mysql' );
|
||||
|
||||
R::exec( ' SET GLOBAL sql_mode="" ' );
|
||||
}
|
||||
|
||||
//HHVM on Travis does not yet support PostgreSQL.
|
||||
if ( defined( 'HHVM_VERSION' ) ) {
|
||||
unset( $ini['pgsql'] );
|
||||
} else {
|
||||
if ( isset( $ini['pgsql'] ) ) {
|
||||
$dsn = "pgsql:host={$ini['pgsql']['host']};dbname={$ini['pgsql']['schema']}";
|
||||
R::addDatabase( 'pgsql', $dsn, $ini['pgsql']['user'], $ini['pgsql']['pass'], FALSE );
|
||||
R::addDatabase( 'pgsqlc', $dsn, $ini['pgsql']['user'], $ini['pgsql']['pass'], FALSE );
|
||||
R::addDatabase( 'pgsqlc2', $dsn, $ini['pgsql']['user'], $ini['pgsql']['pass'], FALSE );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $ini['sqlite'] ) ) {
|
||||
R::addDatabase( 'sqlite', 'sqlite:' . $ini['sqlite']['file'], NULL, NULL, FALSE );
|
||||
R::selectDatabase( 'sqlite' );
|
||||
}
|
||||
|
||||
if ( isset( $ini['CUBRID'] ) ) {
|
||||
$dsn = "cubrid:host={$ini['CUBRID']['host']};port=33000;dbname={$ini['CUBRID']['schema']}";
|
||||
R::addDatabase( 'CUBRID', $dsn, $ini['CUBRID']['user'], $ini['CUBRID']['pass'], FALSE );
|
||||
R::selectDatabase( 'CUBRID' );
|
||||
R::exec( 'AUTOCOMMIT IS ON' );
|
||||
}
|
||||
|
||||
// Function to activate a driver
|
||||
function activate_driver( $d )
|
||||
{
|
||||
R::selectDatabase( $d );
|
||||
}
|
||||
|
||||
$arguments = $_SERVER['argc'];
|
||||
|
||||
$mode = 'all';
|
||||
if ( $arguments > 1 ) {
|
||||
$mode = $_SERVER['argv'][1];
|
||||
}
|
||||
|
||||
$classSpec = null;
|
||||
if ( $arguments > 2 ) {
|
||||
$classSpec = $_SERVER['argv'][2];
|
||||
}
|
||||
|
||||
$covFilter = null;
|
||||
if ( $arguments > 3 ) {
|
||||
$covFilter = $_SERVER['argv'][3];
|
||||
}
|
||||
|
||||
$path = 'RedUNIT/';
|
||||
|
||||
// Possible Selections
|
||||
$packList = array();
|
||||
|
||||
$allPacks = array(
|
||||
'Blackhole/Version',
|
||||
'Blackhole/Toolbox',
|
||||
'Blackhole/Fusebox',
|
||||
'Blackhole/Labels',
|
||||
'Blackhole/Tainted',
|
||||
'Blackhole/Meta',
|
||||
'Blackhole/Import',
|
||||
'Blackhole/Export',
|
||||
'Blackhole/Glue',
|
||||
'Blackhole/Plugins',
|
||||
'Blackhole/Debug',
|
||||
'Blackhole/Stub',
|
||||
'Base/Productivity',
|
||||
'Base/Quickexport',
|
||||
'Base/Hybrid',
|
||||
'Base/Concurrency',
|
||||
'Base/Dispense',
|
||||
'Base/Logging',
|
||||
'Base/Cursors',
|
||||
'Base/Indexes',
|
||||
'Base/Issue408',
|
||||
'Base/Threeway',
|
||||
'Base/Chill',
|
||||
'Base/Arrays',
|
||||
'Base/Boxing',
|
||||
'Base/Typechecking',
|
||||
'Base/Observers',
|
||||
'Base/Database',
|
||||
'Base/Exceptions',
|
||||
'Base/Foreignkeys',
|
||||
'Base/Namedparams',
|
||||
'Base/Prefixes',
|
||||
'Base/Copy',
|
||||
'Base/Dup',
|
||||
'Base/Update',
|
||||
'Base/Utf8',
|
||||
'Base/Batch',
|
||||
'Base/Bean',
|
||||
'Base/Writecache',
|
||||
'Base/Relations',
|
||||
'Base/Association',
|
||||
'Base/Aliasing',
|
||||
'Base/Cross',
|
||||
'Base/Finding',
|
||||
'Base/Partial',
|
||||
'Base/Facade',
|
||||
'Base/Frozen',
|
||||
'Base/Fuse',
|
||||
'Base/Tags',
|
||||
'Base/Xnull',
|
||||
'Base/Largenum',
|
||||
'Base/Issue90',
|
||||
'Base/Issue259',
|
||||
'Base/Issue303',
|
||||
'Base/Nuke',
|
||||
'Base/Keywords',
|
||||
'Base/Count',
|
||||
'Base/With',
|
||||
'Base/Joins',
|
||||
'Base/Traverse',
|
||||
'Base/Misc',
|
||||
'Base/Via',
|
||||
'Base/PullRequest530',
|
||||
'Base/Issue841',
|
||||
'Mysql/Preexist',
|
||||
'Mysql/Double',
|
||||
'Mysql/Writer',
|
||||
'Mysql/Freeze',
|
||||
'Mysql/Setget',
|
||||
'Mysql/Foreignkeys',
|
||||
'Mysql/Parambind',
|
||||
'Mysql/Uuid',
|
||||
'Mysql/Bigint',
|
||||
'Mysql/Issue411',
|
||||
'Postgres/Setget',
|
||||
'Postgres/Foreignkeys',
|
||||
'Postgres/Parambind',
|
||||
'Postgres/Writer',
|
||||
'Postgres/Uuid',
|
||||
'Postgres/Bigint',
|
||||
'Postgres/Partial',
|
||||
'Postgres/Trees',
|
||||
'Sqlite/Setget',
|
||||
'Sqlite/Foreignkeys',
|
||||
'Sqlite/Parambind',
|
||||
'Sqlite/Writer',
|
||||
'Sqlite/Rebuild',
|
||||
'CUBRID/Writer',
|
||||
'CUBRID/Setget',
|
||||
);
|
||||
|
||||
$suffix = array(
|
||||
'Blackhole/Misc',
|
||||
'Base/Close'
|
||||
);
|
||||
|
||||
// Default (mode == all)
|
||||
if ( $mode == 'all' ) {
|
||||
$packList = $allPacks;
|
||||
} else {
|
||||
foreach ( $allPacks as $pack ) {
|
||||
if ( strpos( $pack, $mode ) === 0 ) $packList[] = $pack;
|
||||
}
|
||||
//Add plugin pack to list.
|
||||
if ( count($packList) === 0 && count($extraTestsFromHook) === 0 ) {
|
||||
$packList[] = $mode;
|
||||
}
|
||||
}
|
||||
|
||||
// Always include the last ones.
|
||||
$packList = array_unique(array_merge( $packList, $suffix, $extraTestsFromHook ));
|
||||
$j = 0;
|
||||
foreach ( $packList as $testPack ) {
|
||||
$j++;
|
||||
if ( file_exists( $path . $testPack . '.php' ) ) require( $path . $testPack . '.php' );
|
||||
elseif ( file_exists( $hookPath . $testPack . '.php') ) require( $hookPath . $testPack . '.php' );
|
||||
$testPack = str_replace( '../', '', $testPack );
|
||||
if ($j === 1 && $classSpec) {
|
||||
$testClass = $classSpec;
|
||||
} else {
|
||||
$testClassName = str_replace( ' ', '\\', ( str_replace( '/', ' ', $testPack ) ) );
|
||||
$testClass = '\\RedUNIT\\' . ucfirst( $testClassName );
|
||||
}
|
||||
$test = new $testClass();
|
||||
$drivers = $test->getTargetDrivers();
|
||||
maintestpack( str_replace( '_', ' ', get_class( $test ) ) );
|
||||
$round = 0;
|
||||
$test->setRound( $round );
|
||||
if ( $drivers && is_array( $drivers ) ) {
|
||||
foreach ( $drivers as $driver ) {
|
||||
if ( !isset( $ini[$driver] ) ) continue;
|
||||
echo PHP_EOL;
|
||||
echo '===== DRIVER : (' . $driver . ') =====';
|
||||
echo PHP_EOL;
|
||||
echo PHP_EOL;
|
||||
if ( isset( $colorMap[$driver] ) ) {
|
||||
echo "\033[{$colorMap[$driver]}m";
|
||||
}
|
||||
activate_driver( $driver );
|
||||
$currentDriver = $driver;
|
||||
$test->setCurrentDriver( $driver );
|
||||
$test->prepare();
|
||||
$test->run();
|
||||
$test->cleanUp();
|
||||
if ( isset ( $colorMap[$driver] ) ) {
|
||||
echo "\033[0m";
|
||||
}
|
||||
echo PHP_EOL;
|
||||
$test->setRound( ++$round );
|
||||
}
|
||||
} else {
|
||||
$test->prepare();
|
||||
$test->run();
|
||||
$test->cleanUp();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$xdebugSupported) {
|
||||
echo 'Done. No report - XDEBUG not installed.';
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$report = xdebug_get_code_coverage();
|
||||
$misses = 0;
|
||||
$hits = 0;
|
||||
|
||||
$covLines = array();
|
||||
foreach( $report as $file => $lines ) {
|
||||
|
||||
$pi = pathinfo( $file );
|
||||
|
||||
if ( $covFilter !== null ) {
|
||||
if ( strpos( $file, $covFilter ) === FALSE ) continue;
|
||||
} else {
|
||||
if ( strpos( $file, '/rb.php' ) === FALSE ) {
|
||||
if ( strpos( $file, 'phar/' ) === FALSE ) continue;
|
||||
if ( strpos( $file, '.php' ) === FALSE ) continue;
|
||||
if ( strpos( $file, 'RedBeanPHP' ) === FALSE ) continue;
|
||||
}
|
||||
}
|
||||
$covLines[] = '***** File:'.$file.' ******';
|
||||
$fileData = file_get_contents( $file );
|
||||
$fileLines = explode( "\n", $fileData );
|
||||
$i = 1;
|
||||
foreach( $fileLines as $covLine ) {
|
||||
if ( isset( $lines [$i] ) ) {
|
||||
if ( $lines[$i] === 1 ) {
|
||||
$covLines[] = '[ OK ] '.$covLine;
|
||||
$hits ++;
|
||||
} else if ( $lines[$i] === -1 ){
|
||||
$covLines[] = '[ MISSED! ] '.$covLine;
|
||||
$misses ++;
|
||||
} else {
|
||||
$covLines[] = '[ - ] '.$covLine;
|
||||
}
|
||||
} else {
|
||||
$covLines[] = '[ - ] '.$covLine;
|
||||
}
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
$covFile = implode( "\n", $covLines );
|
||||
@file_put_contents( 'cli/coverage_log.txt', $covFile );
|
||||
if ( $hits > 0 ) {
|
||||
$perc = ( $hits / ( $hits + $misses ) ) * 100;
|
||||
} else {
|
||||
$perc = 0;
|
||||
}
|
||||
echo 'Code Coverage: '.PHP_EOL;
|
||||
echo 'Hits: '.$hits.PHP_EOL;
|
||||
echo 'Misses: '.$misses.PHP_EOL;
|
||||
echo 'Percentage: '.$perc.' %'.PHP_EOL;
|
||||
exit( 0 );
|
14
vendor/gabordemooij/redbean/testing/cli/test_hook_example.php
vendored
Normal file
14
vendor/gabordemooij/redbean/testing/cli/test_hook_example.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Here you can add logic to be executed during the bootstrapping
|
||||
* of RedUNIT.
|
||||
*
|
||||
* You can define/use the following variables:
|
||||
*
|
||||
* $hookPath -> add 1 additional path which will be searched for unit tests
|
||||
* $extraTestsFromHook -> array with additional test packs (will be executed if you pass 'all' argument to CLI runner)
|
||||
*
|
||||
*
|
||||
*/
|
5
vendor/gabordemooij/redbean/testing/cli/testcontainer/put-rb-file-here.txt
vendored
Normal file
5
vendor/gabordemooij/redbean/testing/cli/testcontainer/put-rb-file-here.txt
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/*
|
||||
|
||||
Put the rb.php file in this directory
|
||||
|
||||
*/
|
Reference in New Issue
Block a user