4

I tried using Testee as my test framework but found that SimpleTest but the latest release of SimpleTest was in 2010 so I'm presuming that it is no longer supported which is probably why Stephen Lewis hasn't updated Testee for 10 months.

Basically, I can't get this working and because it is unsupported I guess that it would be better to find out what other folks are doing.

I was thinking of Forking the Codeigniter tests and extending them in some way. Is this what others are doing?

3

I'm using PHPUnit, which is by far more popular in PHP-land. The full ins and outs of getting it set up are probably beyond a stack exchange answer, but assuming there are a couple things which should put you in the right direction.

Testing with EE and CI in general is always an uphill battle, since they weren't really designed with testing in mind, and there are no set standards of how to do things.

Use Mockery to stub out all the core EE classes, and set expectations that they are called. Try to avoid loading the core EE framework altogether, just use mock objects.

In my test bootstrap I wrote a ee() helper method which returns the global mocked EE instance, which you can use to set expectations on.

Database access is a bit more tricky - best bet is probably to create a test database, and then manually load the CI DB components and hook them up to the test database. Using expectations with database driven methods doesn't work very well in my experience.

4
  • That's interesting and good to know how you are approaching it. There is a lot of mocking to be done! Plus I've noticed a lot of static classes which makes mocking harder. Thanks for your reply – dorothy Dorothy Jun 20 '13 at 20:08
  • Actually EE isn't too bad with static classes, most libraries create a single instance and hang off the $EE object, which you can think of as a dependency/service container. The main trick is just to write your own get_instance() or ee() method to return a mock $EE, so you can run your tests without the rest of the framework being loaded. – Adrian Macneil Jun 20 '13 at 22:45
  • Also, be prepared to get your hands dirty :) Very few people are doing unit testing with EE so there is pretty much no information or established practices out there. Usually it's best to just dig into the EE code and figure out creative ways to bend it to your needs. – Adrian Macneil Jun 20 '13 at 22:48
  • I've spent the last year pruning the singleton pattern out of code as I come across it so it's going to be nasty not being able to get rid of them. Cheers again for your support. – dorothy Dorothy Jun 24 '13 at 18:05
0

I think it's ok to use Testee, though the documentation for it is quite lacking and simpletest has fallen out of favor with the rise of laravel, composer and PHPUnit.

I have been able to get it working. The skeleton for a test file would be like so:

<?php

// Need to include the addon you're testing,
// but testee loads Testee_unit_test_case for you
require_once PATH_THIRD.'addon/pi.addon.php';

class Test_addon extends Testee_unit_test_case {

    // The following just makes it easier to 
    // call the addon's methods by storing an
    // instance.
    private $_subject;

    function setUp() {
        parent::setUp();

        $this->_subject = new Addon_class();
    }

After writing such a test file in the tests directory of your addon, you should see it appear in the control panel in the module page for Testee.

I am working on figuring out how to write the tests to mock params and tagdata and the like. I'll report back if i find an answer to that.

3
  • I've asked the remaining part of the question here: expressionengine.stackexchange.com/q/11344/955 – epocsquadron Jun 18 '13 at 19:23
  • I figured out how to pass parameters and tagdata to module and plugin tags -- see the answer to the question I linked. – epocsquadron Jun 18 '13 at 20:44
  • I didn't manage to get Testee working in any useful way. :( but it is useful to know that it is possible. Thanks very much for the link – dorothy Dorothy Jun 20 '13 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.