I'm using a legacy (no-tests) PHP project, full of classes like http://pastebin.com/byBMTAEY
Practically all methods are static, and most of them reference the database directly using a singleton (to limit connections to one)
Most of them also have a reference to a global called _COMPANY, that identifies which company is using the platform (based on the subdomain).
My (very newbie) question is: what's the best way to unit test this class? Should I unit test it at all, since what it does is go to the database and do logic there, and then just wrap up the result?
I mean, I can probably mock the database class, and then say "on 'one' return this result-object", but then what am I testing really? The SQL logic not, for one thing, only the private functions to make a business object... is that enough for the unit test? Or should I somehow also unit test the sql? Or is that reserved for integration testing?
Please help me understand so I can use this practice if applicable.
Example code also included here for reference:
<?php
require_once('DataBase.php');
require_once('businessobjects/User.php');
class UserMgt {
public static function login($email, $pass){
$db = DataBase::getInstance();
$sql = "
SELECT *
FROM user
WHERE login = ? AND password = ? AND active = 1 AND company_id = ?
";
$data = array(
$email, md5($pass), $GLOBALS['_COMPANY']->id,
);
$user = null;
if ($row = $db->one($sql, $data)) { // fetch only one row using the query and parameters
$user = self::copyToUserObject($row); // make a business object
$user->setCapabilities(self::getUserCapabilities($user->getID())); // perform some extra hydration of business object
}
return $user;
}
private static function copyToUserObject($dbrow) {
$user = new User();
// do stuff
return $user;
}
private static function getUserCapabilities($userid) {
// do sql query stuff
// return array
}
}