PHPackages                             ksfraser/famock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. ksfraser/famock

ActiveLibrary[Testing &amp; Quality](/categories/testing)

ksfraser/famock
===============

FrontAccounting function mocks for unit testing

v0.5.0(1mo ago)011[1 PRs](https://github.com/ksfraser/FAMock/pulls)MITPHPPHP &gt;=7.3

Since Feb 6Pushed 1mo agoCompare

[ Source](https://github.com/ksfraser/FAMock)[ Packagist](https://packagist.org/packages/ksfraser/famock)[ RSS](/packages/ksfraser-famock/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (7)Used By (0)

FAMock
======

[](#famock)

FrontAccounting function mocks for unit testing PHP modules that depend on FrontAccounting functions.

Purpose
-------

[](#purpose)

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.

Installation
------------

[](#installation)

### Option 1: Packagist (when published)

[](#option-1-packagist-when-published)

```
composer require ksfraser/famock --dev
```

### Option 2: GitHub Repository (requires authentication)

[](#option-2-github-repository-requires-authentication)

Add 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.

### Option 3: Local Path (recommended for development)

[](#option-3-local-path-recommended-for-development)

```
{
    "repositories": [
        {
            "type": "path",
            "url": "../path/to/FAMock-repo"
        }
    ],
    "require-dev": {
        "ksfraser/famock": "*"
    }
}
```

Usage
-----

[](#usage)

In your test bootstrap or test file:

```
require_once 'vendor/ksfraser/famock/php/FAMock.php';
```

This will load all FA function stubs.

Available Stubs
---------------

[](#available-stubs)

### Database Functions (`FaDbStubs.php`)

[](#database-functions-fadbstubsphp)

- `db_query()` - Mock database queries
- `db_escape()` - Mock string escaping
- `db_fetch()` - Mock result fetching

### UI Functions (`FaUIStubs.php`)

[](#ui-functions-fauistubsphp)

- `start_form()`, `end_form()` - Form HTML output
- `start_table()`, `end_table()` - Table HTML output
- `text_row()`, `check_row()` - Form input helpers
- `display_notification()`, `display_error()` - Message display
- `page()`, `end_page()` - Page structure

### Hook System (`FaHookStubs.php`)

[](#hook-system-fahookstubsphp)

- `fa_hooks()` - Mock hook manager
- `$path_to_root` - Mock global path variable

### Security Functions (`FaSecurityStubs.php`)

[](#security-functions-fasecuritystubsphp)

- `user_check_access()` - Always returns true
- `add_access_extensions()` - No-op

### Session/Company (`FaSessionStubs.php`)

[](#sessioncompany-fasessionstubsphp)

- `get_company_pref()` - Mock company preferences
- `$_SESSION['wa_current_user']` - Mock user session

### Preferences (`FaUpdateOnlyStubs.php`)

[](#preferences-faupdateonlystubsphp)

- `get_company_prefs()` - Get mock preferences
- `update_company_prefs()` - Update mock preferences

Mock Classes
------------

[](#mock-classes)

- `Ksfraser\FAMock\MockDatabase` - PHPUnit mock implementing DatabaseInterface

Contributing
------------

[](#contributing)

When adding new FA function mocks:

1. Create a new stub file following the SRP pattern (e.g., `FaNewCategoryStubs.php`)
2. Use `if (!function_exists('function_name'))` to check if already defined
3. Add the file to `FAMock.php`
4. Update this README

Publishing
----------

[](#publishing)

To publish to Packagist:

1. Push to GitHub: `git push origin main`
2. Go to
3. Submit the GitHub repository URL: `https://github.com/ksfraser/FAMock`
4. 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.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance89

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~11 days

Total

5

Last Release

53d ago

PHP version history (2 changes)0.2.0PHP &gt;=7.4

0.4.1PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8870cc04b29a973eed9ad367a936ab274d744de37ff0c35fa0540a932905271?d=identicon)[ksfraser](/maintainers/ksfraser)

---

Top Contributors

[![ksfraser](https://avatars.githubusercontent.com/u/54461925?v=4)](https://github.com/ksfraser "ksfraser (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ksfraser-famock/health.svg)

```
[![Health](https://phpackages.com/badges/ksfraser-famock/health.svg)](https://phpackages.com/packages/ksfraser-famock)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
