Repository navigation
divide 0.8.0
divide 0.8.0 tests a single Runner Function. You give it a JSON context, and divide calls the Function alone, as Runner would, then shows what it returned, how it changed the context and what it printed. You can also debug the same call in the debugger. No Flow or Step runs.
Test Function
Open it with:
- T on a Step in the Flow Designer: its activity, else its condition;
- Ctrl+F9 on a Function in the Functions window;
- Function... > Test... in the Step dialog.
The Function is resolved by Runner's own importer, with the Flow's function root, its Module folders and .div/runner.json. That is the same file a run of the Flow would load. Inside a Module, nothing outside that Module's folder is tried. It is called as Runner calls it: $func($context), with the context passed by reference and _importer in it.
The dialog:
- Context: a JSON object. Edit... opens it as a tree or as JSON text. The last input of each Function is remembered in your own settings, never in the project.
- Scenario: Save writes the input to
.div/function-tests/<module>/<name>.json, a fixture the team can share. Down offers the saved ones. - Expected return and Expected context after (the keys the context must hold): optional checks, reported as
okorFAIL. - Time limit: 30 seconds by default. The test also has a memory limit.
- Run, or Debug.
PHP files with unsaved changes are saved first.
The report
The report goes to Output, with each part separate:
- the file loaded;
- how the call ended: returned, exception, fatal error,
exit(), not found, or time limit; - the expectations;
- the returned value as JSON, and its type. For a condition, the report also says what that value would do to a Step;
- an exception's class, message, place and trace;
- the context's changes, key by key (
+ ~ -), then the context before and after; - stdout and stderr, never mixed with the result.
An exception's or a fatal error's place, PHP's warnings and a failed expectation also go to Messages, where Enter opens the file at that line.
Debug a Function
Debug makes the same call under Xdebug.
- With no breakpoint in the Function's file, it stops at the Function's first line.
- Otherwise it runs to your breakpoints, in the Function or in any file it calls.
- From there, F7, F8, watches and the call stack work as for any PHP script. Ctrl+F9 goes on, and the same report appears when it ends.
Safety
A test runs the project's real PHP code in its own PHP process, with a time and a memory limit. It is not a sandbox: the Function may write files or use a database or the network. The dialog and the report say so.
Also
- The help page Flow Functions has a new section, Test a Function, in English and Spanish, with the workflow as a GIF and screenshots.
- The Spanish interface covers all of the above.
Known limits
- A test runs a Function once, for real. Simulating Functions with mocks, or simulating whole Flows, is separate work.
Install
Ready to run, with nothing else to install:
- macOS and Linux:
brew install divengine/tap/divide - Windows:
scoop install https://github.com/divengine/divide/releases/latest/download/divide.json, or the.msibelow - Linux: the
.deb,.rpm,.apkand Arch packages, the AppImage or the binary alone, below - macOS: the archive for Apple silicon or Intel, below
Rendering and checking includes need PHP 8 and Div (composer require divengine/div); Runner Flows need Runner (composer require divengine/runner); the Git menu needs git. divide is free software under the GPL, version 3 or later. The binaries are not signed yet: see Installation.
