Pascal Kriete | ba2430b | 2011-04-20 21:44:13 -0400 | [diff] [blame] | 1 | # Do not merge to default until this is blank # |
| 2 | |
| 3 | - Clean up naming conventions |
| 4 | - Figure out config stuff |
| 5 | - Figure out database testing |
| 6 | |
| 7 | |
| 8 | |
| 9 | # -------------- CodeIgniter Testing (4/20/2011) -------------- # |
| 10 | |
| 11 | |
| 12 | # Introduction: |
| 13 | |
| 14 | This is the preliminary CodeIgniter testing documentation. It |
| 15 | will cover both internal as well as external APIs and the reasoning |
| 16 | behind their implemenation, where appropriate. As with all CodeIgniter |
| 17 | documentation, this file should maintain a mostly human readable |
| 18 | format to facilitate clean api design. [see http://arrenbrecht.ch/testing/] |
| 19 | |
| 20 | *FIRST PUBLIC DRAFT: EVERYTHING IS SUBJECT TO CHANGE* |
| 21 | |
| 22 | # Test Suites: |
| 23 | |
| 24 | CodeIgniter bootstraps a request very directly, with very flat class |
| 25 | hierarchy. As a result, there is no main CodeIgniter class until the |
| 26 | controller is instantiated. |
| 27 | |
| 28 | This has forced the core classes to be relatively decoupled, which is |
| 29 | a good thing. However, it makes that portion of code relatively hard |
| 30 | to test. |
| 31 | |
| 32 | Right now that means we'll probably have two core test suites, along |
| 33 | with a base for application and package tests. That gives us: |
| 34 | |
| 35 | 1. Bootstrap Test - test common.php and sanity check codeigniter.php [in planning] |
| 36 | 2. System Test - test core components in relative isolation [in development] |
| 37 | 3. Application Test - bootstrapping for application/tests [not started] |
| 38 | 4. Package Test - bootstrapping for <package>/tests [not started] |
| 39 | |
| 40 | |
| 41 | ## 1. Bootstrap Test |
| 42 | |
| 43 | Testing common.php should be pretty simple. Include the file, and test the |
| 44 | functions. May require some tweaking so that we can grab the statics from all |
| 45 | methods (see is_loaded()). Testing the actual CodeIgniter.php file will most |
| 46 | likely be an output test for the default view, with some object checking after |
| 47 | the file runs. Needs consideration. |
| 48 | |
| 49 | |
| 50 | ## 2. System Test |
| 51 | |
| 52 | Testing the core system relies on being able to isolate the core components |
| 53 | as much as possible. A few of them access other core classes as globals. These |
| 54 | should be mocked up and easy to manipulate. |
| 55 | |
| 56 | All functions in common.php should be a minimal implementation, or and mapped |
| 57 | to a method in the test's parent class to gives us full control of their output. |
| 58 | |
| 59 | |
Pascal Kriete | 34bc089 | 2011-04-21 01:22:23 -0400 | [diff] [blame^] | 60 | ### CI_TestCase Documentation |
Pascal Kriete | ba2430b | 2011-04-20 21:44:13 -0400 | [diff] [blame] | 61 | |
| 62 | |
Pascal Kriete | 34bc089 | 2011-04-21 01:22:23 -0400 | [diff] [blame^] | 63 | Test cases should extend CI_TestCase. This internally extends |
| 64 | PHPUnit_Framework_TestCase, so you have access to all of your |
| 65 | usual PHPUnit methods. |
Pascal Kriete | ba2430b | 2011-04-20 21:44:13 -0400 | [diff] [blame] | 66 | |
| 67 | We need to provide a simple way to modify the globals and the |
| 68 | common function output. We also need to be able to mock up |
| 69 | the super object as we please. |
| 70 | |
| 71 | Current API is *not stable*. Names and implementations will change. |
| 72 | |
Pascal Kriete | 34bc089 | 2011-04-21 01:22:23 -0400 | [diff] [blame^] | 73 | $this->ci_set_config($key, $val) |
| 74 | Set the global config variables. If key is an array, it will |
| 75 | replace the entire config array. They are _not_ merged. |
| 76 | |
Pascal Kriete | ba2430b | 2011-04-20 21:44:13 -0400 | [diff] [blame] | 77 | $this->ci_instance($obj) |
| 78 | set the object to use as the "super object", in a lot |
| 79 | of cases this will be a simple stdClass with the attributes |
Pascal Kriete | 34bc089 | 2011-04-21 01:22:23 -0400 | [diff] [blame^] | 80 | you need it to have. If no parameter, will return the instance. |
Pascal Kriete | ba2430b | 2011-04-20 21:44:13 -0400 | [diff] [blame] | 81 | |
Pascal Kriete | 34bc089 | 2011-04-21 01:22:23 -0400 | [diff] [blame^] | 82 | $this->ci_instance_var($name, $val) |
Pascal Kriete | ba2430b | 2011-04-20 21:44:13 -0400 | [diff] [blame] | 83 | add an attribute to the super object. This is useful if you |
| 84 | set up a simple instance in setUp and then need to add different |
| 85 | class mockups to your super object. |
| 86 | |
| 87 | $this->ci_core_class($name) |
| 88 | Get the _class name_ of a core class, so that you can instantiate |
| 89 | it. The variable is returned by reference and is tied to the correct |
| 90 | $GLOBALS key. For example: |
| 91 | $cfg =& $this->ci_core_class('cfg'); // returns 'CI_Config' |
| 92 | $cfg = new $cfg; // instantiates config and overwrites the CFG global |
| 93 | |
Pascal Kriete | 34bc089 | 2011-04-21 01:22:23 -0400 | [diff] [blame^] | 94 | $this->ci_set_core_class($name, $obj) |
Pascal Kriete | ba2430b | 2011-04-20 21:44:13 -0400 | [diff] [blame] | 95 | An alternative way to set one of the core globals. |
| 96 | |
Pascal Kriete | 34bc089 | 2011-04-21 01:22:23 -0400 | [diff] [blame^] | 97 | $this->ci_get_config() __internal__ |
| 98 | Returns the global config array. Internal as you shouldn't need to |
| 99 | call this (you're setting it, after all). Used internally to make |
| 100 | CI's get_config() work. |
| 101 | |
| 102 | CI_TestCase::instance() __internal__ |
| 103 | Returns an instance of the current test case. We force phpunit to |
| 104 | run with backup-globals enabled, so this will always be the instance |
| 105 | of the currently running test class. |
Pascal Kriete | ba2430b | 2011-04-20 21:44:13 -0400 | [diff] [blame] | 106 | |
| 107 | ## 3. Application Test: |
| 108 | |
| 109 | Not sure yet, needs to handle: |
| 110 | - Libraries |
| 111 | - Helpers |
| 112 | - Models |
| 113 | - MY_* files |
| 114 | - Controllers (uh...?) |
| 115 | - Views? (watir, selenium, cucumber?) |
| 116 | |
| 117 | - Database Testing |
| 118 | |
| 119 | |
| 120 | ## 4. Package Test: |
| 121 | |
| 122 | I don't have a clue how this will work. |
| 123 | |
| 124 | Needs to be able to handle packages |
| 125 | that are used multiple times within the application (i.e. EE/Pyro modules) |
| 126 | as well as packages that are used by multiple applications (library distributions) |