-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from dansysanalyst/add_tests
[TESTS] Add basic tests
- Loading branch information
Showing
6 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
use function Pest\Laravel\get; | ||
|
||
it('properly displays & configure back label', function () { | ||
get(route('blv.index'))->assertSeeText('Back to Laravel'); | ||
|
||
$label = 'My Cool App'; | ||
|
||
config()->set('log-viewer.back_to_system_label', $label); | ||
|
||
get(route('blv.index'))->assertSeeText($label); | ||
}); | ||
|
||
test('home page loads Livewire component', function ($livewireComponent) { | ||
get(route('blv.index'))->assertSeeLivewire($livewireComponent); | ||
})->with([ | ||
'log-viewer::log-list', | ||
'log-viewer::file-list', | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
use Opcodes\LogViewer\Facades\LogViewer; | ||
use function Pest\Laravel\get; | ||
|
||
beforeEach(function () { | ||
LogViewer::clearFileCache(); | ||
generateLogFiles(['laravel.log', 'other.log']); | ||
}); | ||
|
||
it('properly includes log files', function () { | ||
get(route('blv.index'))->assertSeeText('laravel.log') | ||
->assertSeeText('other.log'); | ||
}); | ||
|
||
it('properly excludes log files', function () { | ||
config()->set('log-viewer.exclude_files', ['*other*']); | ||
|
||
get(route('blv.index'))->assertSeeText('laravel.log') | ||
->assertDontSee('other.log'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
use Illuminate\Routing\RouteCollection; | ||
use Illuminate\Support\Facades\Route; | ||
use function Pest\Laravel\get; | ||
|
||
test('testing route', function ($route) { | ||
get(route($route))->assertOK(); | ||
})->with([ | ||
'blv.index', | ||
]); | ||
|
||
test('the default url can be changed', function () { | ||
config()->set('log-viewer.route_path', 'new-log-route'); | ||
|
||
reloadRoutes(); | ||
|
||
expect(route('blv.index'))->toContain('new-log-route'); | ||
|
||
get(route('blv.index'))->assertOK(); | ||
}); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| HELPERS | ||
|-------------------------------------------------------------------------- | ||
*/ | ||
|
||
function reloadRoutes(): void | ||
{ | ||
$router = Route::getFacadeRoot(); | ||
$router->setRoutes((new RouteCollection())); | ||
|
||
Route::middleware('web') | ||
->namespace('App\Http\Controllers') | ||
->group('routes/web.php'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,33 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\File; | ||
use Opcodes\LogViewer\Tests\TestCase; | ||
|
||
uses(TestCase::class)->in(__DIR__); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| HELPERS | ||
|-------------------------------------------------------------------------- | ||
*/ | ||
|
||
/** | ||
* Generate log files with random data | ||
* | ||
* @param array <int, string> $files | ||
* @return void | ||
*/ | ||
function generateLogFiles(array $files): void | ||
{ | ||
foreach ($files as $file) { | ||
$file = storage_path('logs/'.$file); | ||
|
||
if (File::exists($file)) { | ||
File::delete($file); | ||
} | ||
|
||
File::put($file, str()->random()); | ||
|
||
test()->assertFileExists($file); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters