Reputation: 19805
Anyone using CodeIgniter use automated unit testing?
Seems the way CodeIgniter's guy do unit test need to have a controller which run in browser,
e.g.
However, I only want to test from command line, I want automated test and build.
Any recommendation?
Thanks.
Upvotes: 9
Views: 20344
Reputation: 453
Here's what I do:
require_once
the bootstrap.php file in my tests.prove
on tests in the t directorybootstrap.php
:
<?php
// Initialize CodeIgniter, suppressing output.
ob_start();
require_once __DIR__ . '/../index.php';
ob_end_clean();
require_once __DIR__ . '/Test.php';
An example of a test:
t/000-sanity.t
:
#!/usr/bin/env php
<?php
require_once 'bootstrap.php';
plan(1);
is(true, true, 'Test.php works');
All CodeIgniter stuff is available. For example, you can do $ci =& get_instance();
This setup works great in CI 1.7.x and 2.x. Test.php is really easy to use, as well.
Upvotes: 3
Reputation: 1197
You can use this integration with phpunit - http://www.foostack.com/foostack/
It would then run from the command line.
Upvotes: 4