Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pulse00 opened this issue Oct 18, 2012 · 12 comments
Open

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

pulse00 opened this issue Oct 18, 2012 · 12 comments
Assignees

Comments

@pulse00
Copy link

pulse00 commented Oct 18, 2012

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:

  • Set PHPUnit as Testing Framework under General in the projects properties
  • Specify the XML Configuration file under the PHPUnit tab

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
Copy link
Member

iteman commented Oct 18, 2012

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
Copy link
Member

iteman commented Oct 18, 2012

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

@pulse00
Copy link
Author

pulse00 commented Oct 18, 2012

@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
Copy link
Member

iteman commented Oct 18, 2012

@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
Copy link
Author

pulse00 commented Oct 18, 2012

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
Copy link
Member

iteman commented Oct 18, 2012

@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
Copy link
Author

pulse00 commented Oct 18, 2012

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

@iteman
Copy link
Member

iteman commented Oct 18, 2012

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

@pulse00
Copy link
Author

pulse00 commented Oct 18, 2012

@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 <[email protected]>,
              2007 Masahiko Sakamoto <[email protected]>,
              2010 KUMAKURA Yousuke <[email protected]>,
              2011 Shigenobu Nishikawa <[email protected]>,
              2011 KUBO Noriko <[email protected]>,
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:

  • Testing Framework is set to PHPUnit
  • I've added TestFolders containing UnitTests
  • I've set the preload script to my bootstrap file
  • i've added the $_SERVER['KERNEL_DIR'] setting in my bootstrap script
  • I've added the path to the phpunit xml file under the PHPUnit tab

@iteman
Copy link
Member

iteman commented Oct 18, 2012

@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
Copy link
Author

pulse00 commented Oct 18, 2012

@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
Copy link
Member

iteman commented Oct 18, 2012

@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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants