Bootstrap file with PHPUnit Tests

Anyone know why the PHPUnit test boot strap file that I attach to a unit test configuration is not working anyone else have this issue.
When I right click a file in my project in order to have PHPStorm generate a PHPUnit Test file I have the option of also selecting a bottstrap file. But when I do this and then run the test the bootstrap file is not loaded. Anyone know how to do this?
Any help is much appreciated.

10 comments
Comment actions Permalink

I've never figured out what the bootstrap file that is indicated during generation of the test file is for. I'd like to know.

To use a bootstrap.php file, you need to configure a phpunit.xml file and point to that in the RUN configuration, as such:

config1.JPG

Here is the contents of the phpunit.xml file:

<?xml version="1.0"?>
<!-- see http://www.phpunit.de/wiki/Documentation -->
<phpunit bootstrap="./bootstrap.php"
         colors="false"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         stopOnFailure="true">
</phpunit>

0
Comment actions Permalink

Thanks. Yeah this is what I have been doing, but I was curious why it wasnt working. Thanks for the response.
Dear PHPStorm developers can we get a bit more clarification on the use of this parameter in the next release?

0
Comment actions Permalink

Keith,

Thanks for sharing!

I've never figured out what the bootstrap file that is indicated during generation of the test file is for. I'd like to know.

Related discussion - http://youtrack.jetbrains.net/issue/WI-6763. Probably we should replace path to bootstrap with path to phpunit configuration file (see http://youtrack.jetbrains.net/issue/WI-7622)

Thank you for feedback!

0
Comment actions Permalink

Hello Edgar,

When I right click a file in my project in order to have PHPStorm generate a PHPUnit Test file I have the option of also selecting a bottstrap file. But when I do this and then run the test the bootstrap file is not loaded. Anyone know how to do this?

Unfortunately it is a kind of inconsistency in our configuration - you can set path to bootstrap file in 'Generate PHPUnit Test' dialog, but path to configuration file in 'PHPUnit run configuration'.
We have an issue about bootstrap option for PHPUnit run configuration - http://youtrack.jetbrains.net/issue/WI-6730
And an issue about path to xml configuration file for 'Generate PHPUnit Test' action - http://youtrack.jetbrains.net/issue/WI-7622

Please vote and feel free to share you ideas in issues comments.

Thank you for feedback!

0
Comment actions Permalink

Edgar,

Dear PHPStorm developers can we get a bit more clarification on the use of this parameter in the next release?

Yes, we are constantly working on usability problems.
Please submit a new issue if you have some specific idea about the problem described before - http://youtrack.jetbrains.net/issues/WI#newissue=yes

Thank you for feedback!

0
Comment actions Permalink

Thanks for the reply. Nothing personal. I still love PHPStorm it is an awesome IDE and I cannot wait for version 3.0

0
Comment actions Permalink

OK I totaly know what this is for now. Hah I just realized and it is so important.

The bootstrap file information in the UnitTest genrating is so that PHPStorm knows what information it needs in order to generate and properly create the UnitTest PHP code

bootstrap.PNG

It seems so obvious now.
This is just like "MetaData" in the generation process not in the actual Unit Test.
This si just to make sure the dependencies are considered in creating the Unit Test but doesnt mean it will run withthe unit test

in order to do that you need tos pecify the PHPUnit.xml file in the test configurations



Maybe PHPStorm can just make it a bit clearer anyways I hope I will get a chance to creata tutorial ont hsi this weekend because it would be very helpfull


If anyone else has any questions regarding this feeel free to contact me it is now clear.  Cheers


In other words you have to specify the bootstrap twice. Once when you generate the UnitTest code and once for running the unit test
the second time it has to be specified inside the phpunit.xml file

phpunit.PNG

it will only be included if you specify it in the phpunit.xml file and if you tell phpstorm when this file is included
I really need to record a video tutorial on this.

Again feel free to contatct me. I happy to help

0
Comment actions Permalink

I actually would have guessed that is what it is for...however, we don't use it...and I wouldn't even know how to use it, to be honest. What format would that file be in and such?

0
Comment actions Permalink

the boot strap is just a regular php file inwhich you initiate your environemnt. In it you include all the basic stuff like start a session add all your included files and such. If you use MVC frameworks you need thi bootstrp file because it initiates the application for you. Frankly I hired a guy that is better at it then me. I am still learning Unit Testing but I already. Also if you use a Database connection or some sort of CONSTANTS in your application then the bootstrap is where you declare them. Whats great about a bootstrap is you can reshare it across several Unite Test Suites which saves you the trouble of having to add tedious configurations in the setUp() function in the test.

Unit tests are time consuming but you will sleep a lot easier at night knowing everything you wrote is solid and ready to deploy.

0
Comment actions Permalink

We do use a bootstrap file to actually run our application, and I just load our bootstrap file when I load the PHPUnit bootstrap file, which always loads before I run the test. That way it simulates the actual environment we use. I suppose this is just another way.

0

Please sign in to leave a comment.