Install¶
This guide shows how to install friendsofmago/mago-mockery and verify that Mago loads the extension.
Requirements¶
Check that your project meets these version floors:
- PHP 8.1 or newer with
ext-tokenizer carthage-software/mago1.60.2 or newermockery/mockery1.6 or newer
Install the package¶
Run Composer to add the extension as a development dependency:
composer require --dev friendsofmago/mago-mockery
Register the worker in mago.toml¶
Open mago.toml next to composer.json. Add Mockery's library directory to [source] includes and register the bundled worker under [extension-hosts.mockery]:
[source]
includes = ["vendor/mockery/mockery/library"]
[extension-hosts.mockery]
command = ["php", "-d", "xdebug.mode=off", "-d", "pcov.enabled=0", "-d", "memory_limit=512M", "vendor/bin/mago-mockery-worker"]
workers = 1
If [source] includes already contains "vendor", you do not need to list "vendor/mockery/mockery/library" separately. If it does not include "vendor", keep "vendor/mockery/mockery/library" so Mago can read Mockery's interfaces and matcher classes.
Verify the setup¶
Run mago extension validate to confirm that the worker starts and registers its analyzer plugins:
vendor/bin/mago extension validate
Run mago analyze to analyze your test suite with Mockery types active:
vendor/bin/mago analyze
Use vendor/bin/mago rather than a separately installed Mago binary. A version mismatch between the binary and carthage-software/mago in vendor/ can fail with an unsupported protocol version error.
Enable strict mocked method checks¶
To check that literal and higher-order method names exist on the mocked class, add an environment table to [extension-hosts.mockery]:
[extension-hosts.mockery]
command = ["php", "-d", "xdebug.mode=off", "-d", "pcov.enabled=0", "-d", "memory_limit=512M", "vendor/bin/mago-mockery-worker"]
workers = 1
environment = { MAGO_MOCKERY_STRICT_METHODS = "1" }
See Strict mode for rollout details and dynamic method handling.
Handle a non-standard vendor path¶
If mago.toml is not next to vendor/, update the include path and the worker path relative to mago.toml:
[source]
includes = ["../vendor/mockery/mockery/library"]
[extension-hosts.mockery]
command = ["php", "-d", "xdebug.mode=off", "-d", "pcov.enabled=0", "-d", "memory_limit=512M", "../vendor/bin/mago-mockery-worker"]
workers = 1
Next steps¶
- Check every available option in Configuration.
- Inspect worker behavior and autoloader lookup in The worker.
- Share one worker across multiple extensions with Composition.