Skip to content

Commit

Permalink
feat: load helpers from ship
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Dec 31, 2024
1 parent aa94cf8 commit 5f13267
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Foundation/Providers/ApiatoServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ private function loadShipHelpers(): void
$files = File::files($shipHelpersDirectory);

foreach ($files as $file) {
if (!class_exists($file->getBasename('.php'))) {
require $file;
}
require_once $file;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Functional/Providers/ApiatoServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
});
});

it('loads helper functions form Ship', function (): void {
expect(function_exists('this_is_a_test_function_to_test_functions_file'))->toBeTrue()
->and(function_exists('this_is_a_test_function_to_test_helpers_file'))->toBeTrue();
});

it('can register middlewares in the service provider', function (): void {
expect(app(Kernel::class)
->hasMiddleware(BeforeMiddleware::class))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Tests\Support\Doubles\Fakes\Laravel\app\Ship\Helpers;

class ExplosiveClass
{
// This class is used to test if we can handle requiring helper files from
// a directory where it has a class (which is already declared) in it.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

if (!function_exists('this_is_a_test_function_to_test_functions_file')) {
function this_is_a_test_function_to_test_functions_file(): string
{
return 'functions file loaded';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

if (!function_exists('this_is_a_test_function_to_test_helpers_file')) {
function this_is_a_test_function_to_test_helpers_file(): string
{
return 'helpers file loaded';
}
}

0 comments on commit 5f13267

Please sign in to comment.