Add tests for the example processes#6
Merged
Conversation
phpunit.xml.dist has always pointed at tests/Example/, but the directory was empty: 'php vendor/bin/phpunit' reported 'Test directory not found' (exit 2). Travis stopped running years ago and .travis.yml still targets PHP 5.3 to 7.0, versions that predate this project's own requirement of 8.2. Nothing was left that could report the breakage fixed in #5. 6 tests, 17 assertions. Walks both processes along the same paths index.php takes, including the order that intentionally fails authorization and the exception raised for an event in the wrong state. The expected states were taken from an actual run, not from the docs. Verified: applying this test alone to the unfixed master exits 255.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #5 — merge that first, this targets its branch.
#5 fixes the example. This one is about why nobody noticed it was broken for three months.
What was there
phpunit.xml.dist→tests/Example/Test directory not found, exit 2.travis.ymlThe v3.0.0 upgrade even modernised
phpunit.xml.distfrom<filter>to<source>— the config of a suite that has no tests, pointing at a directory that does not exist.What this adds
tests/Example/Order/OrderTest.php— 6 tests, 17 assertions. Walks both processes along the same state pathsindex.phptakes: prepayment through to return, the order that intentionally fails authorization, the exception raised for an event in the wrong state, postpayment shipping before payment, and the dunning path. The expected states were taken from an actual run, not from the documentation.One difference worth knowing:
index.phpshares a singlePrepaymentinstance between both prepayment orders (viaNamedCollection::get()); the tests build a fresh process per order. Bugs that only appear with shared process instances — observers hanging on shared states — are therefore out of reach of these tests.A mutation check on the example code: inverting either condition, or making
Authorizestop failing PREPAYMENT 2, turns the suite red. Changing__toString,getNameor removing theechodoes not — those are exactly the return values whose signatures #5 touches, plus the console output, which is the only productindex.phphas.Verification
Applying this test alone to the current, unfixed
master:It would have caught April.
With #5 applied:
Tests: 6, Assertions: 17— green. (PHPUnit still appendsDeprecations: 2on PHP 8.5 as long as the library is unpatched; Statemachine#29 removes those.)Still missing: something that runs it
A test nobody executes is not a test. There is no CI on this repo —
.travis.ymlis a fossil, Actions has never run. The workflow below covers it, but it is deliberately not part of this PR: pushing.github/workflows/requires a token withworkflowscope, and that scope would allow rewriting CI across the repo. That is a lot of authority for twenty lines of YAML — better added by hand.The YAML parses and every command in it was run locally on PHP 8.5.4 (
composer install,phpunit,php index.php). Whether the runner behaves as expected only shows once it runs.shivammathur/setup-phpis a third-party action — the de-facto standard for PHP CI, but a third-party dependency nonetheless.