diff --git a/.ci/patches/Dockerfile.patch b/.ci/patches/Dockerfile.patch new file mode 100644 index 00000000..be7db5eb --- /dev/null +++ b/.ci/patches/Dockerfile.patch @@ -0,0 +1,22 @@ +diff --git a/Dockerfile b/Dockerfile +new file mode 100644 +index 0000000..ecc7d44 +--- /dev/null ++++ b/Dockerfile +@@ -0,0 +1,16 @@ ++FROM php:latest ++ ++RUN apt-get update && \ ++ apt-get install -y --no-install-recommends \ ++ git \ ++ unzip \ ++ wget \ ++ zip ++ ++WORKDIR /app ++ ++COPY . . ++ ++RUN php artisan key:generate ++ ++CMD php -S 0.0.0.0:8000 server.php diff --git a/.ci/patches/logging.patch b/.ci/patches/logging.patch new file mode 100644 index 00000000..e570946b --- /dev/null +++ b/.ci/patches/logging.patch @@ -0,0 +1,20 @@ +diff --git a/config/logging.php b/config/logging.php +index 088c204..107a3c7 100644 +--- a/config/logging.php ++++ b/config/logging.php +@@ -37,10 +37,14 @@ return [ + 'channels' => [ + 'stack' => [ + 'driver' => 'stack', +- 'channels' => ['single'], ++ 'channels' => ['single', 'bugsnag'], + 'ignore_exceptions' => false, + ], + ++ 'bugsnag' => [ ++ 'driver' => 'bugsnag' ++ ], ++ + 'single' => [ + 'driver' => 'single', + 'path' => storage_path('logs/laravel.log'), diff --git a/.ci/patches/middleware.patch b/.ci/patches/middleware.patch new file mode 100644 index 00000000..645e5140 --- /dev/null +++ b/.ci/patches/middleware.patch @@ -0,0 +1,98 @@ +diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php +index 36ced13..71cc168 100644 +--- a/app/Http/Kernel.php ++++ b/app/Http/Kernel.php +@@ -62,5 +62,9 @@ class Kernel extends HttpKernel + 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, + 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, + 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, ++ 'unMidEx' => \App\Http\Middleware\UnhandledMiddlewareEx::class, ++ 'unMidErr' => \App\Http\Middleware\UnhandledMiddlewareErr::class, ++ 'hanMidEx' => \App\Http\Middleware\HandledMiddlewareEx::class, ++ 'hanMidErr' => \App\Http\Middleware\HandledMiddlewareErr::class, + ]; + } +diff --git a/app/Http/Middleware/HandledMiddlewareErr.php b/app/Http/Middleware/HandledMiddlewareErr.php +new file mode 100644 +index 0000000..f10e6d5 +--- /dev/null ++++ b/app/Http/Middleware/HandledMiddlewareErr.php +@@ -0,0 +1,15 @@ ++ Illuminate\Support\Facades\Validator::class, + 'View' => Illuminate\Support\Facades\View::class, + ++ 'Bugsnag' => Bugsnag\BugsnagLaravel\Facades\Bugsnag::class, ++ + ], + + ]; diff --git a/.ci/patches/test-controller.patch b/.ci/patches/test-controller.patch new file mode 100644 index 00000000..f43f7caf --- /dev/null +++ b/.ci/patches/test-controller.patch @@ -0,0 +1,39 @@ +diff --git a/app/Http/Controllers/TestController.php b/app/Http/Controllers/TestController.php +new file mode 100644 +index 0000000..35978b7 +--- /dev/null ++++ b/app/Http/Controllers/TestController.php +@@ -0,0 +1,33 @@ ++ ++ ++ ++ ++ ++ ++ Laravel ++ ++ ++ notifyError("Handled error", "This is a handled error") ?> ++ ++ +diff --git a/resources/views/handledexception.blade.php b/resources/views/handledexception.blade.php +new file mode 100644 +index 0000000..7de6e66 +--- /dev/null ++++ b/resources/views/handledexception.blade.php +@@ -0,0 +1,12 @@ ++ ++ ++ ++ ++ ++ ++ Laravel ++ ++ ++ notifyException(new Exception("Handled view exception")) ?> ++ ++ +diff --git a/resources/views/unhandlederror.blade.php b/resources/views/unhandlederror.blade.php +new file mode 100644 +index 0000000..91bf125 +--- /dev/null ++++ b/resources/views/unhandlederror.blade.php +@@ -0,0 +1,12 @@ ++ ++ ++ ++ ++ ++ ++ Laravel ++ ++ ++ ++ ++ +diff --git a/resources/views/unhandledexception.blade.php b/resources/views/unhandledexception.blade.php +new file mode 100644 +index 0000000..c0ee78f +--- /dev/null ++++ b/resources/views/unhandledexception.blade.php +@@ -0,0 +1,12 @@ ++ ++ ++ ++ ++ ++ ++ Laravel ++ ++ ++ ++ ++ diff --git a/.ci/patches/web-routes.patch b/.ci/patches/web-routes.patch new file mode 100644 index 00000000..d99df7f4 --- /dev/null +++ b/.ci/patches/web-routes.patch @@ -0,0 +1,50 @@ +diff --git a/routes/web.php b/routes/web.php +index b130397..4b89d73 100644 +--- a/routes/web.php ++++ b/routes/web.php +@@ -1,5 +1,6 @@ + middleware('unMidEx'); ++Route::get('/unhandled_middleware_error', function () { ++})->middleware('unMidErr'); ++Route::get('/handled_middleware_exception', function () { ++})->middleware('hanMidEx'); ++Route::get('/handled_middleware_error', function () { ++})->middleware('hanMidErr'); ++ ++Route::view('/unhandled_view_exception', 'unhandledexception'); ++Route::view('/unhandled_view_error', 'unhandlederror'); ++Route::view('/handled_view_exception', 'handledexception'); ++Route::view('/handled_view_error', 'handlederror'); diff --git a/.ci/setup-laravel-dev-fixture.sh b/.ci/setup-laravel-dev-fixture.sh new file mode 100755 index 00000000..dd882ecc --- /dev/null +++ b/.ci/setup-laravel-dev-fixture.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env sh + +set -e + +cd features/fixtures + +rm -rf laravel-latest + +# Ignore dev dependencies because we don't need them to run the Maze Runner tests +# and they will only introduce more failure points +composer create-project laravel/laravel laravel-latest --no-dev + +cd laravel-latest + +composer require 'laravel/framework:dev-master as 8' --update-with-dependencies --no-update +composer require bugsnag/bugsnag-laravel --no-update + +composer update --no-dev + +printf "\nCreated Laravel project using these versions:\n" + +composer show --direct + +printf "\nApplying patches...\n" + +for patch in ../../../.ci/patches/*.patch; do + patch -p1 < "$patch" +done diff --git a/.gitattributes b/.gitattributes index 113d33f7..69a25630 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,9 +3,11 @@ /example export-ignore /features export-ignore /tests export-ignore +/.ci export-ignore /.editorconfig export-ignore /.gitattributes export-ignore /.gitignore export-ignore +/.github export-ignore /.styleci.yml export-ignore /.travis.yml export-ignore /CONTRIBUTING.md export-ignore @@ -13,4 +15,3 @@ /README.md export-ignore /Makefile export-ignore /phpunit.xml.dist export-ignore -/.github export-ignore diff --git a/.gitignore b/.gitignore index bf36c37b..adf61ba6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ Gemfile.lock maze_output .phpunit.result.cache +/features/fixtures/laravel-latest/* +!/features/fixtures/laravel-latest/.gitignore diff --git a/.travis.yml b/.travis.yml index 2db94bd7..869b476f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,124 +1,170 @@ language: php +stages: + # Run tests against unstable Laravel versions for builds triggered by a cron + - name: Unstable + if: type = cron + - Canary + - Test + - Maze Runner + matrix: include: - php: 5.5.9 dist: trusty env: LARAVEL_VERSION=5.1.* + stage: Canary - php: 5.5 dist: trusty env: LARAVEL_VERSION=5.1.* + stage: Canary - php: 5.5 dist: trusty env: LARAVEL_VERSION=5.2.* + stage: Canary - php: 5.6 dist: xenial env: LARAVEL_VERSION=5.1.* + stage: Test - php: 5.6 dist: xenial env: LARAVEL_VERSION=5.2.* + stage: Test - php: 5.6 dist: xenial env: LARAVEL_VERSION=5.3.* + stage: Canary - php: 5.6 dist: xenial env: LARAVEL_VERSION=5.4.* + stage: Canary - php: 7.0 dist: xenial env: LARAVEL_VERSION=5.1.* + stage: Test - php: 7.0 dist: xenial env: LARAVEL_VERSION=5.2.* + stage: Test - php: 7.0 dist: xenial env: LARAVEL_VERSION=5.3.* - php: 7.0 dist: xenial env: LARAVEL_VERSION=5.4.* + stage: Test - php: 7.0 dist: xenial env: LARAVEL_VERSION=5.5.* + stage: Canary - php: 7.1 dist: bionic env: LARAVEL_VERSION=5.3.* + stage: Test - php: 7.1 dist: bionic env: LARAVEL_VERSION=5.4.* + stage: Test - php: 7.1 dist: bionic env: LARAVEL_VERSION=5.5.* + stage: Test - php: 7.1 dist: bionic env: LARAVEL_VERSION=5.6.* + stage: Canary - php: 7.1 dist: bionic env: LARAVEL_VERSION=5.7.* + stage: Canary - php: 7.1 dist: bionic env: LARAVEL_VERSION=5.8.* + stage: Canary - php: 7.2 dist: bionic env: LARAVEL_VERSION=5.5.* + stage: Test - php: 7.2 dist: bionic env: LARAVEL_VERSION=5.6.* + stage: Test - php: 7.2 dist: bionic env: LARAVEL_VERSION=5.7.* + stage: Test - php: 7.2 dist: bionic env: LARAVEL_VERSION=5.8.* + stage: Test - php: 7.2 dist: bionic env: LARAVEL_VERSION=6.0 + stage: Canary - php: 7.2 dist: bionic env: LARAVEL_VERSION=7.0 + stage: Canary - php: 7.2 dist: bionic env: LARAVEL_VERSION=6.* + stage: Test - php: 7.2 dist: bionic env: LARAVEL_VERSION=7.* + stage: Test - php: 7.3 dist: bionic env: LARAVEL_VERSION=5.5.* + stage: Test - php: 7.3 dist: bionic env: LARAVEL_VERSION=5.6.* + stage: Test - php: 7.3 dist: bionic env: LARAVEL_VERSION=5.7.* + stage: Test - php: 7.3 dist: bionic env: LARAVEL_VERSION=5.8.* + stage: Test - php: 7.3 dist: bionic env: LARAVEL_VERSION=6.* + stage: Test - php: 7.3 dist: bionic env: LARAVEL_VERSION=7.* + stage: Test - php: 7.3 dist: bionic env: LARAVEL_VERSION=8.* + stage: Test - php: 7.4 dist: bionic env: LARAVEL_VERSION=5.8.* + stage: Test - php: 7.4 dist: bionic env: LARAVEL_VERSION=6.0 + stage: Test - php: 7.4 dist: bionic env: LARAVEL_VERSION=7.0 + stage: Test - php: 7.4 dist: bionic env: LARAVEL_VERSION=6.* + stage: Canary - php: 7.4 dist: bionic env: LARAVEL_VERSION=7.* + stage: Canary - php: 7.4 dist: bionic env: LARAVEL_VERSION=8.* + stage: Canary - addons: apt: packages: @@ -131,6 +177,7 @@ matrix: install: bundle install script: bundle exec bugsnag-maze-runner -c env: LARAVEL_FIXTURE=laravel56 + stage: Maze Runner - addons: apt: packages: @@ -143,6 +190,7 @@ matrix: install: bundle install script: bundle exec bugsnag-maze-runner -c env: LARAVEL_FIXTURE=laravel58 + stage: Maze Runner - addons: apt: packages: @@ -155,19 +203,46 @@ matrix: install: bundle install script: bundle exec bugsnag-maze-runner -c env: LARAVEL_FIXTURE=laravel66 + stage: Maze Runner + + - php: 7.4 + dist: bionic + env: LARAVEL_VERSION='8.x-dev as 8' + stage: Unstable + - php: 7.4 + dist: bionic + env: LARAVEL_VERSION='dev-master as 8' + stage: Unstable + - addons: + apt: + packages: + - docker-ce + sudo: required + sevices: + - docker + rvm: 2.4.1 + php: 7.4 + before_install: ruby --version + install: + - bundle install + - ./.ci/setup-laravel-dev-fixture.sh + script: bundle exec bugsnag-maze-runner -c + env: LARAVEL_FIXTURE=laravel-latest + stage: Unstable cache: directories: - $HOME/.composer/cache before_install: - - travis_retry composer require "laravel/framework:${LARAVEL_VERSION}" --no-update - echo "memory_limit=4G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini install: + - composer require "laravel/framework:${LARAVEL_VERSION}" --no-update - if [[ $TRAVIS_PHP_VERSION == 5.5.9 ]]; then travis_retry composer update --no-interaction --prefer-dist --prefer-lowest ; fi - if [[ $TRAVIS_PHP_VERSION != 5.5.9 ]]; then travis_retry composer update --no-interaction --prefer-dist ; fi - - composer show laravel/framework + # Show which versions of our direct dependencies we're using + - composer show --direct script: - make test diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bae6062..f3c52209 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Changelog ========= +## 2.20.1 (2020-10-13) + +* The default value for `filters` in `config/bugsnag.php` is now `null` instead of `['password']`. This allows the default filters from Bugsnag PHP to be used. Existing projects can make the same change to benefit from the new default filters in [Bugsnag PHP v3.23.0](https://github.com/bugsnag/bugsnag-php/releases/tag/v3.23.0) + [#413](https://github.com/bugsnag/bugsnag-laravel/pull/413) + ## 2.20.0 (2020-09-09) ### Enhancements @@ -69,7 +74,7 @@ Changelog ### Bug Fixes -* Changed caching TTL to use DateTime instead. +* Changed caching TTL to use DateTime instead. [Mozammil Khodabacchas](https://github.com/mozammil) [#344](https://github.com/bugsnag/bugsnag-laravel/pull/344) * Update axiom dependency in laravel56 example to remove security vulnerability warning diff --git a/config/bugsnag.php b/config/bugsnag.php index 0eebdb29..d500b515 100644 --- a/config/bugsnag.php +++ b/config/bugsnag.php @@ -77,7 +77,7 @@ | */ - 'filters' => empty(env('BUGSNAG_FILTERS')) ? ['password'] : explode(',', str_replace(' ', '', env('BUGSNAG_FILTERS'))), + 'filters' => empty(env('BUGSNAG_FILTERS')) ? null : explode(',', str_replace(' ', '', env('BUGSNAG_FILTERS'))), /* |-------------------------------------------------------------------------- diff --git a/features/fixtures/docker-compose.yaml b/features/fixtures/docker-compose.yaml index eb885fc8..089143ed 100644 --- a/features/fixtures/docker-compose.yaml +++ b/features/fixtures/docker-compose.yaml @@ -39,3 +39,17 @@ services: - target: 8000 published: 61266 restart: "no" + + laravel-latest: + build: + context: laravel-latest + environment: + - BUGSNAG_API_KEY + - BUGSNAG_ENDPOINT + - BUGSNAG_SESSION_ENDPOINT + - BUGSNAG_CAPTURE_SESSIONS + restart: "no" + ports: + - target: 8000 + published: 61299 + restart: "no" diff --git a/features/fixtures/laravel-latest/.gitignore b/features/fixtures/laravel-latest/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/features/fixtures/laravel-latest/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/features/runtime_versions.feature b/features/runtime_versions.feature index 8910e9bf..b585b3e3 100644 --- a/features/runtime_versions.feature +++ b/features/runtime_versions.feature @@ -15,7 +15,7 @@ Scenario: report for handled event contains runtime version information And the request is a valid for the error reporting API And the event "unhandled" is false And the event "device.runtimeVersions.php" matches "(\d+\.){2}\d+" - And the event "device.runtimeVersions.laravel" matches "(\d+\.){2}\d+" + And the event "device.runtimeVersions.laravel" matches "((\d+\.){2}\d+|\d\.x-dev)" Scenario: report for unhandled event contains runtime version information Given I set environment variable "BUGSNAG_API_KEY" to "a35a2a72bd230ac0aa0f52715bbdc6aa" @@ -28,7 +28,7 @@ Scenario: report for unhandled event contains runtime version information And the request is a valid for the error reporting API And the event "unhandled" is true And the event "device.runtimeVersions.php" matches "(\d+\.){2}\d+" - And the event "device.runtimeVersions.laravel" matches "(\d+\.){2}\d+" + And the event "device.runtimeVersions.laravel" matches "((\d+\.){2}\d+|\d\.x-dev)" Scenario: session payload contains runtime version information Given I set environment variable "BUGSNAG_API_KEY" to "a35a2a72bd230ac0aa0f52715bbdc6aa" @@ -42,4 +42,4 @@ Scenario: session payload contains runtime version information And the request 0 is valid for the session tracking API And the payload has a valid sessions array for request 0 And the payload field "device.runtimeVersions.php" matches the regex "(\d+\.){2}\d+" - And the payload field "device.runtimeVersions.laravel" matches the regex "(\d+\.){2}\d+" + And the payload field "device.runtimeVersions.laravel" matches the regex "((\d+\.){2}\d+|\d\.x-dev)" diff --git a/features/steps/laravel_steps.rb b/features/steps/laravel_steps.rb index c7aef0bf..9a971bc3 100644 --- a/features/steps/laravel_steps.rb +++ b/features/steps/laravel_steps.rb @@ -14,13 +14,13 @@ When(/^I wait for the app to respond on the appropriate port$/) do steps %{ - When I wait for the app to respond on port "#{getLaravelPort}" + When I wait for the app to respond on port "#{fixture_port}" } end When("I navigate to the route {string}") do |route| steps %{ - When I navigate to the route "#{route}" on port "#{getLaravelPort}" + When I navigate to the route "#{route}" on port "#{fixture_port}" } end @@ -29,13 +29,12 @@ assert_includes(values.raw.flatten, desired_value) end -def getLaravelPort +def fixture_port case ENV['LARAVEL_FIXTURE'] - when 'laravel66' - 61266 - when 'laravel58' - 61258 - else - 61256 + when 'laravel-latest' then 61299 + when 'laravel66' then 61266 + when 'laravel58' then 61258 + when 'laravel56' then 61256 + else raise "Unknown laravel fixture '#{ENV['LARAVEL_FIXTURE']}'!" end -end \ No newline at end of file +end diff --git a/features/support/env.rb b/features/support/env.rb index 5194c277..36fea788 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -7,6 +7,8 @@ `composer archive -f zip --dir=#{File.dirname(VENDORED_LIB)} --file=#{File.basename(VENDORED_LIB, '.zip')}` Dir.glob(FIXTURE_DIR + '/laravel*').each do |directory| + next if directory.end_with?('laravel-latest') + FileUtils.cp(VENDORED_LIB, directory + '/bugsnag-laravel.zip') # Remove any locally installed composer deps FileUtils.rm_rf(directory + '/vendor') @@ -18,6 +20,8 @@ parsed_composer = JSON.parse source.read requirements = parsed_composer["require"] Dir.glob(FIXTURE_DIR + '/laravel*').each do |directory| + next if directory.end_with?('laravel-latest') + File.open(directory + '/composer.json.template', 'r') do |template| parsed_template = JSON.parse template.read parsed_template["repositories"][0]["package"]["require"] = requirements diff --git a/features/unhandled_controller.feature b/features/unhandled_controller.feature index 16c82f1b..3da105f4 100644 --- a/features/unhandled_controller.feature +++ b/features/unhandled_controller.feature @@ -32,7 +32,7 @@ Scenario: Unhandled errors are delivered from controllers And the request is a valid for the error reporting API And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa" And the payload field "events" is an array with 1 element - And the exception "errorClass" ends with "FatalThrowableError" + And the exception "errorClass" ends with "Error" And the exception "message" starts with "Call to undefined function" And the exception "message" ends with "foo()" And the event "metaData.request.httpMethod" equals "GET" @@ -56,4 +56,4 @@ Scenario: Sessions are correct in unhandled exceptions from controllers And the request 1 is a valid for the error reporting API And the payload has a valid sessions array for request 0 And the payload field "events.0.session.events.unhandled" equals 1 for request 1 - And the payload field "events.0.session.events.handled" equals 0 for request 1 \ No newline at end of file + And the payload field "events.0.session.events.handled" equals 0 for request 1 diff --git a/features/unhandled_middleware.feature b/features/unhandled_middleware.feature index 839b1624..ea79fdf5 100644 --- a/features/unhandled_middleware.feature +++ b/features/unhandled_middleware.feature @@ -32,7 +32,7 @@ Scenario: Unhandled errors are delivered from middleware And the request is a valid for the error reporting API And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa" And the payload field "events" is an array with 1 element - And the exception "errorClass" ends with "FatalThrowableError" + And the exception "errorClass" ends with "Error" And the exception "message" starts with "Call to undefined function" And the exception "message" ends with "foo()" And the event "metaData.request.httpMethod" equals "GET" @@ -56,4 +56,4 @@ Scenario: Sessions are correct in unhandled exceptions from middleware And the request 1 is a valid for the error reporting API And the payload has a valid sessions array for request 0 And the payload field "events.0.session.events.unhandled" equals 1 for request 1 - And the payload field "events.0.session.events.handled" equals 0 for request 1 \ No newline at end of file + And the payload field "events.0.session.events.handled" equals 0 for request 1 diff --git a/features/unhandled_routing.feature b/features/unhandled_routing.feature index 545814b6..0d62a97d 100644 --- a/features/unhandled_routing.feature +++ b/features/unhandled_routing.feature @@ -32,7 +32,7 @@ Scenario: Unhandled errors are delivered from routing And the request is a valid for the error reporting API And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa" And the payload field "events" is an array with 1 element - And the exception "errorClass" ends with "FatalThrowableError" + And the exception "errorClass" ends with "Error" And the exception "message" equals "Call to undefined function call_foo()" And the event "metaData.request.httpMethod" equals "GET" And the event "app.type" equals "HTTP" @@ -55,4 +55,4 @@ Scenario: Sessions are correct in unhandled exceptions from routing And the request 1 is a valid for the error reporting API And the payload has a valid sessions array for request 0 And the payload field "events.0.session.events.unhandled" equals 1 for request 1 - And the payload field "events.0.session.events.handled" equals 0 for request 1 \ No newline at end of file + And the payload field "events.0.session.events.handled" equals 0 for request 1 diff --git a/src/BugsnagServiceProvider.php b/src/BugsnagServiceProvider.php index fe9a6141..4648a9ec 100644 --- a/src/BugsnagServiceProvider.php +++ b/src/BugsnagServiceProvider.php @@ -36,7 +36,7 @@ class BugsnagServiceProvider extends ServiceProvider * * @var string */ - const VERSION = '2.20.0'; + const VERSION = '2.20.1'; /** * Boot the service provider. diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index 39a54fe3..e6b8d53f 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -6,7 +6,6 @@ use Bugsnag\BugsnagLaravel\MultiLogger; use Bugsnag\BugsnagLaravel\Queue\Tracker; use Bugsnag\Client; -use Bugsnag\Configuration; use Bugsnag\PsrLogger\BugsnagLogger; use Bugsnag\PsrLogger\MultiLogger as BaseMultiLogger; use GrahamCampbell\TestBenchCore\ServiceProviderTrait; @@ -336,4 +335,131 @@ function ($closure) use ($multiLoggerClass) { $app->shouldReceive('alias')->with('bugsnag.multi', $multiLoggerClass)->once(); $provider->register(); } + + public function testFiltersUseDefaultsIfNull() + { + /** @var \Illuminate\Config\Repository $laravelConfig */ + $laravelConfig = $this->app->config; + $bugsnagConfig = $laravelConfig->get('bugsnag'); + + $this->assertNull( + $bugsnagConfig['filters'], + "Expected the default configuration value for 'filters' to be null" + ); + + $client = $this->app->make(Client::class); + $this->assertInstanceOf(Client::class, $client); + + /** @var Client $client */ + $config = $client->getConfig(); + + $this->assertNotEmpty($config->getFilters()); + } + + public function testFiltersUseProvdedValueIfArray() + { + /** @var \Illuminate\Config\Repository $laravelConfig */ + $laravelConfig = $this->app->config; + $bugsnagConfig = $laravelConfig->get('bugsnag'); + $bugsnagConfig['filters'] = ['abc', 'xyz']; + + $laravelConfig->set('bugsnag', $bugsnagConfig); + + $client = $this->app->make(Client::class); + $this->assertInstanceOf(Client::class, $client); + + /** @var Client $client */ + $config = $client->getConfig(); + + $this->assertSame(['abc', 'xyz'], $config->getFilters()); + } + + public function testFiltersUseDefaultsIfNotProvidedAnArray() + { + /** @var \Illuminate\Config\Repository $laravelConfig */ + $laravelConfig = $this->app->config; + $bugsnagConfig = $laravelConfig->get('bugsnag'); + + $bugsnagConfig['filters'] = 'filtering'; + + $laravelConfig->set('bugsnag', $bugsnagConfig); + + $client = $this->app->make(Client::class); + $this->assertInstanceOf(Client::class, $client); + + /** @var Client $client */ + $config = $client->getConfig(); + + $this->assertNotEquals('filtering', $config->getFilters()); + $this->assertNotEmpty($config->getFilters()); + } + + public function testFiltersUseEnvironmentVariableIfProvided() + { + try { + $this->setEnvironmentVariable('BUGSNAG_FILTERS', 'abc, xyz , hello,hi, h e y '); + + // At this point we already have a Laravel app loaded so the environment + // variable won't be picked up. Refreshing the application forces + // the config to re-load so that 'BUGSNAG_FILTERS' is used + $this->refreshApplication(); + + $client = $this->app->make(Client::class); + $this->assertInstanceOf(Client::class, $client); + + /** @var Client $client */ + $config = $client->getConfig(); + + $this->assertSame( + ['abc', 'xyz', 'hello', 'hi', 'hey'], + $config->getFilters() + ); + } finally { + $this->removeEnvironmentVariable('BUGSNAG_FILTERS'); + } + } + + /** + * Set the environment variable "$name" to the given value. + * + * @param string $name + * @param string $value + * + * @return void + */ + private function setEnvironmentVariable($name, $value) + { + // Workaround a PHP 5 parser issue - '$app::VERSION' is valid but + // '$this->app::VERSION' is not + $app = $this->app; + + // Laravel >= 5.8.0 uses "$_ENV" instead of "putenv" by default + if (version_compare($app::VERSION, '5.8.0', '>=')) { + $_ENV[$name] = $value; + } else { + putenv("{$name}={$value}"); + } + } + + /** + * Remove the environment variable "$name" from the environment. + * + * @param string $name + * @param string $value + * + * @return void + */ + private function removeEnvironmentVariable($name) + { + // Workaround a PHP 5 parser issue - '$app::VERSION' is valid but + // '$this->app::VERSION' is not + $app = $this->app; + + // Laravel >= 5.8.0 uses "$_ENV" instead of "putenv" by default + if (version_compare($app::VERSION, '5.8.0', '>=')) { + unset($_ENV[$name]); + } else { + putenv("{$name}"); + } + } }