Search by

pushinbr / pam-native-testing

DavidWilliamBalbino

Deterministic bridge fakes and assertions for PAM Native applications and plugins.

Package info

github.com/push-in/pam-native-testing

pkg:composer/pushinbr/pam-native-testing

Statistics

Installs: 10 913

Dependents: 11

Suggesters: 0

Stars: 0

Open Issues: 0

v0.3.1 2026-08-24 13:33 UTC

This package is auto-updated.

Last update: 2026-11-29 01:43:20 UTC


README

pam-native-testing: Strict bridge fakes, call assertions and golden-image checks for PAM Native tests.

Test PAM Native code without a device, and certify screens when you have one.
Fake native modules with strict stubs, assert every bridge call, and reject black or transparent frames before comparing against a golden image.

Packagist PHP 8.5 CI License

Install · Quick example · API · Checklist · Docs · Issues

Install

Inside a PAM Native project, as a development dependency:

pam composer require --dev pushinbr/pam-native-testing
pam test

The package is plain PHP (no plugin manifest, no native code). pam test runs Pest or PHPUnit inside PAM. New to PAM? Create a project with pam init my-app --template native and run it with pam mobile dev (see the PAM Native overview), then come back here. Composer owns the manifest and the lockfile; pam composer runs it on PAM's verified PHP runtime. Remove it with pam composer remove pushinbr/pam-native-testing.

Quick example

<?php

use Pam\Native\Testing\NativeTestHarness;

$native = NativeTestHarness::install();
$native->succeed('auth.session', 'current', [
    'identifier' => 'user-1',
    'state' => 2,
]);

// Exercise production PHP code.

$native->assertCalled('auth.session', 'current');
$native->assertSatisfied();
NativeTestHarness::uninstall();

Responses can be immediate or deferred (DispatchMode::Deferred, then flushOne() or flush()). Unstubbed calls fail immediately, and assertSatisfied() detects unused responses and unflushed completions.

Platform support

Platform Support Notes
PAM Native ^0.8 || ^0.9 || ^0.10 || ^1.0 From composer.json
PHP 8.5+ Runs anywhere PHP runs: CI, desktop, device
Android / iOS Captured RGBA frames Visual checks take pixels captured by the platform; no native code in this package

Visual certification

Visual certification is deterministic and framework-independent: provide the RGBA pixels captured by Android or iOS, reject black/transparent launch frames, and compare the result with a golden image using explicit channel and changed-pixel tolerances.

use Pam\Native\Testing\Visual\GoldenComparator;
use Pam\Native\Testing\Visual\ScreenHealth;

$health = (new ScreenHealth())->inspect($capturedFrame);
$diff = (new GoldenComparator(channelTolerance: 0.01))->compare($golden, $capturedFrame);

if (!$health['healthy'] || !$diff->accepted) {
    throw new RuntimeException('Native screen failed visual certification.');
}

$golden and $capturedFrame are PixelBuffer(width, height, rgba) instances.

API guide

API Responsibility
NativeTestHarness Install and remove the fake native-module transport.
FakeNativeModuleTransport Stub success/failure, record calls, defer responses, and assert completion.
DispatchMode Choose immediate or deferred callback execution.
RecordedModuleCall Inspect exact module, method, and payload calls.
StubbedModuleResponse Describe deterministic native results.
PixelBuffer Validate a platform-neutral RGBA screenshot contract.
ScreenHealth Detect black and transparent startup frames.
GoldenComparator / VisualDiff Certify screenshots with measurable tolerances.

All coded states, kinds, and variants are sequential integer-backed enums. Use enum cases in application code; do not depend on raw wire numbers.

Production checklist

  • Uninstall the harness during test teardown.
  • Fail every unstubbed native call so tests cannot pass accidentally.
  • Call assertSatisfied() to catch unused responses and pending completions.
  • Run pam doctor, pam test, and a signed release build on every supported platform.
  • Exercise denial, cancellation, backgrounding, process restart, and offline behavior before release.

Troubleshooting

  • A test hangs: flush deferred responses or change the dispatch mode.
  • An assertion sees extra calls: reset or reinstall the harness per test.
  • Production transport leaks between tests: enforce teardown even after failures.
  • Native integration is stale: run pam doctor --fix, rebuild the native host, and inspect the first reported diagnostic.

Report security vulnerabilities through the repository security policy or GitHub private vulnerability reporting, not a public issue.

Docs

Part of the PAM ecosystem

PAM

PAM runs PHP natively on servers, desktops and phones. This repository is one piece of it.

PAM PAM Desktop PAM Native Ecosystem
the runtime and CLI native desktop apps in PHP native Android and iOS apps in PHP every official package and plugin

Docs: push-in.github.io/pam-docs · Issues

Apache License 2.0 · Made in Brazil by Pushin