Skip to content

Testing

ichinya edited this page Nov 20, 2026 · 1 revision

Documentation migrated on 2026-11-20 from README.md at 128ed79c243f. Original bytes. Capture-time statuses and limitations are retained.

Testing and validation

Comparing with Larastan

See the Wiki benchmark summary and complete report index for comparisons, observations and limitations.

Larastan is an independent reference for Laravel behavior. Its code and PHPStan extensions are not copied into this package. Our providers use Mago's native PHP extension SDK; comparison results guide their development and verification.

php scripts/compare.php --project=C:/projects/laravel-app

The test application must have Mago and Larastan installed, a phpstan.neon configuration (or a dist variant), and a working Laravel bootstrap. The script runs the tools through the current PHP executable using the application's dependencies. It leaves application configuration, source files, and baselines unchanged. Analyzers may write their own caches; Larastan boots the Laravel container.

The runs execute sequentially:

  1. Larastan with the application configuration.
  2. Larastan at the same level, with configuration-level ignoreErrors cleared.
  3. Larastan at the maximum level, with those suppressions cleared.
  4. Mago on the source paths from the PHPStan configuration.
  5. Both analyzers on tests/fixtures/analysis/eloquent.php: explicit query(), magic where(), a misspelled method, a missing argument, and an invalid argument.

Reports are stored in var/comparisons/<project-name>/<UTC-timestamp>/, which Git ignores. Override the directory with --output. comparison.md contains the overview; summary.json records versions, paths, levels, diagnostic codes, and exit statuses. Raw JSON and normalized diagnostics are saved separately for each run. mago-only-location-candidates.json lists Mago diagnostics on lines without a Larastan max diagnostic. These are candidates for investigation: matching line numbers do not establish equivalent meaning, and the absence of a Larastan diagnostic does not prove a Mago false positive. Each tool's own exclusions and source annotations remain in effect.

Bootstrap errors and internal PHPStan failures abort the comparison; an incomplete run cannot count as a successful check with zero errors. On the first Windows run, php artisan package:discover may be needed to prevent parallel Larastan processes from attempting to create a missing package manifest at the same time.

Package checks

PHP 8.2+, Composer 2, Mago ^1.48.1, PHP-Parser ^5.8, Doctrine Inflector ^2.1.

composer check

This validates Composer metadata and runs every integration script registered in composer.json. Individual scripts can also be run directly while developing.

composer test:framework-native-contracts runs the focused native framework and PHP contract checks, including LF/CRLF source, changed framework declarations and retained diagnostics.

Some integration scripts leave generated workspaces in var/compatibility-* for inspection. Completed workspaces can be deleted when their detailed reports are no longer needed; subsequent runs create fresh directories. Other files in var, including comparison reports and research scripts, should be assessed separately. var and the local .repowise index are excluded from Git and package archives.

Installer tests cover configuration creation, custom vendor directories, repeated installation, preservation of all eight user configuration variants, and fallback source paths. tests/preset.php runs the real Mago executable and checks Laravel casts and validation rules, visible secret warnings, a nested loop in finally, eval in tests, and failures for eval in application code and invalid syntax. Install dependencies first. To use an external executable, set MAGO_BINARY to a native executable on Windows or to the Composer PHP script at vendor/bin/mago.

tests/analyzer.php runs the real Mago analyzer and extension worker against isolated framework declarations. It checks magic calls, chained and callback model types, named arguments, invalid calls, and fallback for custom behavior. Use the comparison script with a Laravel application to verify the installed framework.

tests/properties.php exercises the real analyzer with migrations outside the host file set, without .env or application bootstrap. It covers property contracts, schema changes, relationships, inherited/trait metadata, invalid accesses and writes, additional migration directories, paths with spaces, concurrent worker requests, fresh metadata on subsequent runs, and visible parse failures. Fixture PHP remains in .stub files in the package so it cannot shadow the installed Laravel framework.

tests/migration-locals.php checks scalar migration preparation, generated columns, schema changes, nullable types, unknown properties and invalid writes through real Mago. It also verifies conservative handling of references, captured variables, dynamic calls and schema branches, without executing migrations or loading .env.

tests/predicates.php checks predicate chains, native argument validation, scope precedence, installed signature changes and declaration priority through real Mago. It includes a provider-disabled comparison and preserves errors for nullable results, unknown properties and invalid writes, without application bootstrap or a database.

tests/relation-methods.php checks relationship generic inference, inherited and late-static model targets, PHPDoc priority, factory overrides and installed contract changes through real Mago. It compares native behavior with the provider disabled, rereads changed source on a new run, and keeps bootstrap and constructor execution traps in an isolated workspace without .env or a database.

tests/factories.php checks concrete factory discovery, count state through chains and variables, single and collection results, named arguments, custom declarations, unknown state and branch unions, protected properties, and native negative cases. Factory fixtures contain execution traps and require no environment file or database.

tests/find.php exercises model and builder lookups, nullable and collection branches, Arrayable, union and unpacked identifiers, first-class callables, native argument validation, inheritance, PHPDoc priority and custom behavior. The real worker analyzes isolated declarations without loading an application.

tests/create.php checks model creation and native builder calls, inherited and late-static results, argument errors, fresh property types, custom declarations and callable references. A second worker run changes the fixture's builder signature to verify version-specific callback support and unavailable methods. The isolated project has no environment file or database and contains execution traps for model construction and application bootstrap.

tests/validation.php checks complete validated arrays, null and named keys, unknown field values, native argument errors, inheritance, overrides and PHPDoc priority. A fresh worker run verifies a more precise framework return contract. The isolated project contains execution traps and needs no environment file or database; only the scenario file is analyzed, with request declarations included as dependencies.

tests/queries.php checks model reads, sorting chains, aggregates, concrete model and collection types, nullable results, invalid returns and arguments, overrides and scope collisions. A fresh worker run verifies changed sorting direction and count contracts, plus unavailable methods. Only the scenario file is analyzed; framework and model declarations are dependencies. The workspace has a path with spaces, concurrent workers, execution traps, and no environment file or database.

A real Composer path repository installation was also checked in an isolated Windows project: automatic configuration creation, native vendor/bin/mago.bat lint, Laravel integration, an application rule override, configuration preservation on repeated composer install, and a nonzero exit status for invalid PHP. That check used Mago 1.48.1; a full Laravel CI run was not performed.

Publication policy

Executable tests, fixture inputs, expected diagnostic oracles and reproducible runners stay in the source repository. Captured measurements, pass/fail observations and historical verification reports belong in this Wiki, with source commits and preserved limitations. Results are historical evidence, not a current gate verdict.

Clone this wiki locally