0

Is there a way to automatically load a Listener (or phpunit configuration file for that matter), without using no more than:

phpunit testdir

? Today I'm using:

phpunit -c phpunit.xml --bootstrap bootstrap.php testdir

and want to exclude all switches. I know that I could have a phpunit.xml file in every directory, but thats not an option..

Thanks in advance!

englund
  • 160
  • 8

2 Answers2

2

PHPUnit by itself should look in the current directory for a phpunit.xml file. So your first and second example should both find and include the same phpunit.xml.

Mike B
  • 31,886
  • 13
  • 87
  • 111
  • Yes, but as I wrote, I would prefer not to have the same phpunit.xml everywhere. – englund Mar 28 '12 at 15:34
  • Why would you need it everywhere? How are your test-cases organized? – Mike B Mar 28 '12 at 15:47
  • Well, my test-cases are in subdirectories. I'm not always in the root-dir, so if I want to be in a specific dir and do a test(s), I would need a phpunit.xml to be in that dir. – englund Mar 28 '12 at 16:05
  • Normally, tests are run from the same directory regardless of scope. You can run the entire suit with `phpunit`. Or just one directory or file with `phpunit path/to/tests`. But the current directory stays the same to take advantage of the single phpunit.xml file. This xml file can be duplicated and tweaked depending on the behavior you want to include. For example, the base phpunit.xml file sets up the bare-minimum requirements for the tests to run. If we wanted to include code-coverage or other listeners we duplicate it into phpunit-coverage.xml and use the -c switch to select it. – Mike B Mar 28 '12 at 16:08
  • Exactly! But as I said, I'm not always in the root dir (where the configuration file is) doing my testing. – englund Mar 28 '12 at 16:11
  • Don't mean to sound glib, but is there a reason you're not always in the root dir? I couldn't find any reasoning behind it in your question or comments. – Mike B Mar 28 '12 at 16:13
  • Yes, lazy people (I'm far from alone working on this project). It would be much easier to just use this single configuration file and run the test from the root dir. But why do something that is easy? :) – englund Mar 28 '12 at 16:18
1

Use a Makefile:

unittest:
    phpunit -c phpunit.xml --bootstrap bootstrap.php testdir

And simply call it with make unittest

Now you can add more for different cases, in the same pattern.

dan-lee
  • 14,365
  • 5
  • 52
  • 77
  • But what if I want to run a different directory or a specific file? I don't want to write static code in for example a Makefile. – englund Mar 28 '12 at 15:39
  • No problem, you can pass arguments to your Makefile. Have a look here: [Passing additional variables from command line to make](http://stackoverflow.com/a/2826178/612202) – dan-lee Mar 28 '12 at 16:56