How does phpunit command make search class testing?
I use windows. For example I have some website with a structure smth like this:
site/
engine/
ModelClass.php
www/
index.php
tests/
开发者_如何学Python ModelCalssTest.php
phpunit.bat
Where should be store phpunit.bat to run test ModelClassTest.php?
You should not need to store a phpunit.bat
at all. It should be in your PATH
.
Just install it via PEAR and be done. If you don't want to do that and you have it locally on the system or your WANT the phpunit sources in your version control (some people want that) it doesn't matter where your phpunit.bat is really. Project root is fine, somewhere in vendor/phpunit/phpunit.bat
is fine too if you have an ant or phing or .bat file in your project root that lets you say "run tests now"
.
What i currently observe as "best-practice" is to put your phpunit.xml.dist
(the config file) in your application root so that people can just:
- get the source
- type
phpunit
- see that everything works
See: a sample project made by the phpunit author
What I've also seen is that people put that config file in their "tests" folder to have a "clean project root". Also works out nicely.
References: Documentation on the phpunit xml file
I usually have phpunit
executable in my PATH and keep a structured directory for tests similar to yours. Then you should configure your phpunit using the xml file in which you can include common options and most important a bootstrap file which contains the one time setup needed for your tests. if you put the xml file in the tests folder you can have a structure like this
tests
├── bootstrap.php
├── TestEnvironment.php
├── application
│ ├── controllers
│ │ └── IndexControllerTest.php
│ ├── forms
│ │ └── UserTest.php
│ ├── helpers
│ │ └── Html2TxtTest.php
│ └── modules
│ └── admin
│ └── models
│ ├── LayoutManagerTest.php
│ ├── ScriptOptionsTest.php
│ ├── ServiceTest.php
│ ├── TemplatesTest.php
│ └── UsersFinderTest.php
└── phpunit.xml
and run tests as you wish with commands like
phpunit # run all tests
phpunit application # run all tests inside application folders
phpunit application/forms/UserTest.php # run all tests inside the given file
So, as far as you have phpunit in the PATH there's no problem in running it, if you can't have it in your PATH, consider put it in the tests folder and run it from there.
This works well in Unix environments, but it should work also on Win32.
精彩评论