[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/tests/includes/ -> install.php (source)

   1  <?php
   2  
   3  /**
   4   * Install YOURLS tables
   5   *
   6   * @return void
   7   */
   8  function yut_install_yourls() {
   9      yut_drop_all_tables_if_local();
  10  
  11      if (!yourls_check_database_version()) {
  12          die( sprintf( 'MySQL version too old. Version is: %s', yourls_get_database_version() ) );
  13      }
  14  
  15      if (!yourls_check_php_version()) {
  16          die( sprintf( 'PHP version too old. Version is: %s', phpversion() ) );
  17      }
  18  
  19      $create = yourls_create_sql_tables();
  20      if (array() != $create['error']) {
  21          die( sprintf( 'Could not run SQL. Error is: %s', implode( "\n\n", $create['error'] ) ) );
  22      }
  23  }
  24  
  25  
  26  /**
  27   * Find YOURLS config depending on unit test context
  28   *
  29   * Unit tests can be run locally (someone typing 'phpunit' in their console) or on Travis
  30   * on YOURLS/YOURLS or YOURLS/YOURLS/YOURLS-unit-tests when pushing commits.
  31   *
  32   * @return string  config file path (eg '/home/you/path/to/config.php')
  33   */
  34  function yut_find_config() {
  35      $config_locations = array(
  36          dirname(dirname(__DIR__)). '/yourls-tests-config.php',  // manual, run locally, config in YOURLS root
  37          dirname(__DIR__). '/yourls-tests-config.php',           // manual, run locally, config in YOURLS/tests
  38          dirname(dirname(__DIR__)) . '/user/config.php',         // Travis, run from YOURLS/YOURLS
  39      );
  40  
  41      foreach($config_locations as $config) {
  42          if (is_readable($config)) {
  43              return str_replace('\\', '/', $config);
  44          }
  45      }
  46  
  47      die( sprintf( "ERROR: config file missing. Current directory: %s\n", dirname(__DIR__) ) );
  48  }
  49  
  50  /**
  51   * Destroy tables in selected DB if tests run locally
  52   *
  53   * If not running in Travis environment, this function will drop all tables in the selected DB
  54   *
  55   * @return void
  56   */
  57  function yut_drop_all_tables_if_local() {
  58      if( !yut_is_local() )
  59          return;
  60  
  61      // If not running in Travis environment, drop any tables from the selected database prior to starting tests
  62      $tables = sprintf('%s,%s,%s', YOURLS_DB_TABLE_URL, YOURLS_DB_TABLE_OPTIONS, YOURLS_DB_TABLE_LOG);
  63      $sql = sprintf('DROP TABLE IF EXISTS %s', $tables);
  64      yourls_get_db()->perform($sql);
  65  }


Generated: Wed Sep 28 05:10:02 2022 Cross-referenced by PHPXref 0.7.1