Skip to content

Add tests for the example processes#6

Merged
Metabor merged 1 commit into
fix/php82-compatibilityfrom
add/tests-and-ci
Jul 15, 2026
Merged

Add tests for the example processes#6
Metabor merged 1 commit into
fix/php82-compatibilityfrom
add/tests-and-ci

Conversation

@Metabor

@Metabor Metabor commented Jul 15, 2026

Copy link
Copy Markdown
Owner

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.disttests/Example/ directory does not exist → Test directory not found, exit 2
.travis.yml targets PHP 5.3, 5.4, 5.5, 5.6, 7.0, hhvm — this project requires 8.2
GitHub Actions none. Zero runs, ever.

The v3.0.0 upgrade even modernised phpunit.xml.dist from <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 paths index.php takes: 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.php shares a single Prepayment instance between both prepayment orders (via NamedCollection::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 Authorize stop failing PREPAYMENT 2, turns the suite red. Changing __toString, getName or removing the echo does not — those are exactly the return values whose signatures #5 touches, plus the console output, which is the only product index.php has.

Verification

Applying this test alone to the current, unfixed master:

exit 255, fatal error

It would have caught April.

With #5 applied: Tests: 6, Assertions: 17 — green. (PHPUnit still appends Deprecations: 2 on 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.yml is 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 with workflow scope, 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-php is a third-party action — the de-facto standard for PHP CI, but a third-party dependency nonetheless.

name: Tests

on:
  push:
  pull_request:

jobs:
  phpunit:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        php: ['8.2', '8.3', '8.4', '8.5']

    name: PHP ${{ matrix.php }}
    steps:
      - uses: actions/checkout@v4

      - uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          coverage: none

      - run: composer install --no-interaction --no-progress

      - run: vendor/bin/phpunit

      # PHPUnit covers the classes; only running the example covers the example.
      - run: php index.php

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.
@Metabor
Metabor merged commit a5315ab into fix/php82-compatibility Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant