blob: b1e9b732f0483676dc373bbc03c251275842cfec [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
Greg Aker25a66902011-04-21 09:24:16 -050022# Requirements
23
241. PHP Unit
25 - pear channel-discover pear.phpunit.de
26 - pear install phpunit/PHPUnit
27
282. vfsStream
29 - pear channel-discover pear.php-tools.net
30 - pear install pat/vfsStream-alpha
31
32
Pascal Krieteba2430b2011-04-20 21:44:13 -040033# Test Suites:
34
35CodeIgniter bootstraps a request very directly, with very flat class
36hierarchy. As a result, there is no main CodeIgniter class until the
37controller is instantiated.
38
39This has forced the core classes to be relatively decoupled, which is
40a good thing. However, it makes that portion of code relatively hard
41to test.
42
43Right now that means we'll probably have two core test suites, along
44with a base for application and package tests. That gives us:
45
461. Bootstrap Test - test common.php and sanity check codeigniter.php [in planning]
472. System Test - test core components in relative isolation [in development]
483. Application Test - bootstrapping for application/tests [not started]
494. Package Test - bootstrapping for <package>/tests [not started]
50
51
52## 1. Bootstrap Test
53
54Testing common.php should be pretty simple. Include the file, and test the
55functions. May require some tweaking so that we can grab the statics from all
56methods (see is_loaded()). Testing the actual CodeIgniter.php file will most
57likely be an output test for the default view, with some object checking after
58the file runs. Needs consideration.
59
60
61## 2. System Test
62
63Testing the core system relies on being able to isolate the core components
64as much as possible. A few of them access other core classes as globals. These
65should be mocked up and easy to manipulate.
66
67All functions in common.php should be a minimal implementation, or and mapped
68to a method in the test's parent class to gives us full control of their output.
69
70
Pascal Kriete34bc0892011-04-21 01:22:23 -040071### CI_TestCase Documentation
Pascal Krieteba2430b2011-04-20 21:44:13 -040072
73
Pascal Kriete34bc0892011-04-21 01:22:23 -040074Test cases should extend CI_TestCase. This internally extends
75PHPUnit_Framework_TestCase, so you have access to all of your
76usual PHPUnit methods.
Pascal Krieteba2430b2011-04-20 21:44:13 -040077
78We need to provide a simple way to modify the globals and the
79common function output. We also need to be able to mock up
80the super object as we please.
81
82Current API is *not stable*. Names and implementations will change.
83
Pascal Kriete34bc0892011-04-21 01:22:23 -040084$this->ci_set_config($key, $val)
85 Set the global config variables. If key is an array, it will
86 replace the entire config array. They are _not_ merged.
87
Pascal Krieteba2430b2011-04-20 21:44:13 -040088$this->ci_instance($obj)
89 set the object to use as the "super object", in a lot
90 of cases this will be a simple stdClass with the attributes
Pascal Kriete34bc0892011-04-21 01:22:23 -040091 you need it to have. If no parameter, will return the instance.
Pascal Krieteba2430b2011-04-20 21:44:13 -040092
Pascal Kriete34bc0892011-04-21 01:22:23 -040093$this->ci_instance_var($name, $val)
Pascal Krieteba2430b2011-04-20 21:44:13 -040094 add an attribute to the super object. This is useful if you
95 set up a simple instance in setUp and then need to add different
96 class mockups to your super object.
97
98$this->ci_core_class($name)
99 Get the _class name_ of a core class, so that you can instantiate
100 it. The variable is returned by reference and is tied to the correct
101 $GLOBALS key. For example:
102 $cfg =& $this->ci_core_class('cfg'); // returns 'CI_Config'
103 $cfg = new $cfg; // instantiates config and overwrites the CFG global
104
Pascal Kriete34bc0892011-04-21 01:22:23 -0400105$this->ci_set_core_class($name, $obj)
Pascal Krieteba2430b2011-04-20 21:44:13 -0400106 An alternative way to set one of the core globals.
107
Pascal Kriete34bc0892011-04-21 01:22:23 -0400108$this->ci_get_config() __internal__
109 Returns the global config array. Internal as you shouldn't need to
110 call this (you're setting it, after all). Used internally to make
111 CI's get_config() work.
112
113CI_TestCase::instance() __internal__
114 Returns an instance of the current test case. We force phpunit to
115 run with backup-globals enabled, so this will always be the instance
116 of the currently running test class.
Pascal Krieteba2430b2011-04-20 21:44:13 -0400117
118## 3. Application Test:
119
120Not sure yet, needs to handle:
121- Libraries
122- Helpers
123- Models
124- MY_* files
125- Controllers (uh...?)
126- Views? (watir, selenium, cucumber?)
127
128- Database Testing
129
130
131## 4. Package Test:
132
133I don't have a clue how this will work.
134
135Needs to be able to handle packages
136that are used multiple times within the application (i.e. EE/Pyro modules)
137as well as packages that are used by multiple applications (library distributions)