When testing Laravel applications, we frequently need to "silence" events, so as not to trigger additional side-effects. Laravel's Event::fake method is useful, but muting a specific model observer is still problematic.
Unobserve takes care of that, making it easy to mute and unmute an observer at will.
Unobserve supports only the latest major version of Laravel. See composer.json for the exact version requirements.
Install it using Composer:
composer require monooso/unobserveFirst, add the CanMute trait to your observer class.
<?php
namespace App\Observers;
use Monooso\Unobserve\CanMute;
class UserObserver
{
use CanMute;
}You can now mute and unmute your observer as needed:
UserObserver::mute();
UserObserver::unmute();Mute all observer events:
UserObserver::mute();Mute specific observer events:
UserObserver::mute('creating');
UserObserver::mute(['creating', 'created']);Unobserve is very stable at this point. If you have any feature ideas please open an issue before doing any work.
Development and testing happen entirely inside Podman containers, driven by the ./dev script. You do not need to install PHP, Composer, or any project dependencies on your machine.
The dev helper script builds a disposable PHP + Composer image for the PHP version you name, mounts your working tree into it, and runs your command. Any changes to composer.json and composer.lock are written back to your disk so they can be committed.
Podman 5.x or later.
The dev script always accepts the target PHP version as the first argument. The first time you run a command with a given PHP version, it builds the image automatically.
| Command | Purpose |
|---|---|
./dev 8.3 |
Open a shell on PHP 8.3 |
./dev 8.3 test |
Run the test suite |
./dev 8.3 lint |
Run Laravel Pint |
./dev 8.3 composer install |
Install dependencies from the lock file |
./dev 8.3 composer update |
Re-resolve dependencies (rewrites composer.lock) |
./dev 8.3 composer outdated |
List outdated packages |
./dev 8.3 php -v |
Run any command in the container |
./dev build 8.3 |
Rebuild the image for a version |
Run ./dev --help for the full reference.
-
Create a branch.
-
Edit
composer.jsonto widen the relevant constraints, e.g."php": "^8.3"and"illuminate/support": "^13.0". -
Re-resolve dependencies against the target PHP version:
./dev 8.3 composer update
-
In the event of a conflict, investigate and iterate:
./dev 8.3 composer why-not laravel/framework 13.0.0 ./dev 8.3 composer require illuminate/support:"^13.0" --no-update ./dev 8.3 composer update -
Run the tests and linter:
./dev 8.3 test ./dev 8.3 lint -
Commit
composer.jsonandcomposer.lock.
Each PHP version keeps its own dependency cache, so several versions can be tested side by side (e.g. ./dev 8.2 test, ./dev 8.3 test) without interfering with each other.
Unobserve is open source software, released under the MIT license.