FrontAccounting function mocks for unit testing PHP modules that depend on FrontAccounting functions.
When writing unit tests for FrontAccounting modules, you often need to mock FA-specific functions that are not available in the test environment. FAMock provides stub implementations of these functions so your tests can run without requiring a full FA installation.
composer require ksfraser/famock --devAdd to your composer.json:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/ksfraser/FAMock.git"
}
],
"require-dev": {
"ksfraser/famock": "dev-main"
}
}Note: Requires GitHub authentication token for private repositories.
{
"repositories": [
{
"type": "path",
"url": "../path/to/FAMock-repo"
}
],
"require-dev": {
"ksfraser/famock": "*"
}
}In your test bootstrap or test file:
require_once 'vendor/ksfraser/famock/php/FAMock.php';This will load all FA function stubs.
db_query()- Mock database queriesdb_escape()- Mock string escapingdb_fetch()- Mock result fetching
start_form(),end_form()- Form HTML outputstart_table(),end_table()- Table HTML outputtext_row(),check_row()- Form input helpersdisplay_notification(),display_error()- Message displaypage(),end_page()- Page structure
fa_hooks()- Mock hook manager$path_to_root- Mock global path variable
user_check_access()- Always returns trueadd_access_extensions()- No-op
get_company_pref()- Mock company preferences$_SESSION['wa_current_user']- Mock user session
get_company_prefs()- Get mock preferencesupdate_company_prefs()- Update mock preferences
Ksfraser\FAMock\MockDatabase- PHPUnit mock implementing DatabaseInterface
When adding new FA function mocks:
- Create a new stub file following the SRP pattern (e.g.,
FaNewCategoryStubs.php) - Use
if (!function_exists('function_name'))to check if already defined - Add the file to
FAMock.php - Update this README
To publish to Packagist:
- Push to GitHub:
git push origin main - Go to https://packagist.org/packages/submit
- Submit the GitHub repository URL:
https://github.com/ksfraser/FAMock - Tag a release:
git tag v0.2.0 && git push --tags
Once published, users can install with: composer require ksfraser/famock --dev
Current Status: FAMock is ready for publishing but currently uses local path installation for development.