Git Product home page Git Product logo

craft.loath's Introduction

Loath

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.

Requirements

  • PHP 5.3.2 or above
  • Craft 1.3 Build 2507 or above

Setup

This is a developer targeted plugin so, I would recommend that you...

  1. Download or clone the repo git clone [email protected]:selvinortiz/craft.loath.git
  2. Place inside craft/plugins or symlink to craft/plugins/loath
  3. Run the test suite, study the code & comments, contribute.

Assumed Directory Structure

@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 PHPUnit

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.

Full Command

/path/to/php -c /path/to/php.ini @craftVendor/phpunit/phpunit/phpunit.php --bootstrap @craftTests/bootstrap.php --configuration @craftTests/phpunit.xml @pluginTestDir

Command Explained

These commands should be executed as a single command with exactly one space between each step.

Invoke the PHP executable and pass along our php.ini

php -c /etc/php5/apache2/php.ini

Run PHPUnit through PHP

/path/to/site/craft/vendor/phpunit/phpunit/phpunit.php or which phpunit

Tell PHPUnit what bootstrap file to use

--bootstrap /path/to/site/craft/app/tests/bootstrap.php

Tell PHPUnit to use the configuration file provided by Craft

--configuration /path/to/site/craft/app/tests/phpunit.xml

Finally, tell PHPUnit where to find your plugin test directory

/path/to/site/craft/plugins/yourplugin/tests

Bundled Command

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

Issues

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.

Changelog

1.1.0

  • 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

1.0.0

  • Initial release

Feedback & Support

If you have any feedback or questions, please reach out to me on twitter @selvinortiz

License & Credits

Loath is open source software licensed under the MIT license

Open Source Initiative

craft.loath's People

Contributors

selvinortiz avatar

Watchers

James Cloos avatar Webremote avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.