diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist index a593e62..94c3a3b 100644 --- a/core/phpcs.xml.dist +++ b/core/phpcs.xml.dist @@ -2,6 +2,8 @@ Default PHP CodeSniffer configuration for Drupal core. . + ../sites/default/default.settings.php + ./scripts/run-test.sh diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 09a7aad..24e11b5 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -5,12 +5,12 @@ * This script runs Drupal tests from command line. */ +use Drupal\Core\Asset\AttachedAssets; use Drupal\Component\FileSystem\FileSystem; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Timer; use Drupal\Component\Uuid\Php; use Drupal\Core\Database\Database; -use Drupal\Core\Site\Settings; use Drupal\Core\StreamWrapper\PublicStream; use Drupal\Core\Test\TestDatabase; use Drupal\Core\Test\TestRunnerKernel; @@ -98,7 +98,8 @@ $test_discovery = NULL; try { $test_discovery = \Drupal::service('test_discovery'); - } catch (Exception $e) { + } + catch (Exception $e) { error_log((string) $e); echo (string)$e; exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); @@ -113,7 +114,7 @@ } // Output the list of files. else { - foreach(array_values($test_classes) as $test_class) { + foreach (array_values($test_classes) as $test_class) { echo $test_class . "\n"; } } @@ -147,7 +148,7 @@ drupal_set_time_limit(0); simpletest_script_reporter_init(); -$tests_to_run = array(); +$tests_to_run = []; for ($i = 0; $i < $args['repeat']; $i++) { $tests_to_run = array_merge($tests_to_run, $test_list); } @@ -344,7 +345,7 @@ function simpletest_script_help() { */ function simpletest_script_parse_args() { // Set default values. - $args = array( + $args = [ 'script' => '', 'help' => FALSE, 'list' => FALSE, @@ -366,7 +367,7 @@ function simpletest_script_parse_args() { 'verbose' => FALSE, 'keep-results' => FALSE, 'keep-results-table' => FALSE, - 'test_names' => array(), + 'test_names' => [], 'repeat' => 1, 'die-on-fail' => FALSE, 'browser' => FALSE, @@ -375,7 +376,7 @@ function simpletest_script_parse_args() { 'execute-test' => '', 'xml' => '', 'non-html' => FALSE, - ); + ]; // Override with set values. $args['script'] = basename(array_shift($_SERVER['argv'])); @@ -398,7 +399,7 @@ function simpletest_script_parse_args() { $args[$matches[1]] = array_shift($_SERVER['argv']); } // Clear extraneous values. - $args['test_names'] = array(); + $args['test_names'] = []; $count++; } else { @@ -423,7 +424,7 @@ function simpletest_script_parse_args() { if ($args['browser']) { $args['keep-results'] = TRUE; } - return array($args, $count); + return [$args, $count]; } /** @@ -591,13 +592,13 @@ function simpletest_script_setup_database($new = FALSE) { else { $sqlite = DRUPAL_ROOT . '/' . $args['sqlite']; } - $databases['test-runner']['default'] = array( + $databases['test-runner']['default'] = [ 'driver' => 'sqlite', 'database' => $sqlite, - 'prefix' => array( + 'prefix' => [ 'default' => '', - ), - ); + ], + ]; // Create the test runner SQLite database, unless it exists already. if ($new && !file_exists($sqlite)) { if (!is_dir(dirname($sqlite))) { @@ -659,7 +660,7 @@ function simpletest_script_execute_batch($test_classes) { $total_status = SIMPLETEST_SCRIPT_EXIT_SUCCESS; // Multi-process execution. - $children = array(); + $children = []; while (!empty($test_classes) || !empty($children)) { while (count($children) < $args['concurrency']) { if (empty($test_classes)) { @@ -669,7 +670,7 @@ function simpletest_script_execute_batch($test_classes) { try { $test_id = Database::getConnection('default', 'test-runner') ->insert('simpletest_test_id') - ->useDefaults(array('test_id')) + ->useDefaults(['test_id']) ->execute(); } catch (Exception $e) { @@ -681,7 +682,7 @@ function simpletest_script_execute_batch($test_classes) { $test_class = array_shift($test_classes); // Fork a child process. $command = simpletest_script_command($test_id, $test_class); - $process = proc_open($command, array(), $pipes, NULL, NULL, array('bypass_shell' => TRUE)); + $process = proc_open($command, [], $pipes, NULL, NULL, ['bypass_shell' => TRUE]); if (!is_resource($process)) { echo "Unable to fork test process. Aborting.\n"; @@ -689,12 +690,12 @@ function simpletest_script_execute_batch($test_classes) { } // Register our new child. - $children[] = array( + $children[] = [ 'process' => $process, 'test_id' => $test_id, 'class' => $test_class, 'pipes' => $pipes, - ); + ]; } // Wait for children every 200ms. @@ -755,7 +756,7 @@ function simpletest_script_run_phpunit($test_id, $class) { set_time_limit($reflection->getStaticPropertyValue('runLimit')); } - $results = simpletest_run_phpunit_tests($test_id, array($class), $status); + $results = simpletest_run_phpunit_tests($test_id, [$class], $status); simpletest_process_phpunit_results($results); // Map phpunit results to a data structure we can pass to @@ -781,7 +782,7 @@ function simpletest_script_run_one_test($test_id, $test_class) { else { $class_name = $test_class; // Use empty array to run all the test methods. - $methods = array(); + $methods = []; } $test = new $class_name($test_id); if (is_subclass_of($test_class, TestCase::class)) { @@ -834,7 +835,7 @@ function simpletest_script_command($test_id, $test_class) { } $command .= ' --php ' . escapeshellarg($php); $command .= " --test-id $test_id"; - foreach (array('verbose', 'keep-results', 'color', 'die-on-fail') as $arg) { + foreach (['verbose', 'keep-results', 'color', 'die-on-fail'] as $arg) { if ($args[$arg]) { $command .= ' --' . $arg; } @@ -887,7 +888,7 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) { // Do not output verbose cleanup messages in case of a positive exitcode. $output = !empty($exitcode); - $messages = array(); + $messages = []; $messages[] = "- Found database prefix '$db_prefix' for test ID $test_id."; @@ -916,7 +917,7 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) { // simpletest_clean_temporary_directories() cannot be used here, since it // would also delete file directories of other tests that are potentially // running concurrently. - file_unmanaged_delete_recursive($test_directory, array('Drupal\simpletest\TestBase', 'filePreDeleteCallback')); + file_unmanaged_delete_recursive($test_directory, ['Drupal\simpletest\TestBase', 'filePreDeleteCallback']); $messages[] = "- Removed test site directory."; } @@ -957,7 +958,7 @@ function simpletest_script_get_test_list() { global $args; $types_processed = empty($args['types']); - $test_list = array(); + $test_list = []; if ($args['all'] || $args['module']) { try { $groups = simpletest_test_get_all($args['module'], $args['types']); @@ -967,7 +968,7 @@ function simpletest_script_get_test_list() { echo (string) $e; exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); } - $all_tests = array(); + $all_tests = []; foreach ($groups as $group => $tests) { $all_tests = array_merge($all_tests, array_keys($tests)); } @@ -975,7 +976,7 @@ function simpletest_script_get_test_list() { } else { if ($args['class']) { - $test_list = array(); + $test_list = []; foreach ($args['test_names'] as $test_class) { list($class_name) = explode('::', $test_class, 2); if (class_exists($class_name)) { @@ -989,7 +990,7 @@ function simpletest_script_get_test_list() { echo (string) $e; exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); } - $all_classes = array(); + $all_classes = []; foreach ($groups as $group) { $all_classes = array_merge($all_classes, array_keys($group)); } @@ -1036,7 +1037,7 @@ function simpletest_script_get_test_list() { // minimal conditions only; i.e., a '*.php' file that has '/Tests/' in // its path. // Ignore anything from third party vendors. - $ignore = array('.', '..', 'vendor'); + $ignore = ['.', '..', 'vendor']; $files = []; if ($args['directory'][0] === '/') { $directory = $args['directory']; @@ -1126,11 +1127,11 @@ function simpletest_script_get_test_list() { function simpletest_script_reporter_init() { global $args, $test_list, $results_map; - $results_map = array( + $results_map = [ 'pass' => 'Pass', 'fail' => 'Fail', 'exception' => 'Exception', - ); + ]; echo "\n"; echo "Drupal test run\n"; @@ -1171,13 +1172,13 @@ function simpletest_script_reporter_display_summary($class, $results) { // Output all test results vertically aligned. // Cut off the class name after 60 chars, and pad each group with 3 digits // by default (more than 999 assertions are rare). - $output = vsprintf('%-60.60s %10s %9s %14s %12s', array( + $output = vsprintf('%-60.60s %10s %9s %14s %12s', [ $class, $results['#pass'] . ' passes', !$results['#fail'] ? '' : $results['#fail'] . ' fails', !$results['#exception'] ? '' : $results['#exception'] . ' exceptions', !$results['#debug'] ? '' : $results['#debug'] . ' messages', - )); + ]); $status = ($results['#fail'] || $results['#exception'] ? 'fail' : 'pass'); simpletest_script_print($output . "\n", simpletest_script_color_code($status)); @@ -1198,7 +1199,7 @@ function simpletest_script_reporter_write_xml_results() { } $test_class = ''; - $xml_files = array(); + $xml_files = []; foreach ($results as $result) { if (isset($results_map[$result->status])) { @@ -1214,7 +1215,7 @@ function simpletest_script_reporter_write_xml_results() { $doc = new DomDocument('1.0'); $root = $doc->createElement('testsuite'); $root = $doc->appendChild($root); - $xml_files[$test_class] = array('doc' => $doc, 'suite' => $root); + $xml_files[$test_class] = ['doc' => $doc, 'suite' => $root]; } } @@ -1412,7 +1413,7 @@ function simpletest_script_color_code($status) { * @see http://php.net/manual/en/function.levenshtein.php */ function simpletest_script_print_alternatives($string, $array, $degree = 4) { - $alternatives = array(); + $alternatives = []; foreach ($array as $item) { $lev = levenshtein($string, $item); if ($lev <= strlen($item) / $degree || FALSE !== strpos($string, $item)) { @@ -1440,7 +1441,7 @@ function simpletest_script_print_alternatives($string, $array, $degree = 4) { */ function simpletest_script_load_messages_by_test_id($test_ids) { global $args; - $results = array(); + $results = []; // Sqlite has a maximum number of variables per query. If required, the // database query is split into chunks. @@ -1448,15 +1449,15 @@ function simpletest_script_load_messages_by_test_id($test_ids) { $test_id_chunks = array_chunk($test_ids, SIMPLETEST_SCRIPT_SQLITE_VARIABLE_LIMIT); } else { - $test_id_chunks = array($test_ids); + $test_id_chunks = [$test_ids]; } foreach ($test_id_chunks as $test_id_chunk) { try { $result_chunk = Database::getConnection('default', 'test-runner') - ->query("SELECT * FROM {simpletest} WHERE test_id IN ( :test_ids[] ) ORDER BY test_class, message_id", array( + ->query("SELECT * FROM {simpletest} WHERE test_id IN ( :test_ids[] ) ORDER BY test_class, message_id", [ ':test_ids[]' => $test_id_chunk, - ))->fetchAll(); + ])->fetchAll(); } catch (Exception $e) { echo (string) $e; @@ -1492,12 +1493,12 @@ function simpletest_script_open_browser() { } // Get the results form. - $form = array(); + $form = []; SimpletestResultsForm::addResultForm($form, $results); // Get the assets to make the details element collapsible and theme the result // form. - $assets = new \Drupal\Core\Asset\AttachedAssets(); + $assets = new AttachedAssets(); $assets->setLibraries([ 'core/drupal.collapse', 'system/admin', diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php index 2b2bdb7..7287710 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -86,7 +86,7 @@ * ); * @endcode */ -$databases = array(); +$databases = []; /** * Customizing database settings. @@ -154,13 +154,13 @@ * The 'default' element is mandatory and holds the prefix for any tables * not specified elsewhere in the array. Example: * @code - * 'prefix' => array( + * 'prefix' => [ * 'default' => 'main_', * 'users' => 'shared_', * 'sessions' => 'shared_', * 'role' => 'shared_', * 'authmap' => 'shared_', - * ), + * ], * @endcode * You can also use a reference to a schema/database as a prefix. This may be * useful if your Drupal installation exists in a schema that is not the default @@ -168,13 +168,13 @@ * time. * Example: * @code - * 'prefix' => array( + * 'prefix' => [ * 'default' => 'main.', * 'users' => 'shared.', * 'sessions' => 'shared.', * 'role' => 'shared.', * 'authmap' => 'shared.', - * ); + * ]; * @endcode * NOTE: MySQL and SQLite's definition of a schema is a database. * @@ -183,14 +183,14 @@ * example, to enable MySQL SELECT queries to exceed the max_join_size system * variable, and to reduce the database connection timeout to 5 seconds: * @code - * $databases['default']['default'] = array( - * 'init_commands' => array( + * $databases['default']['default'] = [ + * 'init_commands' => [ * 'big_selects' => 'SET SQL_BIG_SELECTS=1', - * ), - * 'pdo' => array( + * ], + * 'pdo' => [ * PDO::ATTR_TIMEOUT => 5, - * ), - * ); + * ], + * ]; * @endcode * * WARNING: The above defaults are designed for database portability. Changing @@ -205,22 +205,22 @@ * * Sample Database configuration format for PostgreSQL (pgsql): * @code - * $databases['default']['default'] = array( + * $databases['default']['default'] = [ * 'driver' => 'pgsql', * 'database' => 'databasename', * 'username' => 'sqlusername', * 'password' => 'sqlpassword', * 'host' => 'localhost', * 'prefix' => '', - * ); + * ]; * @endcode * * Sample Database configuration format for SQLite (sqlite): * @code - * $databases['default']['default'] = array( + * $databases['default']['default'] = [ * 'driver' => 'sqlite', * 'database' => '/path/to/databasefilename', - * ); + * ]; * @endcode */ @@ -244,12 +244,12 @@ * * Example: * @code - * $config_directories = array( + * $config_directories = [ * CONFIG_SYNC_DIRECTORY => '/directory/outside/webroot', - * ); + * ]; * @endcode */ -$config_directories = array(); +$config_directories = []; /** * Settings: @@ -377,7 +377,7 @@ * Specify every reverse proxy IP address in your environment. * This setting is required if $settings['reverse_proxy'] is TRUE. */ -# $settings['reverse_proxy_addresses'] = array('a.b.c.d', ...); +# $settings['reverse_proxy_addresses'] = ['a.b.c.d', ...]; /** * Set this value if your proxy server sends the client IP in a header @@ -462,16 +462,14 @@ * example, to use Symfony's APC class loader without automatic detection, * uncomment the code below. */ -/* -if ($settings['hash_salt']) { - $prefix = 'drupal.' . hash('sha256', 'drupal.' . $settings['hash_salt']); - $apc_loader = new \Symfony\Component\ClassLoader\ApcClassLoader($prefix, $class_loader); - unset($prefix); - $class_loader->unregister(); - $apc_loader->register(); - $class_loader = $apc_loader; -} -*/ +# if ($settings['hash_salt']) { +# $prefix = 'drupal.' . hash('sha256', 'drupal.' . $settings['hash_salt']); +# $apc_loader = new \Symfony\Component\ClassLoader\ApcClassLoader($prefix, $class_loader); +# unset($prefix); +# $class_loader->unregister(); +# $apc_loader->register(); +# $class_loader = $apc_loader; +# } /** * Authorized file system operations: @@ -562,10 +560,10 @@ * The "en" part of the variable name, is dynamic and can be any langcode of * any added language. (eg locale_custom_strings_de for german). */ -# $settings['locale_custom_strings_en'][''] = array( +# $settings['locale_custom_strings_en'][''] = [ # 'forum' => 'Discussion board', # '@count min' => '@count minutes', -# ); +# ]; /** * A custom theme for the offline page: @@ -619,7 +617,7 @@ * override in a services.yml file in the same directory as settings.php * (definitions in this file will override service definition defaults). */ -# $settings['bootstrap_config_storage'] = array('Drupal\Core\Config\BootstrapConfigStorageFactory', 'getFileStorage'); +# $settings['bootstrap_config_storage'] = ['Drupal\Core\Config\BootstrapConfigStorageFactory', 'getFileStorage']; /** * Configuration overrides. @@ -710,9 +708,9 @@ * * For example: * @code - * $settings['trusted_host_patterns'] = array( + * $settings['trusted_host_patterns'] = [ * '^www\.example\.com$', - * ); + * ]; * @endcode * will allow the site to only run from www.example.com. * @@ -723,12 +721,12 @@ * * For example: * @code - * $settings['trusted_host_patterns'] = array( + * $settings['trusted_host_patterns'] = [ * '^example\.com$', * '^.+\.example\.com$', * '^example\.org$', * '^.+\.example\.org$', - * ); + * ]; * @endcode * will allow the site to run off of all variants of example.com and * example.org, with all subdomains included.