Upgrading a shared capability in two sites one at a time

Two minimal PHP/Composer fixtures adopt a version sequentially: record their composition, verify the other consumer stays unchanged and restore source with its lock.

One replaced section and a retained previous part suggest a gradual upgrade with a defined way back.
One replaced section and a retained previous part suggest a gradual upgrade with a defined way back.

A shared library has a new version, but two sites do not have to receive it simultaneously. One is ready to use the new behavior while the other retains its familiar scenario. This is a normal system state when each consumer's code, configuration, dependencies, and verified outcome are known.

Problems arise when “the package has been upgraded” is treated as an answer about every site at once. Releasing the library, installing it in the first application, and accepting it in the second are distinct events. Similarly, restoring an older library version does not always restore the application to its previous working state.

Keep article_demo as one Symfony project. In this dependency experiment, A and B are disposable minimal PHP/Composer fixtures with their own locks and vendor directories. They are not Symfony sites and have no Kernel or container. We check local compositions rather than deployment or rollback of working sites.

Two consumers and one small promise

A hypothetical journal displays Field notes, while a catalog displays Copper lamp. Both use demo-lab/card-label, but each has its own page-scenario class, configuration, and separate vendor/ directory. The package name was invented for the example; it does not identify an internal platform library.

Version 1.0.0 contains this class:

<?php

declare(strict_types=1);

namespace DemoLab\CardLabel;

final class CardLabel
{
    public function format(string $title): string
    {
        $title = trim($title);
        if ($title === '') {
            throw new \InvalidArgumentException('A title must not be empty.');
        }
        return $title;
    }
}

The contract is narrow. Leading and trailing characters recognized by PHP's trim() are removed from the title. The result must remain nonempty; otherwise, the method throws InvalidArgumentException. Spaces inside the title remain unchanged. This is neither general Unicode normalization nor HTML escaping. The PHP manual defines the exact behavior of trim().

Each fixture’s SiteHeadline receives CardLabel through its constructor. The journal calls format(' Field notes '), while the catalogue calls format(' Copper lamp '). bin/headline.php loads vendor/autoload.php, constructs SiteHeadline(new CardLabel()) and prints the result. It is plain PHP without Symfony Console or a DI container.

Both initially require the exact teaching version 1.0.0. That makes version selection easier to observe in the experiment. Real applications can use a different policy for allowed ranges; it does not replace the particular dependency set recorded in a lock file.

A new capability preserves the old call

Version 1.1.0 retains format() and adds a method:

    public function withPrefix(string $title, string $prefix): string
    {
        return $prefix . $this->format($title);
    }

The journal wants to display Journal: Field notes, so its new code will call withPrefix(). The catalog will continue using format(). The new method adds no translations, HTML, or storage access; the consumer supplies the prefix as an ordinary string.

This change is intended as a compatible extension: the old call should preserve its return type, empty-value handling, and trimming behavior. Given a declared public API, SemVer associates a compatible feature addition with a minor version. The number 1.1.0 does not verify compatibility automatically; examples must exercise the old promises again.

The class is declared final for this reason: the exercise has no third-party subclasses with a method of the same name. Adding a method to an extensible library would need a broader analysis. Compatibility is always assessed relative to the permitted ways of using the API.

An adoption matrix instead of one flag

The labels L_A0, L_A1, L_B0, and L_B1 in the table are symbolic names for future lock snapshots, not fabricated checksums. They can be associated with exact bytes only after Composer actually runs.

Experiment state Journal A Catalog B What to check
Baseline Old code, 1.0.0, L_A0 Old code, 1.0.0, L_B0 Both familiar headlines
New library in A only Old code, 1.1.0, L_A1 Unchanged A's old scenario still works and B is unchanged
A uses the new method New code, 1.1.0, L_A1 Unchanged Only the journal has a prefix
Separate restoration rehearsal for A Copy of old code with L_A0 Unchanged The previous journal can be reproduced in a new directory
B accepts the new library New code, 1.1.0, L_A1 Old code, 1.1.0, L_B1 Both local scenarios work with different API usage

Two rows containing different versions are not inherently an error. They describe a controlled intermediate state. An unknown combination is the danger: for example, new journal code with a library that does not yet contain the required method.

The separate restoration rehearsal does not switch traffic or restart a server. It creates a new local directory with the previous composition and checks it. Afterwards, the original upgraded A remains available for the final comparison with B.

Preparing an isolated environment

Create two minimal Composer fixtures with PHP 8.4+ and PSR-4 for local App\ classes. ZIP artifacts need ext-zip. example/run-lab.sh prepares sources, archives and consumers and runs the complete matrix; the fragments below explain its steps. Keep working application configuration and data out of the exercise.

