-
Notifications
You must be signed in to change notification settings - Fork 0
Improve tests coverage #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cffa0f3
refactor: return indexed array from parse_csv function for consistent…
AbdelrhmanSaid 0c706c3
refactor: encapsulate cache invalidation logic in forgetCachedValue m…
AbdelrhmanSaid fda3587
refactor: update LangExtractor to accept dynamic file extensions and …
AbdelrhmanSaid e931a2d
refactor: change view compiled path to use system temporary directory…
AbdelrhmanSaid 49906d2
test: add comprehensive feature and unit tests for core components in…
AbdelrhmanSaid 87b36c3
test: add unit and feature tests for authentication context, datatabl…
AbdelrhmanSaid bdf0fb0
docs: add Test Coverage Improvement Plan outlining goals, current sta…
AbdelrhmanSaid 93b9ab3
Add GitHub Actions workflow for testing
AbdelrhmanSaid 0e825f7
refactor: remove LaravelLangExtractorServiceProvider and related comm…
AbdelrhmanSaid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,30 @@ | ||
| name: tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| pull_request: | ||
| branches: | ||
| - master | ||
|
|
||
| jobs: | ||
| ci: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: 8.4 | ||
| tools: composer:v2 | ||
| coverage: xdebug | ||
|
|
||
| - name: Install Dependencies | ||
| run: composer install --no-interaction --prefer-dist --optimize-autoloader | ||
|
|
||
| - name: Run Tests | ||
| run: composer test |
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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
37 changes: 0 additions & 37 deletions
37
src/packages/lang-extractor/src/Console/LangExtractCommand.php
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
26 changes: 0 additions & 26 deletions
26
src/packages/lang-extractor/src/LaravelLangExtractorServiceProvider.php
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
tests/Feature/Core/Middleware/EnsureDependenciesBuiltTest.php
This file contains hidden or 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,28 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Http\Request; | ||
| use Illuminate\Support\Facades\File; | ||
| use Redot\Http\Middleware\EnsureDependenciesBuilt; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| it('continues without rebuilding when the dependency lock is current', function () { | ||
| $directory = public_path('assets/dist'); | ||
| $trackedFile = 'composer.json'; | ||
|
|
||
| File::ensureDirectoryExists($directory); | ||
| File::put($directory . '/lock.json', json_encode([ | ||
| 'files' => [ | ||
| $trackedFile => filemtime(base_path($trackedFile)), | ||
| ], | ||
| 'directories' => [], | ||
| ])); | ||
|
|
||
| $response = (new EnsureDependenciesBuilt)->handle( | ||
| Request::create('/'), | ||
| fn () => new Response('next') | ||
| ); | ||
|
|
||
| expect($response->getContent())->toBe('next'); | ||
|
|
||
| File::delete($directory . '/lock.json'); | ||
| }); |
This file contains hidden or 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\Support\Facades\Route; | ||
| use Redot\Http\Middleware\Localization; | ||
|
|
||
| it('sets the application locale from the route parameter', function () { | ||
| Route::middleware(Localization::class) | ||
| ->get('/{locale}/localized-probe', fn () => response(app()->getLocale() . '|' . request()->route('locale', 'missing'))) | ||
| ->name('website.localized-probe'); | ||
|
|
||
| $this->get('/ar/localized-probe') | ||
| ->assertOk() | ||
| ->assertSee('ar|missing'); | ||
|
|
||
| expect(session('website_locale'))->toBe('ar') | ||
| ->and(app()->getLocale())->toBe('ar'); | ||
| }); | ||
|
|
||
| it('redirects unsupported route locales to the fallback locale', function () { | ||
| Route::middleware(Localization::class) | ||
| ->get('/{locale}/fallback-probe', fn () => response('ok')) | ||
| ->name('website.fallback-probe'); | ||
|
|
||
| $this->get('/fr/fallback-probe?foo=bar') | ||
| ->assertRedirect('/en/fallback-probe?foo=bar') | ||
| ->assertStatus(301); | ||
| }); | ||
|
|
||
| it('lets the locale query string override the route locale', function () { | ||
| Route::middleware(Localization::class) | ||
| ->get('/{locale}/query-locale-probe', fn () => response('ok')) | ||
| ->name('website.query-locale-probe'); | ||
|
|
||
| $this->get('/en/query-locale-probe?locale=ar') | ||
| ->assertRedirect('/ar/query-locale-probe?locale=ar') | ||
| ->assertStatus(301); | ||
| }); |
This file contains hidden or 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,53 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Support\Facades\Artisan; | ||
| use Illuminate\Support\Facades\Schema; | ||
| use Redot\Sidebar\Sidebar; | ||
| use Redot\Toastify\Toastify; | ||
|
|
||
| it('boots the package testbench application', function () { | ||
| expect(app()->bound(Sidebar::class))->toBeTrue() | ||
| ->and(app()->make(Sidebar::class))->toBeInstanceOf(Sidebar::class) | ||
| ->and(app('sidebar'))->toBe(app()->make(Sidebar::class)) | ||
| ->and(app()->bound(Toastify::class))->toBeTrue() | ||
| ->and(app('toastify'))->toBeInstanceOf(Toastify::class); | ||
| }); | ||
|
|
||
| it('merges package configuration', function () { | ||
| expect(config('redot.features.dashboard.enabled'))->toBeTrue() | ||
| ->and(config('redot.features.dashboard.prefix'))->toBe('dashboard') | ||
| ->and(config('redot.locales'))->toHaveCount(2) | ||
| ->and(config('datatables.assets'))->toBeArray() | ||
| ->and(config('toastify.defaults'))->toBeArray() | ||
| ->and(config('toastify.toastifiers.success'))->toBeArray(); | ||
| }); | ||
|
|
||
| it('runs package migrations in the testbench database', function () { | ||
| foreach ([ | ||
| 'settings', | ||
| 'languages', | ||
| 'language_tokens', | ||
| 'login_tokens', | ||
| 'permissions', | ||
| 'roles', | ||
| 'model_has_permissions', | ||
| 'model_has_roles', | ||
| 'role_has_permissions', | ||
| ] as $table) { | ||
| expect(Schema::hasTable($table))->toBeTrue("Expected table [$table] to exist."); | ||
| } | ||
| }); | ||
|
|
||
| it('registers package artisan commands', function () { | ||
| $commands = array_keys(Artisan::all()); | ||
|
|
||
| expect($commands)->toContain( | ||
| 'uploads:clear', | ||
| 'permissions:sync', | ||
| 'lang:extract', | ||
| 'lang:sync', | ||
| 'lang:publish', | ||
| 'lang:revert', | ||
| 'make:datatable', | ||
| ); | ||
| }); |
This file contains hidden or 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,78 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Console\Command; | ||
| use Illuminate\Support\Facades\File; | ||
| use Illuminate\Support\Facades\View; | ||
| use Illuminate\Support\Str; | ||
|
|
||
| function package_root(): string | ||
| { | ||
| return dirname(__DIR__, 3); | ||
| } | ||
|
|
||
| it('autoloads all package classes declared under composer psr-4 roots', function () { | ||
| $root = package_root(); | ||
| $composer = json_decode(File::get($root . '/composer.json'), true, flags: JSON_THROW_ON_ERROR); | ||
| $prefixes = $composer['autoload']['psr-4']; | ||
| $autoloadFiles = collect($composer['autoload']['files'] ?? []) | ||
| ->map(fn (string $path): string => realpath($root . '/' . $path)) | ||
| ->filter() | ||
| ->all(); | ||
| $packagePaths = collect($prefixes) | ||
| ->reject(fn (string $path, string $namespace): bool => $namespace === 'Redot\\') | ||
| ->map(fn (string $path): string => realpath($root . '/' . $path)) | ||
| ->filter() | ||
| ->all(); | ||
|
|
||
| foreach ($prefixes as $namespace => $path) { | ||
| foreach (File::allFiles($root . '/' . $path) as $file) { | ||
| if ($file->getExtension() !== 'php') { | ||
| continue; | ||
| } | ||
|
|
||
| if (in_array(realpath($file->getPathname()), $autoloadFiles, true)) { | ||
| continue; | ||
| } | ||
|
|
||
| if ($namespace === 'Redot\\' && Str::startsWith($file->getPathname(), $root . '/src/packages')) { | ||
| continue; | ||
| } | ||
|
|
||
| $relative = Str::of($file->getRelativePathname()) | ||
| ->replace(DIRECTORY_SEPARATOR, '\\') | ||
| ->replaceEnd('.php', ''); | ||
|
|
||
| $class = $namespace . $relative; | ||
|
|
||
| expect(class_exists($class) || interface_exists($class) || trait_exists($class)) | ||
| ->toBeTrue("Expected [$class] to autoload."); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| it('keeps command classes concrete and named', function () { | ||
| foreach (File::allFiles(package_root() . '/src/Commands') as $file) { | ||
| $class = 'Redot\\Commands\\' . $file->getBasename('.php'); | ||
| $reflection = new ReflectionClass($class); | ||
|
|
||
| expect($reflection->isSubclassOf(Command::class))->toBeTrue("$class must extend Command."); | ||
|
|
||
| $instance = app($class); | ||
| $name = method_exists($instance, 'getName') ? $instance->getName() : null; | ||
|
|
||
| expect($name)->not->toBeEmpty("$class must define a command name."); | ||
| } | ||
| }); | ||
|
|
||
| it('can resolve package views referenced by service providers', function () { | ||
| foreach ([ | ||
| 'toastify::css', | ||
| 'toastify::js', | ||
| 'datatables::datatable', | ||
| 'datatables::filters.string', | ||
| 'datatables::partials.table', | ||
| 'datatables::pagination.default', | ||
| ] as $view) { | ||
| expect(View::exists($view))->toBeTrue("Expected view [$view] to exist."); | ||
| } | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$packagePathsis computed but never used. Dropping it (or using it to constrain which paths are scanned) would reduce noise and keep the test intent clearer.