piece / makegood

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

PHPUnit bootstrap file loaded multiple times causing a fatal error #14

Open pulse00 opened 12 years ago

pulse00 commented 12 years ago

I'm trying to setup MakeGood with a Symfony2 project which uses phpunit with an xml configuration file.

The projects tests work fine when run from the cli manually. When i configure the project in makegood, i'm doing the following:

When running a test, i'm getting

Fatal error: Cannot redeclare class Symfony\Component\DependencyInjection\ContainerInterface  bootstrap.php.cache

bootstrap.php.cache is the bootstrap file specified in phpunits xml config file. It looks like MakeGood is loading that bootstrap file twice somehow.

Am i missing something here?

iteman commented 12 years ago

MakeGood has provided the required PHP components for MakeGood itself as the com.piece_framework.makegood.stagehandtestrunner plugin. The path to the components is automatically added to the include_path when running a test. The most of the components will be loaded immediately after launching MakeGood's launcher command testrunner.php.

To avoid raising the error, specify the bootstrap.php.cache (or another script that loads the bootstrap.php.cache) as the preload script for your project.

iteman commented 12 years ago

Additionally, you should also define the $_SERVER['KERNEL_DIR'] in your preload script.

pulse00 commented 12 years ago

@iteman thanks for the hint,

Why is there a special tab for the XML Configuration File of PHPUnit? In which use case would i set this?

Also i'm a step further now. When i run tests, i'm getting PDOException: Could not find driver. It seems makeGood uses a different PHP executable than the one i've defined in the PHP preferences of PDT.

How does MakeGood determine the php executable to use?

iteman commented 12 years ago

@pulse00 Hi,

Why is there a special tab for the XML Configuration File of PHPUnit? In which use case would i set this?

MakeGood works with most elements of the PHPUnit XML configuration file. Especially the <groups> element will help you to run tests only for continuous testing. (e.g. excluding tests with database)

How does MakeGood determine the php executable to use?

Take a look at the following code:

com.piece_framework.makegood.launch.PHPexeItemRepository:

public class PHPexeItemRepository {
    public PHPexeItem findByProject(IProject project) {
        PHPexeItem phpexeItem = PHPDebugPlugin.getPHPexeItem(project);
        if (phpexeItem == null) {
            return PHPDebugPlugin.getWorkspaceDefaultExe();
        }
        return phpexeItem;
    }
}
pulse00 commented 12 years ago

thanks for the clarification. I think i've found what's causing the PDOException: Could not find driver.

I have defined the my php.ini in the workspaces default PHP Executable item: /opt/local/etc/php54/php.ini. However, on OSX / macports php loads all extensions via additional .ini files, e.g.:

 php --ini
Configuration File (php.ini) Path: /opt/local/etc/php54
Loaded Configuration File:         /opt/local/etc/php54/php.ini
Scan for additional .ini files in: /opt/local/var/db/php54
Additional .ini files parsed:      /opt/local/var/db/php54/APC.ini,
/opt/local/var/db/php54/bbcode.ini,
/opt/local/var/db/php54/curl.ini,
/opt/local/var/db/php54/gd.ini,
/opt/local/var/db/php54/iconv.ini,
/opt/local/var/db/php54/mbstring.ini,
/opt/local/var/db/php54/memcache.ini,
/opt/local/var/db/php54/memcached.ini,
/opt/local/var/db/php54/mysql.ini,
/opt/local/var/db/php54/oauth.ini,
/opt/local/var/db/php54/openssl.ini,
/opt/local/var/db/php54/pcntl.ini,
/opt/local/var/db/php54/posix.ini,
/opt/local/var/db/php54/redis.ini,
/opt/local/var/db/php54/sqlite.ini,
/opt/local/var/db/php54/uploadprogress.ini,
/opt/local/var/db/php54/xdebug.ini

Could there be some problem with the launcher not loading the additional ini files?

iteman commented 12 years ago

@pulse00 Hi,

Could there be some problem with the launcher not loading the additional ini files?

This is a FAQ for PDT (and also MakeGood).

The Eclipse PDT team decided to introduce the -n option to fix the Bug #324073. So only php.ini from /tmp/zend_debug/... has been loaded, and all additional INI files have not been loaded.

This has been introduced since PDT 2.2.0 M201010110334 (2010/10/11).

For more information, see the following links:

pulse00 commented 12 years ago

@iteman sorry for missing that point in the FAQ. i wasn't aware of that issue regarding additional ini files.

iteman commented 12 years ago

@pulse00 We would be happy If there is a better way to fix the bug :-)

pulse00 commented 12 years ago

@iteman i've now setup the executable so all additional ini files are parsed properly. When i run the tests, the Stagehand_TestRunner is executed but with no argument it seems. The console has the following output when running tests:

Stagehand_TestRunner version 3.2.0

Copyright (c) 2005-2012 KUBO Atsuhiro <kubo@iteman.jp>,
              2007 Masahiko Sakamoto <msakamoto-sf@users.sourceforge.net>,
              2010 KUMAKURA Yousuke <kumatch@gmail.com>,
              2011 Shigenobu Nishikawa <shishi.s.n@gmail.com>,
              2011 KUBO Noriko <noricott@gmail.com>,
All rights reserved.

Usage:
  [options] command [arguments]

Options:
  --help           -h Prints help and exit.
  --version        -V Prints version information and exit.
  --ansi              Enables ANSI output.
  --no-ansi           Disables ANSI output.

Testing Framework Commands:
  cakephp      Runs tests with CakePHP.
  ciunit       Runs tests with CIUnit.
  phpspec      Runs tests with PHPSpec.
  phpunit      Runs tests with PHPUnit.
  simpletest   Runs tests with SimpleTest.
Other Commands:
  compile      Compiles the DIC for the production environment.
  help         Prints the help for a command.
  list         Lists commands.

My project has now the following setup:

iteman commented 12 years ago

@pulse00 This is another FAQ for MakeGood, but no documents yet.

Unfortunately, I don't know why this issue happens. I've thought that the command line is broken by any reason. Try to restart Eclipse.

pulse00 commented 12 years ago

@iteman restarting eclipse with --clean solved that problem, the tests are executed now.

I'm sorry to bug you so much, but now the tests fail because the Symfony WebTestCase throws RuntimeException, because not enough arguments have been passed to the cli:

https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php#L62

Normally, you run Symfony phpunit tests with the -c option to the app dir where the phpunit.xml is located:

phpunit -c app

The Symfony tests assume that this argument is being passed to phpunit, if not, it throws that exception above.

It would really cool to get Symfony phpunit test working, i'd be adding a corresponding wiki entry if i get it running ;)

iteman commented 12 years ago

@pulse00 I apologize for the inconvenience.

It seems that the error is raised when the $_SERVER['KERNEL_DIR'] is not set:

https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php#L119

It would really cool to get Symfony phpunit test working, i'd be adding a corresponding wiki entry if i get it running ;)

Symfony guys would be happy to read such wiki entry :-)