All Projects → timacdonald → Log Fake

timacdonald / Log Fake

Licence: mit
A drop in fake logger for testing with the Laravel framework.

Projects that are alternatives of or similar to Log Fake

Laravel Executor
Configurable code that can be run when installing and updating your web app.
Stars: ✭ 204 (-19.69%)
Mutual labels:  hacktoberfest, laravel
Larastan
⚗️ Adds code analysis to Laravel improving developer productivity and code quality.
Stars: ✭ 3,554 (+1299.21%)
Mutual labels:  hacktoberfest, laravel
Laravelpackage.com
Documentation for LaravelPackage.com: Learn to create Laravel specific PHP packages from scratch, following this open documentation.
Stars: ✭ 214 (-15.75%)
Mutual labels:  hacktoberfest, laravel
Icalendar Generator
Generate calendars in the iCalendar format
Stars: ✭ 193 (-24.02%)
Mutual labels:  hacktoberfest, laravel
Laravel Query Monitor
Simple artisan command to monitoring triggered queries
Stars: ✭ 230 (-9.45%)
Mutual labels:  hacktoberfest, laravel
Librenms
Community-based GPL-licensed network monitoring system
Stars: ✭ 2,567 (+910.63%)
Mutual labels:  hacktoberfest, laravel
Onesignal
OneSignal notifications channel for Laravel
Stars: ✭ 222 (-12.6%)
Mutual labels:  hacktoberfest, laravel
Media Manager
A simple file browser and up-loader for Laravel written in Vue.JS
Stars: ✭ 190 (-25.2%)
Mutual labels:  hacktoberfest, laravel
Tracker
Laravel Stats Tracker
Stars: ✭ 2,638 (+938.58%)
Mutual labels:  laravel, logging
Laravel Craftsman
Laravel Craftsman CLI for easily crafting Laravel assets for any project (artisan make on steroids)
Stars: ✭ 227 (-10.63%)
Mutual labels:  hacktoberfest, laravel
Laravel Datatables Buttons
jQuery DataTables Buttons Plugin for Laravel.
Stars: ✭ 192 (-24.41%)
Mutual labels:  hacktoberfest, laravel
Laravel Admin Starter
A Laravel Admin Starter project with Page Builder, Roles, Impersonation, Analytics, Blog, News, Banners, FAQ, Testimonials and more
Stars: ✭ 240 (-5.51%)
Mutual labels:  hacktoberfest, laravel
Multi Tenant
Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously github.com/hyn/multi-tenant
Stars: ✭ 2,304 (+807.09%)
Mutual labels:  hacktoberfest, laravel
Laravel Surveillance
Put malicious users, IP addresses and anonymous browser fingerprints under surveillance, log the URLs they visit and block malicious ones from accessing the Laravel app.
Stars: ✭ 198 (-22.05%)
Mutual labels:  hacktoberfest, laravel
Nebula
Nebula is a minimalistic and easy to use administration tool for Laravel applications, made with Laravel, Alpine.js, and Tailwind CSS.
Stars: ✭ 190 (-25.2%)
Mutual labels:  hacktoberfest, laravel
Urlhub
URL shortener web application based on the Laravel PHP Framework.
Stars: ✭ 217 (-14.57%)
Mutual labels:  hacktoberfest, laravel
Monica
Personal CRM. Remember everything about your friends, family and business relationships.
Stars: ✭ 15,499 (+6001.97%)
Mutual labels:  hacktoberfest, laravel
Laravel Datatables Html
Laravel DataTables HTML Builder Plugin
Stars: ✭ 188 (-25.98%)
Mutual labels:  hacktoberfest, laravel
Wagonwheel
Offer an online version of your Laravel emails to users.
Stars: ✭ 224 (-11.81%)
Mutual labels:  hacktoberfest, laravel
Gistlog
GistLog - simple, easy blogging based on GitHub gists
Stars: ✭ 237 (-6.69%)
Mutual labels:  hacktoberfest, laravel

Log Fake: a Laravel package by Tim MacDonald

Log fake for Laravel

CI codecov Type coverage Mutation testing badge Total Downloads

A bunch of Laravel facades / services are able to be faked, such as the Dispatcher with Bus::fake(), to help with testing and assertions. This package gives you the ability to fake the logger in your app, and includes the ability to make assertions against channels and stacks introduced in logging overhaul in Laravel 5.6.

Version support

  • PHP: 7.1, 7.2, 7.3, 7.4, 8.0
  • Laravel: 5.6, 5.7, 5.8, 6.0, 7.0, 8.0
  • PHPUnit: 7.0, 8.0, 9.0

