views:

357

answers:

2

I'm used to web development using LAMP, PHP5, MySQL plus NetBeans with Xdebug.

Now I want to improve my development, by learning how to use (A) proper testing and (B) a framework. So I have set up CodeIgniter, SimpleTest and the easy Xdebug add-in for Firefox. This is great fun because maroonbytes provided me with clear instructions and a configured setup ready for download. I am standing on the shoulders of giants, and very grateful.

I've used SimpleTest a bit in the past. Here is a the kind of thing I wrote:

<?php
require_once('../simpletest/unit_tester.php');
require_once('../simpletest/reporter.php');

class TestOfMysqlTransaction extends UnitTestCase {
  function testDB_ViewTable() {
    $this->assertEqual(1,1);   // a pseudo-test
  }
}
$test = new TestOfMysqlTransaction();
$test->run(new HtmlReporter())
?>

So I hope I know what a test looks like. What I can't figure out is where and how to put a test in my new setup. I don't see any sample tests in the maroonbytes package, and Google so far has led me to posts that assume unit testing is already functionally available. What do I do?

+1  A: 

Edit:

If you are following the maroonbytes setup, just follow the instructions:

  1. Download the SimpleTest framework and extract the files into your @codeigniter directory.
  2. In both your main folder and your admin/application folder create a new folder called tests.
  3. Within the new tests folder setup additional folders called ‘models’, ‘views’, ‘controllers’, ‘libraries’ and ‘helpers’.

Any file ending in .php and with a UnitTestCase inside any of those folders, should be run. :)

Favio
Thanks Favio. I am giving this a bit more time. I'm on WAMP and the test GUI from maroonbytes is glitched up; tonight I'll be back on LAMP and I will try your answer. But also, your folder structure is different ... so being lazy, I am hoping a maroonbytes fan will post something.
Smandoli
Np. :) I've changed my answer, I was not sure I was on the right track with my previous one. HTH!
Favio
I have a .php file with content as described in the OP, and I've tried stashing it the various test subfolders. But I can't run the tests successfully through the 'CodeIgniter Application Test Suite' interface. I get 'Message: include_once(/var/www/sparts/main/tests/test_suite_3.php) [function.include-once]: failed to open stream'. That's all wrong, it should go to localhost and that path isn't right. Wish I knew what is going on.
Smandoli
Favio, could you provide a minimal/pseudo test? Then I could be sure it's not my file, for one thing.
Smandoli
Hmm, if you are getting that error, and your actual file is in a different path, then that's the hint you need to make this work. Perhaps some kind of configuration is missing. I would just try to debug the code and see where the path is being set, and why it is being set to a different path. Definitely, error_reporting(E_ALL) is your friend here. And your example test is fine; just don't think you'll need the SimpleTest requires as this is an automated setup.
Favio
+1 this answer, for your input and patience, thanks. O-KAY, turning on the debugger now ...
Smandoli
I now have something specific from the debugger; posted as a new question at http://stackoverflow.com/questions/3327832/simpletest-with-codeigniter-wont-identify-file
Smandoli
A: 

First, tests must be named properly. To test a controller welcome placed in the file welcome.php a test is named welcome_controller_test.php and stored under tests/controllers/. For more, see this post.

Second, Xdebug's GET argument interferes with the test routine. See post just above, also this post.

Third, the stub test I posted needed two four lines deleted:

//require_once('../simpletest/unit_tester.php');
//require_once('../simpletest/reporter.php');
...
//$test = new TestOfMysqlTransaction();
//$test->run(new HtmlReporter())

I am making tests fairly happily now. CodeIgniter lets me create/maintain tests easily, so my goal of TDD looks reachable. My earlier attempts at TDD gave me the idea, but scratch PHP was just too barren for me to be effective (and we won't discuss VBA!).

Smandoli