PHPackages                             kohana/koharness - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. kohana/koharness

AbandonedArchivedLibrary[Testing &amp; Quality](/categories/testing)

kohana/koharness
================

Creates test harnesses for kohana modules by bootstrapping a temporary kohana application with dependencies

v0.1.1(11y ago)520.2k519BSD-3-ClausePHPPHP &gt;=5.3.3

Since Aug 1Pushed 11mo ago7 watchersCompare

[ Source](https://github.com/kohana/koharness)[ Packagist](https://packagist.org/packages/kohana/koharness)[ Docs](http://kohanaframework.org)[ RSS](/packages/kohana-koharness/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (19)

koharness - bootstrap a clean Kohana app for testing your modules
=================================================================

[](#koharness---bootstrap-a-clean-kohana-app-for-testing-your-modules)

[![Build Status](https://camo.githubusercontent.com/6994a2363063dbf939940b3331c7f224f7ca1b1587d6bef070ee2b8e4fc2d921/68747470733a2f2f7472617669732d63692e6f72672f6b6f68616e612f6b6f6861726e6573732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kohana/koharness)

koharness is a very simple package (read, hack) that provides a clean testing environment for your Kohana modules. It can generate a basic Kohana application containing your module and any dependencies, which you can then use to run tests with your favourite tools.

koharness gives you full control of module loading order, which may be vital for modules that are designed to extend others using the Cascading File System.

Installing koharness in your module
-----------------------------------

[](#installing-koharness-in-your-module)

Add it as a development dependency in your module's composer.json:

```
{
	"require-dev": {
		"kohana/koharness" : "*@dev"
	}
}
```

Run `composer install` in your module's root directory.

Configuring module dependencies
-------------------------------

[](#configuring-module-dependencies)

Your module will almost certainly require the kohana core (if it doesn't you can probably test it in isolation without koharness or any other bootstrapper - which is obviously good).

If you want to use phpunit, you'll probably also want the Kohana unittest module.

Add them (and anything else you need) to your composer.json too. For extra cleanliness, force composer-installers to install kohana modules into the normal vendor path instead of into /modules (note, this won't affect end-users of your module).

```
{
	"require": {
		"kohana/core":     "3.3.*",
	},
	"require-dev": {
		"kohana/unittest": "3.3.*",
		"kohana/koharness" : "*@dev"
	},
	"extra": {
		"installer-paths": {
		"vendor/{$vendor}/{$name}": ["type:kohana-module"]
	}
  }
}
```

This will get all the dependencies installed on your machine, but you need to tell koharness how to bootstrap them for your test environment and the order that they should be loaded by Kohana::modules().

Add a `koharness.php` file in the repository root:

```
// {my-module-root}/koharness.php
return array(
	// This list of paths will also be passed to Kohana::modules(). Define the modules (including your own)
	// in the order you want them to appear in Kohana::modules()
	'modules' => array(
		'my-module' => __DIR__,
		'unittest'  => __DIR__.'/vendor/kohana/unittest'
	),

	// You can specify where to create the harness application - the default is /tmp/koharness
	'temp_dir' => '/home/me/testing'
);
```

Building your harness
---------------------

[](#building-your-harness)

Now you have your module in a directory with all its dependencies inside it - so it needs to be turned "inside out" to be more like a standard app with your module as a dependency. Here's where koharness does it's thing.

In your module root directory, just run `vendor/bin/koharness` (presuming you're using composer's default `bin-dir` setting). This will **wipe out your specified temp\_dir** and build a structure of symlinks and files that looks like this:

```
$temp_dir
\---application
|   \---cache
|   \---logs
|   |   bootstrap.php
|
\---modules
|   \---my-module -> WORKING_DIR
|   \---unittest  -> WORKING_DIR/vendor/kohana/unittest
|
\---system -> WORKING_DIR/vendor/kohana/core
\---vendor -> WORKING_DIR/vendor

```

The bootstrap.php is generated from a standard Kohana 3.3 template that ships with koharness, with your modules included.

Running tests
-------------

[](#running-tests)

Once you have built your harness, you can run tests using whatever tool you prefer.

### PHPUnit with the kohana unittest module

[](#phpunit-with-the-kohana-unittest-module)

Easy peasy:

```
cd /tmp/koharness
vendor/bin/phpunit --bootstrap=modules/unittest/bootstrap.php modules/unittest/tests.php
```

### Other tools

[](#other-tools)

If you want to load your kohana environment in phpspec, behat or similar then you'll also find your module working directory contains a `koharness_bootstrap.php` that defines the various path constants that you'd normally get from index.php or the unittest module runner.

In phpspec for example, you could just do something like this:

```
// MODULE_ROOT/spec/ObjectBehavior.php