Installation

You can install using composer from Packagist.

$ composer require timacdonald/log-fake --dev

Basic usage

<?php

use Illuminate\Support\Str;
use TiMacDonald\Log\LogFake;
use Illuminate\Support\Facades\Log;

//...

Log::swap(new LogFake);

Log::info('Donuts have arrived');

Log::assertLogged('info', function ($message, $context) {
    return Str::contains($message, 'Donuts');
});

Channels

If you are logging to a specific channel in your app, such as Slack with Log::channel('slack')->critical('It is 5pm, go home'), you need to also prefix your assertions in the same manner.

<?php

use TiMacDonald\Log\LogFake;
use Illuminate\Support\Facades\Log;

//...

Log::swap(new LogFake);

Log::channel('slack')->alert('It is 5pm, go home');

Log::channel('slack')->assertLogged('alert'); // ✅ passes

// without the channel prefix...

Log::assertLogged('alert');  // ❌ fails

Stacks

If you are logging to a stack in your app, like with channels, you will need to prefix your assertions. Note that the order of the stack does not matter.

<?php

use TiMacDonald\Log\LogFake;
use Illuminate\Support\Facades\Log;

//...

Log::swap(new LogFake);

Log::stack(['bugsnag', 'sentry'])->critical('Perform evasive maneuvers');


Log::stack(['bugsnag', 'sentry'])->assertLogged('critical');  // ✅ passes

// without the stack prefix...

Log::assertLogged('critical'); // ❌ fails

Available assertions

All assertions are relative to the channel or stack as shown in the previous examples.

assertLogged($level, $callback = null)

<?php

use Illuminate\Support\Str;

Log::assertLogged('info');

Log::channel('slack')->assertLogged('alert');

Log::stack(['bugsnag', 'sentry'])->assertLogged('critical');

// with a callback

Log::assertLogged('info', function ($message, $context) {
    return Str::contains($message, 'Donuts');
});

Log::channel('slack')->assertLogged('alert', function ($message, $context) {
    return Str::contains($message, '5pm');
});

Log::stack(['bugsnag', 'sentry'])->assertLogged('critical', function ($message, $context) {
    return Str::contains($message, 'evasive maneuvers');
});

assertLoggedMessage($level, $message)

<?php

Log::assertLoggedMessage('info', 'User registered');

Log::channel('slack')->assertLoggedMessage('alert', 'It is 5pm, go home');

Log::stack(['bugsnag', 'sentry'])->assertLoggedMessage('critical', 'Perform evasive maneuvers');

assertLoggedTimes($level, $times = 1, $callback = null)

<?php

use Illuminate\Support\Str;

Log::assertLoggedTimes('info', 5);

Log::channel('slack')->assertLoggedTimes('alert', 5);

Log::stack(['bugsnag', 'sentry'])->assertLoggedTimes('critical', 5);

// with a callback

Log::assertLogged('info', 5, function ($message, $context) {
    return Str::contains($message, 'Donuts');
});

Log::channel('slack')->assertLogged('alert', 5, function ($message, $context) {
    return Str::contains($message, '5pm');
});

Log::stack(['bugsnag', 'sentry'])->assertLogged('critical', 5, function ($message, $context) {
    return Str::contains($message, 'evasive maneuvers');
});

assertNotLogged($level, $callback = null)

<?php

use Illuminate\Support\Str;

Log::assertNotLogged('info');

Log::channel('slack')->assertNotLogged('alert');

Log::stack(['bugsnag', 'sentry'])->assertNotLogged('critical');

// with a callback

Log::assertNotLogged('info', function ($message, $context) {
    return Str::contains($message, 'Donuts');
});

Log::channel('slack')->assertNotLogged('alert' , function ($message, $context) {
    return Str::contains($message, '5pm');
});

Log::stack(['bugsnag', 'sentry'])->assertNotLogged('critical', function ($message, $context) {
    return Str::contains($message, 'evasive maneuvers');
});

assertNothingLogged()

<?php

Log::assertNothingLogged();

Log::channel('slack')->assertNothingLogged();

Log::stack(['bugsnag', 'sentry'])->assertNothingLogged();

Credits

And a special (vegi) thanks to Caneco for the logo ✨

Thanksware

You are free to use this package, but I ask that you reach out to someone (not me) who has previously, or is currently, maintaining or contributing to an open source library you are using in your project and thank them for their work. Consider your entire tech stack: packages, frameworks, languages, databases, operating systems, frontend, backend, etc.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].