I would like to get some feedback on what is one of my first PHPUnit test cases.
The subject of the tests is a simple configuration class in a PHP app. It is used to create, store and retrieve configuration settings.
The settings are stored in an array within the class. Each setting has the following properties:
key (for example
frontend:menu:bgcolor)type (one of
string,int,hexcolor,boolean)value (mixed)
read only (boolean)
Every setting has to be created first. On creation, each setting is assigned a type, the read only flag (defaults to false), and a default value.
Class methods:
public function create($key, $value, $type = "string", $read_only = false)
public function set($key, $value)
public function get($key)
The tests I am running:
(ok) and (fail) are the expected results of the test.
Create a setting named
testwith typestringwith an initial valuexyz(ok)Load the setting
testand expect return valuexyz(ok)Set the setting
testtoabc(ok)Load the setting
testand expect return valueabc(ok)Load the setting
töst(fail, key doesn't exist)Create a setting named
test_read_onlywith typestring, an initial valueMary had a little lamband the read-only flag set to true (ok)Set the setting named
test_read_onlytoPeter had a big lamb(fail, key is read only)Load the setting named
test_read_onlyand expect return valueMary had a little lamb(ok)Create a setting named
test_integerwith typeint, an initial value5and the read-only flag set to true (ok)Create a setting named
test_integer_secondwith typeint, and an initial value5.23049505906(fail, initial value has wrong type)Create a setting named
test_weirdwith typesdasfäödsf#ädfsaö(fail, type not found)Set the setting named
test_weirdtoPeter had a little lamb(fail, key not defined)
Questions:
- Does this test case make sense to you?
- Would you consider this a complete test case?
- What would you do differently, or in addition?
Update: Suggestions that have come up so far that I will implement:
- String length checks
- Tests involving the remaining data types
booleanandhexcolor- Key naming tests are not necessary right now but will be in the future.