PHPackages                             sugarcraft/candy-testing - 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. sugarcraft/candy-testing

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

sugarcraft/candy-testing
========================

Test harness for TEA programs — ProgramSimulator, golden-file assertions, and snapshot helpers for SugarCraft.

00PHP

Since Jun 1Pushed 1w agoCompare

[ Source](https://github.com/sugarcraft/candy-testing)[ Packagist](https://packagist.org/packages/sugarcraft/candy-testing)[ RSS](/packages/sugarcraft-candy-testing/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

candy-testing
=============

[](#candy-testing)

Test harness for TEA (The Elm Architecture) programs — pioneering what [bubble-tea issue #1654](https://github.com/charmbracelet/bubbletea/issues/1654) never shipped.

> **TEA background:** The Elm Architecture (Model / Update / View) is the foundation of [charmbracelet/bubbletea](https://github.com/charmbracelet/bubbletea). Testing TEA programs deterministically has been a long-standing gap — `candy-testing` closes it for the PHP ecosystem.

Overview
--------

[](#overview)

`candy-testing` provides the infrastructure SugarCraft pioneers for deterministic TEA program testing:

- **`ProgramSimulator`** — drives a `Program` with scripted input, captures model/view/cmds
- **`ScriptedInput`** — fluent builder for message sequences (`->key('q')->enter()`)
- **Snapshot assertions** — `assertGoldenAnsi`, `assertCellGrid`, `assertAnsiEquals`
- **`GoldenFile`** — load/save helper for `.golden` fixture files
- **`TapeRecorder`** — emits VHS-compatible `.tape` files for demo rendering

Quickstart
----------

[](#quickstart)

```
use SugarCraft\Testing\ProgramSimulator;
use SugarCraft\Testing\Input\ScriptedInput;
use SugarCraft\Testing\Snapshot\Assertions;

// Build a scripted session and run the simulator.
$sim = ProgramSimulator::for($program)
    ->send(new KeyMsg(KeyType::Char, 'a'))
    ->send(new KeyMsg(KeyType::Enter))
    ->run();

// Assert the view output matches the golden file.
Assertions::assertGoldenAnsi(__DIR__ . '/fixtures/counter.golden', $sim->view);

// Inspect the final model state.
$counter = $sim->model; // CounterModel with updated count
```

Requirements
------------

[](#requirements)

- PHP 8.3+
- `sugarcraft/candy-core` (Program, Msg, Model, Cmd)
- `sugarcraft/candy-buffer` (Buffer for cell-grid assertions)

Install
-------

[](#install)

```
composer require sugarcraft/candy-testing:@dev
```

API
---

[](#api)

### ProgramSimulator

[](#programsimulator)

```
// Wrap a Program for testing.
$sim = ProgramSimulator::for($program);

// Enqueue messages (fluent).
$sim->send(new KeyMsg(...))->send(new KeyMsg(...));

// Override the cmd runner to capture instead of executing side effects.
$sim->withFakeCmdRunner(fn($cmd) => null);

// Run the session and get the result.
$result = $sim->run();
echo $result->view;   // Last view() output
echo $result->model;  // Final model state
echo $result->output; // Raw accumulated ANSI bytes
```

### Assertions

[](#assertions)

```
// Golden ANSI snapshot (auto-creates on first run if UPDATE_GOLDENS=1).
Assertions::assertGoldenAnsi('tests/fixtures/view.golden', $actual);

// Cell-grid diff (for buffer-based renderers).
Assertions::assertCellGrid($expected2DArray, $buffer);

// Byte-exact ANSI comparison with readable diff on failure.
Assertions::assertAnsiEquals("\x1b[1;32mHello\x1b[0m", $actual);
```

### ScriptedInput

[](#scriptedinput)

```
$input = ScriptedInput::new()
    ->key('h', ctrl: true)  // Ctrl+h
    ->arrow('down')
    ->enter()
    ->ticks(5)             // 5 tick events
    ->resize(120, 40)
    ->key('q')
    ->build();
```

License
-------

[](#license)

MIT

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance64

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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.

### Community

Maintainers

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

---

Top Contributors

[![detain](https://avatars.githubusercontent.com/u/1364504?v=4)](https://github.com/detain "detain (7 commits)")

### Embed Badge

![Health badge](/badges/sugarcraft-candy-testing/health.svg)

```
[![Health](https://phpackages.com/badges/sugarcraft-candy-testing/health.svg)](https://phpackages.com/packages/sugarcraft-candy-testing)
```

###  Alternatives

[szepeviktor/phpstan-wordpress

WordPress extensions for PHPStan

3309.4M1.2k](/packages/szepeviktor-phpstan-wordpress)[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14228.7M340](/packages/dms-phpunit-arraysubset-asserts)[jasonmccreary/laravel-test-assertions

A set of helpful assertions when testing Laravel applications.

3524.1M38](/packages/jasonmccreary-laravel-test-assertions)[orchestra/workbench

Workbench Companion for Laravel Packages Development

8219.1M67](/packages/orchestra-workbench)[soyuka/contexts

Behatch contexts

282.2M21](/packages/soyuka-contexts)[roquie/laravel-dusk-select2

Select2.js support for the Laravel Dusk testing.

41356.2k5](/packages/roquie-laravel-dusk-select2)

PHPackages © 2026

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