Permalink
Browse files

Add support for multiple XML files, allow CLI overrides

  • Loading branch information...
1 parent 40f66b0 commit 79cab114bca08cc9b762b3237a2a26d8d8a3da85 @NSinopoli NSinopoli committed May 12, 2013
Showing with 83 additions and 48 deletions.
  1. +12 −15 README.md
  2. +7 −5 app/config/bootstrap.php
  3. +7 −4 app/controller/Home.php
  4. +10 −6 app/view/home/index.html
  5. +47 −18 bin/vpu
View
@@ -135,9 +135,8 @@ By default, the file selector does not display hidden folders (i.e., folders wit
If you'd like to use a [PHPUnit XML configuration file](http://www.phpunit.de/manual/current/en/appendixes.configuration.html) to define which tests to run, you will have to do the following:
-1. Within the `$config` array, change `xml_configuration_file` to the path where the configuration file can be found.
- - Note that if you leave this set to `false`, but select 'Yes' for the 'Use XML Config' option on the UI, VPU will complain and run with the tests chosen in the file selector instead.
-2. Modify your PHPUnit XML configuration file to include this block:
+1. Within the `$config` array, change `xml_configuration_files` to reflect the location(s) where the configuration file(s) can be found.
+2. Modify your PHPUnit XML configuration file(s) to include this block:
```xml
<!-- This is required for VPU to work correctly -->
@@ -162,24 +161,22 @@ If you'd like to load any bootstraps, you will have to do the following:
VPU can be run at the command line, making it possible to automate the generation of test results via cron.
-### Configuration
+### Usage
-The CLI script requires that the `xml_configuration_file` setting within the `$config` array of `app/config/bootstrap.php` be properly set. VPU will run the tests specified in the XML configuration file. Please be sure that the [configuration file](#xml-configuration) contains the required JSON listener.
-
-In order to [save](#snapshots) the test results, the CLI script also requires that the `snapshot_directory` setting within the `$config` array of `app/config/bootstrap.php` be properly set. Note that the value of `create_snapshots` within the `$config` array has no effect on the CLI script.
+```bash
+# from the project root
+bin/vpu --xml_configuration_file app/config/phpunit.xml --snapshot_directory app/history -e -s
+```
-Errors will be [sandboxed](#sandboxing) if `sandbox_errors` is set to `true` within the `$config` array of `app/config/bootstrap.php`.
+### Options
-Test statistics will be stored if `store_statistics` is set to `true` within the `$config` array of `app/config/bootstrap.php`. Make sure that the [database](#graph-generation) is configured correctly.
+-f, --xml_configuration_file: The path to the [XML configuration file](#xml-configuration). Required. Please be sure that the [configuration file](#xml-configuration) contains the required JSON listener.
-### Executing
+-d, --snapshot_directory: The path where the [snapshot](#snapshots) should be stored. Optional. Defaults to the value of `snapshot_directory` within the `$config` array of `app/config/bootstrap`.
-VPU can be executed from the command line using the following command:
+-e, --sandbox_errors: Whether or not to [sandbox](#sandboxing) PHP errors. Optional. Defaults to the value of `sandbox_errors` within the `$config` array of `app/config/bootstrap`.
-```bash
-# from the project root
-bin/vpu
-```
+-s, --store_statistics: Whether or not to store the statistics in a database. Optional. Defaults to the value of `store_statistics` within the `$config` array of `app/config/bootstrap`. Make sure that the [database](#graph-generation) is configured correctly.
## Version Information
View
@@ -58,13 +58,15 @@
// (i.e., folders with a '.' prefix)
'ignore_hidden_folders' => true,
- // The PHPUnit XML configuration file to use
- // (set to false to disable)
+ // The PHPUnit XML configuration files to use
+ // (leave empty to disable)
//
- // In order for VPU to function correctly, the configuration file must
+ // In order for VPU to function correctly, the configuration files must
// contain a JSON listener (see the README for more information)
- 'xml_configuration_file' => false,
- //'xml_configuration_file' => "{$root}/app/config/phpunit.xml",
+ 'xml_configuration_files' => array(),
+ //'xml_configuration_files' => array(
+ // "{$root}/app/config/phpunit.xml"
+ //),
// Paths to any necessary bootstraps
'bootstraps' => array(
View
@@ -52,15 +52,17 @@ public function index($request) {
$store_statistics = \app\lib\Library::retrieve('store_statistics');
$create_snapshots = \app\lib\Library::retrieve('create_snapshots');
$sandbox_errors = \app\lib\Library::retrieve('sandbox_errors');
- $use_xml = \app\lib\Library::retrieve('xml_configuration_file');
+ $xml_configuration_files = \app\lib\Library::retrieve(
+ 'xml_configuration_files'
+ );
return compact(
'create_snapshots',
'sandbox_errors',
'stats',
'store_statistics',
'suites',
'test_directories',
- 'use_xml'
+ 'xml_configuration_files'
);
}
@@ -75,8 +77,9 @@ public function index($request) {
$xml_config = false;
$notifications = array();
- if ( $request->data['use_xml'] ) {
- $xml_config = \app\lib\Library::retrieve('xml_configuration_file');
+ if ( $xml_file_index = $request->data['xml_configuration_file'] ) {
+ $files = \app\lib\Library::retrieve('xml_configuration_files');
+ $xml_config = $files[$xml_file_index - 1];
if ( !$xml_config || !$xml_config = realpath($xml_config) ) {
$notifications[] = array(
'type' => 'failed',
View
@@ -98,16 +98,20 @@
</select>
</li>
<li>
- <label for='use_xml' class='options-description'>
+ <label for='xml_configuration_file'>
<i class='icon-wrench'></i>
- Use XML Config
+ XML Configuration File
</label>
- <select id='use_xml' name='use_xml' class='test-options'>
- <option value='0'>No</option>
- <option value='1' <?php if ( $use_xml ) echo "selected='selected'"; ?>>Yes</option>
+ </li>
+ <li>
+ <select id='xml_configuration_file' name='xml_configuration_file'>
+ <option value='0' selected='selected'>None</option>
+ <?php foreach ( $xml_configuration_files as $index => $xml_configuration_file ): ?>
+ <option value='<?=($index + 1);?>'><?=$xml_configuration_file;?></option>
+ <?php endforeach; ?>
</select>
<p class='help-block'>
- Note that setting this to "Yes" will cause VPU to ignore the tests selected above and use the tests specified in the XML file instead.
+ Note that choosing an XML configuration file will cause VPU to ignore the tests selected above and use the tests specified in the XML file instead.
</p>
</li>
View
65 bin/vpu
@@ -2,17 +2,35 @@
<?php
require dirname(__DIR__) . '/app/config/bootstrap.php';
- $xml_config = \app\lib\Library::retrieve('xml_configuration_file');
+ $opts = array(
+ 'f:' => 'xml_configuration_file:',
+ 'd::' => 'snapshot_directory::',
+ 'e::' => 'sandbox_errors::',
+ 's::' => 'store_statistics::'
+ );
+ $options = getopt(implode(array_keys($opts)), array_values($opts));
+
+ if ( isset($options['f']) ) {
+ $xml_config = $options['f'];
+ } elseif ( isset($options['xml_configuration_file']) ) {
+ $xml_config = $options['xml_configuration_file'];
+ } else {
+ $xml_config = false;
+ }
if ( !$xml_config || !$xml_config = realpath($xml_config) ) {
die(
- "\nA valid xml_configuration_file must be specified in "
- . "app/config/bootstrap.php for VPU to work."
+ "A valid xml_configuration_file must be specified "
+ . "[-f|--xml_configuration_file] for VPU to work.\n"
);
}
$vpu = new \app\lib\VPU();
- $sandbox_errors = \app\lib\Library::retrieve('sandbox_errors');
+ if ( isset($options['e']) || isset($options['sandbox_errors']) ) {
+ $sandbox_errors = true;
+ } else {
+ $sandbox_errors = \app\lib\Library::retrieve('sandbox_errors');
+ }
if ( $sandbox_errors ) {
error_reporting(\app\lib\Library::retrieve('error_reporting'));
set_error_handler(array($vpu, 'handle_errors'));
@@ -30,16 +48,23 @@
$errors = $vpu->get_errors();
$to_view = compact('suites', 'stats', 'errors');
- $filename = realpath(
- \app\lib\Library::retrieve('snapshot_directory')
- ) . '/' . date('Y-m-d_H-i') . '.html';
+ if ( isset($options['d']) ) {
+ $filename = $options['d'];
+ $snapshot_error = '[-d]';
+ } elseif ( isset($options['snapshot_directory']) ) {
+ $filename = $options['snapshot_directory'];
+ $snapshot_error = '[--snapshot_directory]';
+ } else {
+ $filename = \app\lib\Library::retrieve('snapshot_directory');
+ $snapshot_error = 'the snapshot_directory in app/config/bootstrap.php';
+ }
+ $filename = realpath($filename) . '/' . date('Y-m-d_H-i') . '.html';
$handle = @fopen($filename, 'a');
if ( !$handle ) {
die(
- "\nThere was an error creating the snapshot. Please ensure that "
- . "the snapshot_directory in app/config/bootstrap.php exists and "
- . "has the proper permissions."
+ "There was an error creating the snapshot. Please ensure that "
+ . "{$snapshot_error} exists and has the proper permissions.\n"
);
}
@@ -49,9 +74,13 @@
fwrite($handle, $contents);
fclose($handle);
- echo "\nSnapshot successfully created at {$filename}.";
+ echo "Snapshot successfully created at {$filename}.\n";
- $store_statistics = \app\lib\Library::retrieve('store_statistics');
+ if ( isset($options['s']) || isset($options['store_statistics']) ) {
+ $store_statistics = true;
+ } else {
+ $store_statistics = \app\lib\Library::retrieve('store_statistics');
+ }
if ( !$store_statistics ) {
exit;
}
@@ -60,8 +89,8 @@
$db = new $db_options['plugin']();
if ( !$db->connect($db_options) ) {
die(
- "\nThere was an error connecting to the database:\n"
- . implode(' ', $db->get_errors())
+ "There was an error connecting to the database:\n"
+ . implode(' ', $db->get_errors()) . "\n"
);
}
@@ -77,12 +106,12 @@
$table = ucfirst(rtrim($key, 's')) . 'Result';
if ( !$db->insert($table, $data) ) {
die(
- "\nThere was an error inserting a record into the database:\n"
- . implode(' ', $db->get_errors())
+ "There was an error inserting a record into the database:\n"
+ . implode(' ', $db->get_errors()) . "\n"
);
}
}
- echo "\nThe statistics generated during this test run were successfully "
- . "stored.";
+ echo "The statistics generated during this test run were successfully "
+ . "stored.\n";
?>

0 comments on commit 79cab11

Please sign in to comment.