Skip to content

feat: add an orchestration layer for testing packages - #10727

Open
paulbalandan wants to merge 1 commit into
codeigniter4:4.8from
paulbalandan:package-orchestrator
Open

paulbalandan wants to merge 1 commit into
codeigniter4:4.8from
paulbalandan:package-orchestrator

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description
Libraries that supplement CodeIgniter have no standard way to replicate an appstarter environment in their tests. Each package copies the same <const> block into phpunit.xml.dist, points CONFIGPATH at vendor/codeigniter4/framework/app/Config, and fakes everything else in tests/_support. A customised app/, a .env file, or a real spark run cannot be tested.

This adds CodeIgniter\Test\Orchestrator\AbstractOrchestrator. A package extends it, implements getPackageRoot(), and gets a throwaway skeleton built from the installed framework:

  • build() copies app, public, writable and spark from the framework, points Paths.php at its system directory, writes a .env, shares the package's autoloader through a vendor/autoload.php shim, mirrors the fixture directories, then calls afterBuild().
  • boot() builds the skeleton, defines the path constants against it, and loads system/Test/bootstrap.php, so CIUnitTestCase tests run unchanged against it.
  • spark() runs the skeleton's spark in a separate process and returns a SparkResult with the exit code, stdout, stderr and timedOut. It accepts stdin, environment overrides and a timeout.
  • write(), delete() and clean() change or remove the skeleton. They refuse paths that leave it, including through .. and symlinks.
  • Subclasses can override getFixtures(), getEnv(), getPath(), getFrameworkPath() and afterBuild().

Parallel runs get separate skeletons from ORCHESTRATOR_TEST_TOKEN, or from TEST_TOKEN as set by ParaTest.

Not covered: starting FrankenPHP for Worker Mode. The user guide shows how to publish the worker files with worker:install from afterBuild().

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added the 4.8 PRs that target the `4.8` branch. label Nov 5, 2026
@neznaika0

Copy link
Copy Markdown
Contributor

Have you looked at the forum? This is a very useful feature; I haven’t added it to the framework yet, as such innovations aren’t always added to production.
I’ll take a closer look later.

@neznaika0 neznaika0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t fully understand the entire process, but I grasped the main idea.
All my tests passed on Arch.

  1. The reason for using two vendor/autoload.php files is unclear.
  2. The documentation should describe the limitations — the current version specified in the project is being tested. That to test another version, you need a copy of the framework in some folder.
  3. I tried to launch spark directly after creation, but nothing happens. Is this correct?
orchestrator/$ ORCHESTRATOR_FLOOD=1 php spark orchestrator:pro
be 

CodeIgniter v4.8.0-dev Command Line Tool - Server Time: 2026-11-05 19:26:58 UTC+00:00

That’s all for now; we need to try it with a real package.

Comment thread docs/testing/packages.md

## Defining an Orchestrator

Extend `CodeIgniter\Test\Orchestrator\AbstractOrchestrator` and implement `getPackageRoot()`:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to specify where the test file with this code will be located. Although I’m a more experienced user, it’s not immediately clear where to start

use FilesystemIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RuntimeException;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Framework has CodeIgniter\Exceptions\RuntimeException

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants