CodeView
Back to article:
prod
tests
integration
reference-output
Ko
resources
test-clones
xml
custom-file
default-file
dist-file
special
tools
Base
Ko
unit
<?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 */ require_once( 'PHPUnit/Runner/Version.php' ); require_once( dirname( __FILE__ ) . '/tools/bootstrap.php' ); require_once( HARNESS_LOADER ); PHPUnitXt_Utils_Loader::load( 'PHPUnitXt_Ko_PrinterOptions' ); class KoHarnessTest extends PHPUnit_Framework_TestCase { /* @var string the full path to Komodo's drive_testrunner.php */ protected $testrunner_path; /* @var KoDebugRun */ protected $dummy_setup; /* @var PHPUnitXt_Ko_PrinterOptions */ protected $default_printer_options; /* @var boolean true if PHPUnit < 3.5 is used */ protected $is_legacy_phpunit; /* @var boolean true if --force-new-harness is on by default. Relevant for testing PHPUnit < 3.5. */ protected $force_new_harness_by_default; /** * @dataProvider provideArgsAndReference */ public function testRunnerOutput ( $args, $dummy_test, $reference_file ) { // Get runner output $this->dummy_setup->create_harness_environment( $dummy_test, $args ); ob_start(); require( $this->testrunner_path ); $output = ob_get_clean(); $output = DebugOutputTools::normalize_output( $output ); /* Special case PHPUnit < 3.5: The harness under test runs only if the --force-new-harness switch is set, either by default or explicitly. If this is not the case and the legacy testrunner executes, different content should be returned (no content at all, normally, or error messages emitted by a buggy testrunner). */ $force_new_harness = ( $this->force_new_harness_by_default or in_array( '--force-new-harness', $args ) ); $using_legacy_runner = ( $this->is_legacy_phpunit and ! $force_new_harness ); // Compare if ( $using_legacy_runner ) { $this->assertStringNotEqualsFile( $reference_file, $output ); } else { $this->assertStringEqualsFile( $reference_file, $output ); } } public function provideArgsAndReference () { $this->create_fixture(); $reference_output_dir = KO_REFERENCE_OUTPUT_DIR; /* * I. Testing printer options */ $option_set = new PrinterOptionSet( $this->default_printer_options ); $option_set->prepend_path_to_filenames( $reference_output_dir ); $dummy_test_path = INTEGRATION_TEST_RESOURCE_DIR . '/DummyClassTst.php'; $test_configurations = $option_set->get_test_configurations(); foreach ( $test_configurations as $configuration ) { $provider[] = array( $configuration[ 'args' ], $dummy_test_path, $configuration[ 'output_file' ] ); } /* * II. Testing XML configurations */ $debug_factory = new DebugFactory( 'Ko' ); foreach( BulkOutputGenerator::get_xml_config_dirs() as $xml_config_dir ) { $option_set = $debug_factory->create_xml_switches_from_dirpath( $xml_config_dir ); $option_set->prepend_path_to_filenames( $reference_output_dir ); $test_configurations = $option_set->get_test_configurations(); foreach ( $test_configurations as $configuration ) { $provider[] = array( $configuration[ 'args' ], $xml_config_dir, $configuration[ 'output_file' ] ); } } return $provider; } public function setUp () { putenv( 'PHPUNIT_COMMAND_NOEXIT=true' ); $this->create_fixture(); $testrunner = 'drive_testrunner.php'; $this->testrunner_path = PHPUnitXt_Utils_Loader::root() . "/$testrunner"; $this->dummy_setup = new KoDebugRun(); $this->dummy_setup->set_testrunner( $testrunner ); $this->force_new_harness_by_default = ( $this->default_printer_options->get( 'force-new-harness' ) == true ); $this->is_legacy_phpunit = version_compare( PHPUnit_Runner_Version::id(), '3.5.0', '<' ); } public function create_fixture () { // Objects used by a provider must be available before setup is called, // hence a separate method. $this->default_printer_options = new PHPUnitXt_Ko_PrinterOptions(); } } ?>