monooso / unobserve
Mute and unmute Laravel observers at will.
Installs: 300 355
Dependents: 0
Suggesters: 0
Security: 0
Stars: 83
Watchers: 4
Forks: 11
Open Issues: 2
Requires
- php: ^8.2
- illuminate/contracts: ^11.0
- illuminate/support: ^11.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.52
- orchestra/testbench: ^9.0
- phpunit/phpunit: ^11.0
- dev-main
- v6.0.0
- 5.x-dev
- v5.2.0
- v5.1.0
- v5.0.1
- v5.0.0
- 4.x-dev
- v4.0.0
- 3.x-dev
- v3.0.0
- 2.x-dev
- v2.0.2
- v2.0.1
- v2.0.0
- 1.x-dev
- v1.1.1
- v1.1.0
- v1.0.0
- dev-dependabot/composer/composer-fcf7e6b117
- dev-dependabot/composer/laravel/framework-11.31.0
- dev-dependabot/composer/symfony/process-7.1.7
- dev-dependabot/composer/symfony/http-foundation-7.1.7
- dev-update-readme
- dev-laravel-11
This package is auto-updated.
Last update: 2024-11-14 18:55:00 UTC
README
About Unobserve
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.
Requirements and installation
Select the appropriate version of Unobserve from the following table.
Install Unobserve using Composer:
composer require monooso/unobserve
Usage
First, 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 options
Mute all observer events:
UserObserver::mute();
Mute specific observer events:
UserObserver::mute('creating'); UserObserver::mute(['creating', 'created']);
Development
Unobserve is very stable at this point. If you have any feature ideas please open an issue before doing any work.
Here's how to set everything up for local development on Unobserve 1:
- Clone the repository.
- Install the dependencies by running
composer install
. - Install the code quality tools by running
composer install --working-dir=tools/php-cs-fixer
. - Set your Git hooks directory to
.githooks
by runninggit config core.hooksPath .githooks
.
License
Unobserve is open source software, released under the MIT license.