Skip to content

Commit

Permalink
Setup laravel 11 fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoehaines committed Jun 7, 2024
1 parent b86e08a commit f071b59
Show file tree
Hide file tree
Showing 20 changed files with 387 additions and 4 deletions.
20 changes: 20 additions & 0 deletions features/fixtures/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ services:
- target: 8000
published: 61310

laravel11:
build:
context: laravel11
args:
- PHP_VERSION
environment:
- BUGSNAG_API_KEY
- BUGSNAG_ENDPOINT
- BUGSNAG_SESSION_ENDPOINT
- BUGSNAG_CAPTURE_SESSIONS
- BUGSNAG_USE_CUSTOM_GUZZLE
- BUGSNAG_REGISTER_OOM_BOOTSTRAPPER
- BUGSNAG_DISCARD_CLASSES
- BUGSNAG_REDACTED_KEYS
- BUGSNAG_QUERY
restart: "no"
ports:
- target: 8000
published: 61311

laravel-latest:
build:
context: laravel-latest
Expand Down
23 changes: 23 additions & 0 deletions features/fixtures/laravel11/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ARG PHP_VERSION
FROM php:$PHP_VERSION

RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
unzip \
wget \
zip

WORKDIR /app

COPY . .
COPY --from=composer /usr/bin/composer /usr/local/bin/composer

RUN cp .env.example .env
RUN composer install --no-dev
RUN php artisan key:generate

# create database & apply migrations
RUN touch database/database.sqlite && php artisan migrate --no-interaction

CMD php -S 0.0.0.0:8000 -t public
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Http\Controllers;

use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
use Exception;

class TestController extends Controller
{
public function unhandledException()
{
throw new Exception('Crashing exception!');
}

public function unhandledError()
{
foo();
}

public function handledException()
{
Bugsnag::notifyException(new Exception('Handled exception'));

return 'done';
}

public function handledError()
{
Bugsnag::notifyError('Handled error', 'This is a handled error');

return 'done';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Http\Middleware;

use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
use Closure;

class HandledMiddlewareErr
{
public function handle($request, Closure $next)
{
Bugsnag::notifyError('Handled middleware error', 'This is a handled error');
return $next($request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Http\Middleware;

use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
use Closure;
use Exception;

class HandledMiddlewareEx
{
public function handle($request, Closure $next)
{
Bugsnag::notifyException(new Exception('Handled middleware exception'));
return $next($request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Http\Middleware;

use Closure;

class UnhandledMiddlewareErr
{
public function handle($request, Closure $next)
{
foo();
return $next($request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Exception;

class UnhandledMiddlewareEx
{
public function handle($request, Closure $next)
{
throw new Exception('Unhandled middleware exception');
return $next($request);
}
}
29 changes: 29 additions & 0 deletions features/fixtures/laravel11/app/Jobs/HandledJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Jobs;

use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class HandledJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Bugsnag::leaveBreadcrumb(__METHOD__);

Bugsnag::notifyException(new Exception('Handled :)'));
}
}
29 changes: 29 additions & 0 deletions features/fixtures/laravel11/app/Jobs/UnhandledJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Jobs;

use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use RuntimeException;

class UnhandledJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Bugsnag::leaveBreadcrumb(__METHOD__);

throw new RuntimeException('uh oh :o');
}
}
32 changes: 30 additions & 2 deletions features/fixtures/laravel11/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

namespace App\Providers;

use Illuminate\Support\Facades\Queue;
use Illuminate\Support\ServiceProvider;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
use Illuminate\Queue\Events\JobExceptionOccurred;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -11,14 +16,37 @@ class AppServiceProvider extends ServiceProvider
*/
public function register(): void
{
//
if (!getenv('BUGSNAG_USE_CUSTOM_GUZZLE')) {
return;
}

$this->app->singleton('bugsnag.guzzle', function ($app) {
$handler = \GuzzleHttp\HandlerStack::create();
$handler->push(\GuzzleHttp\Middleware::mapRequest(function ($request) {
return $request->withHeader('X-Custom-Guzzle', 'yes');
}));

return new \GuzzleHttp\Client(['handler' => $handler]);
});
}

/**
* Bootstrap any application services.
*/
public function boot(): void
{
//
Bugsnag::leaveBreadcrumb(__METHOD__);

Queue::before(function (JobProcessing $event) {
Bugsnag::leaveBreadcrumb('before');
});

Queue::after(function (JobProcessed $event) {
Bugsnag::leaveBreadcrumb('after');
});

Queue::exceptionOccurred(function (JobExceptionOccurred $event) {
Bugsnag::leaveBreadcrumb('exceptionOccurred');
});
}
}
10 changes: 9 additions & 1 deletion features/fixtures/laravel11/bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
<?php

use Illuminate\Foundation\Application;
use Bugsnag\BugsnagLaravel\OomBootstrapper;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

(new OomBootstrapper())->bootstrap();

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
$middleware->alias([
'unMidEx' => \App\Http\Middleware\UnhandledMiddlewareEx::class,
'unMidErr' => \App\Http\Middleware\UnhandledMiddlewareErr::class,
'hanMidEx' => \App\Http\Middleware\HandledMiddlewareEx::class,
'hanMidErr' => \App\Http\Middleware\HandledMiddlewareErr::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
//
Expand Down
1 change: 1 addition & 0 deletions features/fixtures/laravel11/bootstrap/providers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

return [
Bugsnag\BugsnagLaravel\BugsnagServiceProvider::class,
App\Providers\AppServiceProvider::class,
];
10 changes: 10 additions & 0 deletions features/fixtures/laravel11/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@
"description": "The skeleton application for the Laravel framework.",
"keywords": ["laravel", "framework"],
"license": "MIT",
"repositories": [
{
"type": "path",
"url": "bugsnag-laravel",
"options": {
"symlink": false
}
}
],
"require": {
"php": "^8.2",
"bugsnag/bugsnag-laravel": "dev-main as 99.99.99",
"laravel/framework": "^11.9",
"laravel/tinker": "^2.9"
},
Expand Down
6 changes: 6 additions & 0 deletions features/fixtures/laravel11/config/app.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Illuminate\Support\Facades\Facade;

return [

/*
Expand Down Expand Up @@ -123,4 +125,8 @@
'store' => env('APP_MAINTENANCE_STORE', 'database'),
],

'aliases' => Facade::defaultAliases()->merge([
'Bugsnag' => Bugsnag\BugsnagLaravel\Facades\Bugsnag::class,
])->toArray(),

];
6 changes: 5 additions & 1 deletion features/fixtures/laravel11/config/logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@

'stack' => [
'driver' => 'stack',
'channels' => explode(',', env('LOG_STACK', 'single')),
'channels' => ['single', 'bugsnag'],
'ignore_exceptions' => false,
],

'bugsnag' => [
'driver' => 'bugsnag',
],

'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
Expand Down
12 changes: 12 additions & 0 deletions features/fixtures/laravel11/resources/views/handlederror.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body>
<?php app('bugsnag')->notifyError("Handled error", "This is a handled error") ?>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body>
<?php app('bugsnag')->notifyException(new Exception("Handled view exception")) ?>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body>
<?php foo() ?>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body>
<?php throw new Exception("Unhandled exception") ?>
</body>
</html>
Loading

0 comments on commit f071b59

Please sign in to comment.