Crafted with hatred by Selvin Ortiz for Craft CMS
Loath is a sample plugin designed to illustrate unit testing in Craft
Its goal is to help you get started with unit testing and write testable code.
- PHP 5.3.2 or above
- Craft 1.3 Build 2507 or above
This is a developer targeted plugin so, I would recommend that you...
- Download or clone the repo
git clone git@github.com:selvinortiz/craft.loath.git
- Place inside
craft/plugins
or symlink tocraft/plugins/loath
- Run the test suite, study the code & comments, contribute.
@craft = /path/to/site/craft
@craftTests = @craft/app/tests
@craftVendor = @craft/app/vendor
@pluginTestDir = @craft/plugins/loath/tests
/path/to/site/craft
- /app
- /tests
- /vendor
- /plugins
- loath
- tests
Running plugin tests via phpunit within craft can be tricky but hopefully this will get you started in the right direction.
Here is the example command that should work in most cases.
/path/to/php -c /path/to/php.ini @craftVendor/phpunit/phpunit/phpunit.php --bootstrap @craftTests/bootstrap.php --configuration @craftTests/phpunit.xml @pluginTestDir
These commands should be executed as a single command with exactly one space between each step.
php -c /etc/php5/apache2/php.ini
/path/to/site/craft/vendor/phpunit/phpunit/phpunit.php
or which phpunit
--bootstrap /path/to/site/craft/app/tests/bootstrap.php
--configuration /path/to/site/craft/app/tests/phpunit.xml
/path/to/site/craft/plugins/yourplugin/tests
This repo includes a shell script that you can edit with your paths and run it.
The loath/tests/run.sh
file should be executable +x
and the paths should be update, once you've address that you can simply...
- cd into
craft/plugins/loath/tests
- run
./run.sh
The biggest issues I've come across during testing have to do with bootstrapping dependencies.
Some issues are really hard to diagnose and explain and in effort to keep this short... I figured that rather than explaining every single issue I've found, I'd just post what is currently working for me and other's I've helped and if you can't get things running just post a comment here and we can sort it out together.
- Added the
models/LoathModel
- Fixed a path issue in the bundled
run.sh
- Improved the way dependencies are loaded
- Improved the way static method dependencies are handled
- Initial release
If you have any feedback or questions, please reach out to me on twitter @selvinortiz
Loath is open source software licensed under the MIT license