piece / makegood

A continuous test runner for Eclipse PDT
https://github.com/piece/makegood/wiki
44 stars 17 forks source link

Getting "unrecognized option --no-ansi" from phpunit #44

Open samuell opened 11 years ago

samuell commented 11 years ago

I'm trying to debug my MediaWiki extension, by requiring the MediaWiki testcases.

After getting everything seemingly set up correct

(I do this:

global $IP;
$IP = __DIR__ . '/../../../../../';
define( 'MEDIAWIKI', true );

# Get MWInit class
require_once( "$IP/includes/Init.php" );

# Start the autoloader, so that extensions can derive classes from core files
require_once( "$IP/includes/AutoLoader.php" );

# Load the profiler
require_once( "$IP/includes/profiler/Profiler.php" );

# Load up some global defines.
require_once( "$IP/includes/Defines.php" );

# Some more stuff
#require_once( "$IP/includes/WebStart.php" );
require_once( "$IP/includes/GlobalFunctions.php" );
require_once( "$IP/tests/phpunit/MediaWikiPHPUnitCommand.php" );
require_once( "$IP/tests/phpunit/phpunit.php" );

class RDFImportTest extends MediaWikiTestCase {

    function setUp() {}
    function tearDown() {}

    /**
     * Simple test to see that the PHPUnit test framework
     * (And the MakeGood Eclipse plugin) is correctly set up.
     */
    public function testPhpUnitSetup() {
        $this->assertTrue(true);
    }

}

... I still get this error:

#!/usr/bin/env php
PHPUnit 3.6.10 by Sebastian Bergmann.

unrecognized option --no-ansi

I have grepped through the MediaWiki tests code with:

grep -inr "no-ansi" *

... and have found no reference. OTOH, I found this string in the sources for the MakeGood plugin, in my eclipse plugins folder, so I'm suspecting that that is where this flag is set.

I'm running:

matsu-hide8 commented 11 years ago

This error is raised by using the phpunit.php of the MediaWiki. Before the MakeGood runs tests, the execution of PHP is terminated by the MediaWiki.

Please change the code not to use it. (And require the MediaWikiTestCase.php.)

Ciantic commented 10 years ago

I'm getting this error as well. PHPUnit 3.7.28. Is MakeGood using an option that is not recognized anymore?

P.S. I have project which has nothing to do with MediaWiki, I suspect the makegood tries to pass some command line args for phpunit with no reason, no-ansi option has never been in PHPUnit.

Ciantic commented 10 years ago

The problem is in testrunner.php I suspect, I sniffed the command line from the Process Explorer in Windows:

php.exe -c ...\php.ini -d asp_tags=off -d short_open_tag=off \..makegood...\testrunner.php" --no-ansi phpunit --log-junit=....xml --log-junit-realtime --phpunit-config=...

It's not setting --no-ansi to phpunit, but to testrunner.php?

Ciantic commented 10 years ago

Yes, this HACK fixes the problem:

  1. Open the \plugins\com.piece_framework.makegood.stagehandtestrunner_2.5.0.v201311031709\resources\php\bin\testrunner.php
  2. Insert these two lines after the namespace definition:

    array_splice($argv, 1, 1);
    array_splice($_SERVER['argv'], 1, 1);

These lines removes the --no-ansi from the command line arguments, you can check this by var_dump($_SERVER['argv']); exit; when the version changes.

WesWedding commented 10 years ago

Without delving into what MakeGood is doing with --no-ansi, the reason Wordpress in particular can't use MakeGood without a hacky solution (I modified PHPUnit directly so that it ignored unrecognized command line options) is that the Wordpress-tests booststrap.php passes the entire command line to PHPUnit_Util_Getopt::getopt, probably under the assumption that PHPunit is being run directly. The Wordpress-tests boostrap.php is required to run tests in a Wordpress environment.

So, I guess the question is: Is this a Wordpress problem or a MakeGood problem?

WesWedding commented 10 years ago

I submitted a bug/patch to Wordpress (http://core.trac.wordpress.org/ticket/26725). The problem Ciantic and I had is really because Wordpress does funky things when it bootstraps its test environment, and not really MakeGood's fault.

iteman commented 10 years ago

Thank you @stickywes.

MakeGood uses own testrunner command instead of the phpunit command to launch a test run. The testrunner command has own command line arguments and options. So PHPUnit cannot recognize our command line.

TRPB commented 10 years ago

I'm not using wordpress but have the same issue. Unfortunately, if I try the array_splice hack above I get the error:

!/usr/bin/env php

PHPUnit 3.7.32 by Sebastian Bergmann.

Cannot open file "--log-junit=/tmp/com.piece_framework.makegood.launch/MakeGood1398899990790.xml".

Clearly the file name should not have the --log-junit= prefix. The phpunit documentation ( http://phpunit.de/manual/3.7/en/textui.html ) suggests it should be --log-junit not, --log-junit= but removing the equals sign makes no difference and test still cannot be run. I've been struggling for quite some time to get MakeGood working and nothing I do seems to help.

iteman commented 10 years ago

@TomBZombie An error "unrecognized option --no-ansi" will be raised only if PHPUnit_TextUI_Command::handleArguments() is called in the test run. Since MakeGood never use PHPUnit_TextUI_Command as the command line parser for PHPUnit, I think that PHPUnit_TextUI_Command::handleArguments() would be called by your test environment.

abrarkhan1234 commented 9 years ago

Getting the same issue for Eclipse Luna, unable to find the code for the plugin which @Ciantic has suggested needs to be tweaked. Can you advise how I can find it?