CodeView

PHPUnit test harness for Komodo

PrinterOptionSet.php

<?php
 
    /**
     * @author  Michael Heim
     * @link    http://www.zeilenwechsel.de/
     * @version 1.2.0
     * @license http://www.zeilenwechsel.de/it/code/browse/komodo-phpunit-harness/prod/license.txt
     */
 
    /**
     * Object representing multiple sets of switches for a test harness. A default
     * printer configuration is passed in, and all available combinations of switches
     * for that printer will be generated, along with filenames for output.
     */
    class PrinterOptionSet extends DebugOptionSet {
 
        /* @var PHPUnitXt_Base_PrinterOptions */
        protected $default_printer_options;
 
        /**
         * @param PHPUnitXt_Base_PrinterOptions $default_printer_options  an options object for the desired printer type, in
         *                                                                its default state. The concrete options and their
         *                                                                combinations will be set by the generator.
         */
        public function __construct( PHPUnitXt_Base_PrinterOptions $default_printer_options ) {
 
            $this->default_printer_options = $default_printer_options;
 
        }
 
        /**
         * Returns an array of argument strings covering all possible combinations of
         * printer options.
         *
         * @return array
         */
        protected function get_argstring_sets () {
 
            if ( is_null( $this->argstrings ) ) {
 
                $options = $this->default_printer_options->get_option_names( false );
                $this->argstrings = $this->get_combinations( $options );
 
            }
 
            return $this->argstrings;
 
        }
 
        /**
         * Returns an array of strings, representing all possible combinations of
         * printer options.
         * 
         * @param  array   $option_names     array of the option names
         * @return array
         */
        protected function get_combinations ( array $option_names ) {
 
            $current  = array_shift( $option_names );
            $opposite = $this->default_printer_options->get_opposite_option_name( $current );
 
            if ( count( $option_names ) > 0 ) {
 
                $combinations = $this->get_combinations( $option_names );
 
                foreach ( $combinations as $combination ) {
 
                    $new_set[] = trim( "--$current $combination" );
                    $new_set[] = trim( ( $opposite == '' ? $combination : "--$opposite $combination" ) );
 
                }
 
            } else {
 
                $new_set = array( "--$current", ( $opposite == '' ? '' : "--$opposite" ) );
 
            }
 
            return $new_set;
 
        }
 
        /**
         * Returns the default state of a printer option.
         * 
         * @param string $name
         * 
         */
        public function get_default_value ( $name ) {
 
            return $this->default_printer_options->get( $name );
 
        }
 
    }
 
?>