blob: 27871478bf6984526efcbe8ba5ec7ff208d9b00a [file] [log] [blame]
Pascal Krieteba2430b2011-04-20 21:44:13 -04001# 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
14This is the preliminary CodeIgniter testing documentation. It
15will cover both internal as well as external APIs and the reasoning
16behind their implemenation, where appropriate. As with all CodeIgniter
17documentation, this file should maintain a mostly human readable
18format 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
24CodeIgniter bootstraps a request very directly, with very flat class
25hierarchy. As a result, there is no main CodeIgniter class until the
26controller is instantiated.
27
28This has forced the core classes to be relatively decoupled, which is
29a good thing. However, it makes that portion of code relatively hard
30to test.
31
32Right now that means we'll probably have two core test suites, along
33with a base for application and package tests. That gives us:
34
351. Bootstrap Test - test common.php and sanity check codeigniter.php [in planning]
362. System Test - test core components in relative isolation [in development]
373. Application Test - bootstrapping for application/tests [not started]
384. Package Test - bootstrapping for <package>/tests [not started]
39
40
41## 1. Bootstrap Test
42
43Testing common.php should be pretty simple. Include the file, and test the
44functions. May require some tweaking so that we can grab the statics from all
45methods (see is_loaded()). Testing the actual CodeIgniter.php file will most
46likely be an output test for the default view, with some object checking after
47the file runs. Needs consideration.
48
49
50## 2. System Test
51
52Testing the core system relies on being able to isolate the core components
53as much as possible. A few of them access other core classes as globals. These
54should be mocked up and easy to manipulate.
55
56All functions in common.php should be a minimal implementation, or and mapped
57to a method in the test's parent class to gives us full control of their output.
58
59
Pascal Kriete34bc0892011-04-21 01:22:23 -040060### CI_TestCase Documentation
Pascal Krieteba2430b2011-04-20 21:44:13 -040061
62
Pascal Kriete34bc0892011-04-21 01:22:23 -040063Test cases should extend CI_TestCase. This internally extends
64PHPUnit_Framework_TestCase, so you have access to all of your
65usual PHPUnit methods.
Pascal Krieteba2430b2011-04-20 21:44:13 -040066
67We need to provide a simple way to modify the globals and the
68common function output. We also need to be able to mock up
69the super object as we please.
70
71Current API is *not stable*. Names and implementations will change.
72
Pascal Kriete34bc0892011-04-21 01:22:23 -040073$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 Krieteba2430b2011-04-20 21:44:13 -040077$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 Kriete34bc0892011-04-21 01:22:23 -040080 you need it to have. If no parameter, will return the instance.
Pascal Krieteba2430b2011-04-20 21:44:13 -040081
Pascal Kriete34bc0892011-04-21 01:22:23 -040082$this->ci_instance_var($name, $val)
Pascal Krieteba2430b2011-04-20 21:44:13 -040083 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 Kriete34bc0892011-04-21 01:22:23 -040094$this->ci_set_core_class($name, $obj)
Pascal Krieteba2430b2011-04-20 21:44:13 -040095 An alternative way to set one of the core globals.
96
Pascal Kriete34bc0892011-04-21 01:22:23 -040097$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
102CI_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 Krieteba2430b2011-04-20 21:44:13 -0400106
107## 3. Application Test:
108
109Not 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
122I don't have a clue how this will work.
123
124Needs to be able to handle packages
125that are used multiple times within the application (i.e. EE/Pyro modules)
126as well as packages that are used by multiple applications (library distributions)