The complete example/run-lab.sh also needs Python 3, tar and cmp: generating artifacts and state records, taking snapshots and comparing unchanged compositions are part of the exercise.

The two teaching-package versions are delivered as immutable ZIP archives through a Composer artifact repository. Each has its own composer.json with a version, a PHP require, and a PSR-4 mapping from DemoLab\CardLabel\ to src/. The ZIP extension is needed for local artifacts. Register the source in both root applications.

ADOPTION_LAB="$(mktemp -d)"
for fixture in site-a site-b; do
    mkdir "$ADOPTION_LAB/$fixture"
    cat > "$ADOPTION_LAB/$fixture/composer.json" <<JSON
{
    "type": "project",
    "license": "proprietary",
    "require": {"php": ">=8.4"},
    "autoload": {"psr-4": {"App\\\\": "src/"}}
}
JSON
done

Prepare the archives in a separate directory. After registering it, both applications run composer require 'demo-lab/card-label:1.0.0'. This experiment uses no path repository or symlink: the installed package must be a copy of an artifact. Otherwise, changing the source could alter B before its explicit upgrade.

Before starting, retain each consumer's source, configuration, composer.json, composer.lock. Record artifact contents, checksums, and actual tool versions separately. Data consists of string fixtures; there is no database or external side effect.

Upgrade A first, then let B adopt

Run the following inside A's directory:

composer require 'demo-lab/card-label:1.1.0'
composer validate --strict --no-check-publish --no-check-all
composer check-platform-reqs
php bin/headline.php

The --no-check-all flag has a narrow purpose here: the experiment deliberately pins the library to an exact version, and Composer normally warns about overly strict constraints. Combined with --strict, that warning would stop the scenario before the behavior check. The flag suppresses that constraint check; it does not make invalid JSON or an inconsistent lock acceptable. The validate reference distinguishes these options.

The first pass retains the old journal code. The expected result is Field notes, testing the new library against the old consumer. Only afterwards does the local scenario switch to withPrefix(' Field notes ', 'Journal: '), followed by a check of the new headline.

require changes the requirement and may update dependency resolution. Review the complete composer.json and lock diff, including transitive packages and recipe changes if any occur. Naming one package in a command does not prove that only its files changed. Command modes are described in the Composer reference.

After A is upgraded, check B. Seeing the same headline is insufficient: that scenario could conceal a dependency change. Compare hashes of the lock files, requirements, local code, and installed CardLabel.php with their baseline values. The conclusion “B was unchanged” then has a concrete subject to verify.

Only then does B receive 1.1.0. Its local code retains the old format() call, so Copper lamp remains the expected result. Check the journal again with its prefix. If those two scenarios are actually observed to succeed, they support these particular combinations rather than every possible client of the library.

Why reverting only the dependency is insufficient

Once the journal adopts withPrefix(), its code is no longer compatible with 1.0.0. For a controlled failure, copy upgraded A into a third disposable directory and restore only the old library version there. The expected result is the specific missing-new-method error.

The lab verifier separates this case from other errors: it establishes that withPrefix() is absent, calls the new consumer code, and checks that the error refers to that method. A failed installation, container failure, or another error does not establish that the intended incompatibility was reproduced.

A correct rehearsal restores A's entire previous composition into a new directory. Run composer install with the retained lock there rather than resolving dependencies again through update. With a consistent lock, Composer installs the previously selected versions. Then verify the old scenario and compare checksums of the restored source and dependency.

This also restores local code that no longer requires the new API capability. A restored lock without the old code would preserve the incompatibility; old code without the correct lock would preserve uncertainty about dependencies. Configuration belongs to the same composition even when it did not change in this particular exercise.

The boundary that requires a different plan

The exercise performs no database writes, queues messages, caches a new format, or calls external services. Restoring local files is therefore sufficient for its limited scenario. The rehearsal establishes nothing about recovering real data or reversing an external action.

If the new version wrote a format that the old version cannot read, the previous lock does not restore data compatibility. If a message or payment request was sent, old code does not “send it back.” A separate plan must define a compatible transition, continued support for old readers, a compensating action, or a decision to move forward with another fix instead of rolling back.

Even this simple model needs old artifacts to remain available. An exact lock that points to a deleted local ZIP is not a self-contained archive of the program. Reproduction also depends on the corresponding bytes being accessible.

Sequential adoption is useful because every step has a specific consumer and a narrow acceptance criterion. A library's success is not automatically credited to every site. For A and B independently, the composition they use, the scenario they check, and the previous composition they can actually restore remain explicit.

  1. Conformance How one fix to a shared foundation reaches sites
  2. Vendors & Packages A package works in the project: why that is not enough for a separate release
  3. Architecture The cost of a shared foundation: assessing changes without invented savings percentages
  4. Platform Engineering Consumer contract tests: catch a break before upgrading the site

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article