blob: eaad2c480bbb626322fcff96feb7a189c0d6102d [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
60### CodeIgniterTestCase Documentation
61
62
63Test cases should extend CodeIgniterTestCase. This internally
64extends PHPUnit_Framework_TestCase, so you have access to all
65of your usual PHPUnit methods.
66
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
73$this->ci_instance($obj)
74 set the object to use as the "super object", in a lot
75 of cases this will be a simple stdClass with the attributes
76 you need it to have.
77
78$this->ci_set_instance_var($name, $val)
79 add an attribute to the super object. This is useful if you
80 set up a simple instance in setUp and then need to add different
81 class mockups to your super object.
82
83$this->ci_core_class($name)
84 Get the _class name_ of a core class, so that you can instantiate
85 it. The variable is returned by reference and is tied to the correct
86 $GLOBALS key. For example:
87 $cfg =& $this->ci_core_class('cfg'); // returns 'CI_Config'
88 $cfg = new $cfg; // instantiates config and overwrites the CFG global
89
90$this->ci_set_core_class($name, $obj);
91 An alternative way to set one of the core globals.
92
93
94## 3. Application Test:
95
96Not sure yet, needs to handle:
97- Libraries
98- Helpers
99- Models
100- MY_* files
101- Controllers (uh...?)
102- Views? (watir, selenium, cucumber?)
103
104- Database Testing
105
106
107## 4. Package Test:
108
109I don't have a clue how this will work.
110
111Needs to be able to handle packages
112that are used multiple times within the application (i.e. EE/Pyro modules)
113as well as packages that are used by multiple applications (library distributions)