PHPackages                             axy/posix - 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. axy/posix

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

axy/posix
=========

Mockable wrapper for POSIX functions

0.2.0(2y ago)011MITPHPPHP &gt;=8.1

Since Oct 14Pushed 2y ago1 watchersCompare

[ Source](https://github.com/axypro/posix)[ Packagist](https://packagist.org/packages/axy/posix)[ Docs](https://github.com/axypro/posix)[ RSS](/packages/axy-posix/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

axy/posix
=========

[](#axyposix)

Mockable wrapper for POSIX functions.

[![Latest Stable Version](https://camo.githubusercontent.com/3bf5c6ae5aa0691a6dea39f44b40928e86ffc41716ef10357a7a34ed0483dc3c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6178792f706f7369782e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/axy/posix)[![Minimum PHP Version](https://camo.githubusercontent.com/2d18ce514c7016022dad012ac9e39a8b6f47cc411b2daff6627cbf208f8cea63/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e312d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![Tests](https://github.com/axypro/posix/actions/workflows/test.yml/badge.svg)](https://github.com/axypro/posix/actions/workflows/test.yml)[![Coverage Status](https://camo.githubusercontent.com/9c6e05b4aee93b918fa459d57b6e82239a0122054c52b6fbe884eb9999f1aa24/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f61787970726f2f706f7369782f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/axypro/posix?branch=master)[![License](https://camo.githubusercontent.com/d78ed7a477014ef4beccbd3b5184968e2748928594753a9646fba956ed6308e9/68747470733a2f2f706f7365722e707567782e6f72672f6178792f706f7369782f6c6963656e7365)](LICENSE)

The library provides the interface `axy\posix\IPosix` which almost completely reproduces [the POSIX functions list](https://www.php.net/manual/en/ref.posix.php). The standard implementation is also provided. It is the `RealPosix` class that just delegates execution to those functions.

What benefits of using this? Except of some minor improvements (see below), using an object with a specified interface allows you to change implementation. Firstly, this is useful for tests. The `RealPosix` itself provides the listener functionality (see below).

IPosix
------

[](#iposix)

The interface contains methods similar to standard `posix_*()` functions.

- Method names doesn't contain prefix `posix_`. Otherwise, the names as identical. It can be possible change they to more human-readable style, but it is the standard, you know.
- An exception is thrown when an error is happened (standard functions usually return `FALSE`).
- For same reason there are no methods for get the last error code.
- Structures that are returned by some methods (`getgrgid()` for example) are converted to objects of certain data-classes (standard functions return associative arrays).

Exceptions
----------

[](#exceptions)

Are located in `axy\posix\exceptions`:

- `IPosixException` - the main interface
    - `PosixException` - a standard function error (extends `LogicException`, just because)
        - The constructor takes an error code as only argument
        - An exception object has readonly properties:
            - `$posixErrorCode (int)` - the origin error code, is equal to the exception code
            - `$posixErrorConstant (?string)` - the error constant name (`EPERM` for example, NULL if not defined)
            - `$posixErrorMessage (string)` - the error message as `posix_strerror()` returned
    - `PosixNotImplementedException` - the corresponding function is not defined (for example, `getpgid` is not defined on all systems, some functions were added in 8.3)

Structures
----------

[](#structures)

All the following structures is data classes. Each of them has the property `$data` that contains the original array and other named properties for elements of that array.

- `PosicUserInfo` - returned by `getpwnam()`, `getpwuid()`
- `PosixGroupInfo` - returned by `getgrgid()`, `getgrnam()`
- `PosixTimesInfo` - returned by `times()`
- `PosixUnameInfo` - returned by `uname()`
- `PosixResourceLimits` - returned by `getrlimits()`, contains two subobjects `hard` and `soft` with a similar structure

Constants
---------

[](#constants)

All constants that used as method arguments are collected in the `PosixConstants` class. These are just copies of [the standard constants](https://www.php.net/manual/en/posix.constants.access.php) (without the prefix `POSIX_`). The PHP version allows collect these in the `IPosix` but this would clutter the interface with rarely used elements.

Error codes
-----------

[](#error-codes)

Error codes constants are collected in `PosixErrors`. There is a method `PosixErrors::getConstName(int $code): ?string` that returns the constant name for a code.

Listener
--------

[](#listener)

Listeners for `RealPosix` allow to make a logger or a simple mock.

```
$posix = new RealPosix($listener);
```

A listener must implement `axy\posix\IPosixListener` or extend `PosixListener`. There are two methods:

- `before(string $method, array $args, ?int &$code = null): mixed`
- `after(string $method, array $args, mixed $result, ?int &$code = null): mixed`

`before()` is called before the call of a real function. It takes the method name (such "getgid", without the prefix) and the arguments list. If it returns any value except `NULL` it is considered as the result and the real function is not called.

`after()` is called, respectively, at the end and takes also `$result` (as the result of performance, it also can be the result of `before()`). It can change the result and return it. If you don't want change result here just return the `$result` argument.

- Both methods must return values in the standard function format. For `getgrgid()` it is an array, not a data object.
- The methods must follow the return value type. If they return `int` when `string` is required it will lead to the fatal error.
- To signal an error they can throw `PosixException` or return the standard value for this case (usually it is `FALSE` or -1).
- Both method takes `$code` by a link and can change it. It will be used as the error code if an error will be detected. `before()` takes it as `NULL`, `after()` takes it changed by `before()` or the real error code. If an error is happened and `$code` was not changed by listeners will be used the real code from `posix_get_last_error()`.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 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 ~33 days

Total

4

Last Release

849d ago

### Community

Maintainers

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

---

Top Contributors

[![vasa-c](https://avatars.githubusercontent.com/u/557081?v=4)](https://github.com/vasa-c "vasa-c (19 commits)")

---

Tags

mockposix

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/axy-posix/health.svg)

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

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/packages/mockery-mockery)[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[php-mock/php-mock

PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.

36918.1M98](/packages/php-mock-php-mock)[phake/phake

The Phake mock testing library

4758.0M324](/packages/phake-phake)[kahlan/kahlan

The PHP Test Framework for Freedom, Truth and Justice.

1.2k1.2M247](/packages/kahlan-kahlan)[brain/monkey

Mocking utility for PHP functions and WordPress plugin API

33412.5M350](/packages/brain-monkey)

PHPackages © 2026

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