mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-30 20:51:57 +08:00
Prevented entity "Not Found" events from being logged
- Added testing to cover, which was more hassle than thought since Laravel did not have built in log test helpers, so: - Added Log testing helper. Related to #2110
This commit is contained in:
@ -16,7 +16,10 @@ use BookStack\Entities\Repos\PageRepo;
|
||||
use BookStack\Settings\SettingService;
|
||||
use BookStack\Uploads\HttpFetcher;
|
||||
use Illuminate\Support\Env;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Mockery;
|
||||
use Monolog\Handler\TestHandler;
|
||||
use Monolog\Logger;
|
||||
use Throwable;
|
||||
|
||||
trait SharedTestHelpers
|
||||
@ -69,14 +72,14 @@ trait SharedTestHelpers
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of a user with 'viewer' permissions
|
||||
* @param $attributes
|
||||
* @return mixed
|
||||
* Get an instance of a user with 'viewer' permissions.
|
||||
*/
|
||||
protected function getViewer($attributes = [])
|
||||
protected function getViewer(array $attributes = []): User
|
||||
{
|
||||
$user = Role::getRole('viewer')->users()->first();
|
||||
if (!empty($attributes)) $user->forceFill($attributes)->save();
|
||||
if (!empty($attributes)) {
|
||||
$user->forceFill($attributes)->save();
|
||||
}
|
||||
return $user;
|
||||
}
|
||||
|
||||
@ -277,4 +280,22 @@ trait SharedTestHelpers
|
||||
$this->assertStringStartsWith('You do not have permission to access', $error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a test handler as the logging interface for the application.
|
||||
* Allows capture of logs for checking against during tests.
|
||||
*/
|
||||
protected function withTestLogger(): TestHandler
|
||||
{
|
||||
$monolog = new Logger('testing');
|
||||
$testHandler = new TestHandler();
|
||||
$monolog->pushHandler($testHandler);
|
||||
|
||||
Log::extend('testing', function() use ($monolog) {
|
||||
return $monolog;
|
||||
});
|
||||
Log::setDefaultDriver('testing');
|
||||
|
||||
return $testHandler;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user