Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API only config #355

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/log-viewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

'enabled' => env('LOG_VIEWER_ENABLED', true),

'api_only' => env('LOG_VIEWER_API_ONLY', false),

'require_auth_in_production' => true,

/*
Expand Down
4 changes: 4 additions & 0 deletions src/LogViewerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ protected function registerRoutes()
$this->loadRoutesFrom(self::basePath('/routes/api.php'));
});

if (config('log-viewer.api_only', false)) {
return;
}

Route::group([
'domain' => config('log-viewer.route_domain', null),
'prefix' => config('log-viewer.route_path'),
Expand Down
15 changes: 15 additions & 0 deletions tests/DeferPackageProviderTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Opcodes\LogViewer\Tests;

use Illuminate\Foundation\Support\Providers\RouteServiceProvider;

class DeferPackageProviderTestCase extends TestCase
{
protected function getPackageProviders($app)
{
return [
RouteServiceProvider::class,
];
}
}
13 changes: 13 additions & 0 deletions tests/Feature/OnlyApiRoutesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use Opcodes\LogViewer\LogViewerServiceProvider;
use Opcodes\LogViewer\Tests\DeferPackageProviderTestCase;
use Symfony\Component\Routing\Exception\RouteNotFoundException;

uses(DeferPackageProviderTestCase::class);

test('only has api routes', function () {
config(['log-viewer.api_only' => true]);
$this->app->register(LogViewerServiceProvider::class);
route('log-viewer.index');
})->throws(RouteNotFoundException::class);
22 changes: 19 additions & 3 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@
use Opcodes\LogViewer\LogIndex;
use Opcodes\LogViewer\Logs\LogType;
use Opcodes\LogViewer\Tests\TestCase;
use Symfony\Component\Finder\Finder;

uses(TestCase::class)->in(__DIR__);
$finder = new Finder();

$useTestCases = [];
foreach ($finder->files()->in(__DIR__)->notName('OnlyApiRoutesTest.php')->name('*.php') as $file) {
$useTestCases[] = $file->getRealPath();
}

$callingPublishTestCases = [];
foreach ($finder->files()->in(__DIR__ . '/Feature')->notName('OnlyApiRoutesTest.php')->name('*.php') as $file) {
$callingPublishTestCases[] = $file->getRealPath();
}

uses(TestCase::class)->in(...$useTestCases);
uses()->afterEach(fn () => clearGeneratedLogFiles())->in('Feature', 'Unit');
uses()->beforeEach(fn () => Artisan::call('log-viewer:publish'))->in('Feature');
uses()->beforeEach(fn () => Artisan::call('log-viewer:publish'))->in(...$callingPublishTestCases);
uses()->beforeEach(function () {
// let's not include any of the default mac logs or similar
config(['log-viewer.include_files' => ['*.log', '**/*.log']]);
config([
'log-viewer.api_only' => false,
'log-viewer.include_files' => ['*.log', '**/*.log']
]);
})->in('Unit', 'Feature');

/*
Expand Down