public function testGetAllUsers() { $myDb = DBMaker::create('ptest'); Database::clearDB(); $db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini'); $users = UsersDB::getAllUsers(); $this->assertEquals(4, count($users), 'It should fetch all of the users in the test database'); foreach ($users as $user) { $this->assertTrue(is_a($user, 'User'), 'It should return valid User objects'); } }
<h2>It should allow a user to be added</h2> <?php echo "Number of users in db before added is: " . count(UsersDB::getAllUsers()) . "<br>"; $validTest = array("userName" => "joan", "password" => "123"); $user = new User($validTest); $userId = UsersDB::addUser($user); echo "Number of users in db after added is: " . count(UsersDB::getAllUsers()) . "<br>"; echo "User ID of new user is: {$userId}<br>"; ?> <h2>It should not add an invalid user</h2> <?php echo "Number of users in db before added is: " . count(UsersDB::getAllUsers()) . "<br>"; $invalidUser = new User(array("userName" => "krobbins\$")); $userId = UsersDB::addUser($invalidUser); echo "Number of users in db after added is: " . count(UsersDB::getAllUsers()) . "<br>"; echo "User ID of new user is: {$userId}<br>"; ?> <h2>It should get a User by userName</h2> <?php $users = UsersDB::getUsersBy('userName', 'George'); echo "The value of User George is:<br>{$users['0']}<br>"; ?> <h2>It should get a User by userId</h2> <?php $users = UsersDB::getUsersBy('userId', '3'); echo "The value of User 3 is:<br>{$users['0']}<br>"; ?>