/extended_test_case

Extended test case class for CakePHP that makes for a better testAction() experience.

Primary LanguagePHP

Note: This repo is no longer under active development. These improvements were contributed to the CakePHP core in the 2.0-dev stage. Please take a look at the docs for more info. This plugin is still plenty usable for projects still on the CakePHP 1.3 branch.

Extended Test Case

Extended test case aims to make the displeasure of using CakeTestCase::testAction() slightly more pleasurable.

Usage

Above your test case, use:

App::import('Lib', 'ExtendedTestCase.ExtendedTestCase');

Then extend your test case with ExtendedTestCase instead of CakeTestCase and define the testController variable in your test case as the controller you are testing.

For more information about utilizing mocks, etc. visit here.

Another handy feature that ExtendedTestCase adds is the ability to just test certain methods. This is especially useful when you are making minor changes to one method (say, a controller method) who's test lies in a large test case that loads a lot of fixtures. While testing internally, you can conveniently add an array of methods that you want to run in a $testMethods var on your test case.

class MyTestCase extends ExtendedTestCase {
    var $testMethods = array('testThis');

    function testThis() {} // will run
    function testThat() {} // will not run
}

Since no other tests run, you'll only need to load the database and fixtures for the method you care about at the time.

Remember to remove $testMethods before you commit anything :)

Features

  • Falls back to old testAction method if ExtendedTestCase::testController is not defined
  • Allows use of mocks for things like the Email component or your controller actions (render, header, etc.) in tests
  • Simulates most of what the controller action does, minus actually rendering anything
  • Allows testing a subset of test methods within a large test case

License

Licensed under The MIT License http://www.opensource.org/licenses/mit-license.php Redistributions of files must retain the above copyright notice.

Links