Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/3.x' into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Jan 9, 2025
2 parents 4008285 + ad22ac7 commit 4d95bcc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Laravel/src/Commands/MoonShineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

use Leeto\PackageCommand\Command;
use MoonShine\Laravel\Support\StubsPath;
use MoonShine\MenuManager\MenuItem;
use ReflectionClass;

abstract class MoonShineCommand extends Command
{
Expand Down Expand Up @@ -43,11 +45,14 @@ public static function addResourceOrPageToMenu(string $class, string $title, str
{
$namespace = rtrim($namespace, '\\');

$reflector = new ReflectionClass(moonshineConfig()->getLayout());

self::addResourceOrPageTo(
class: "$namespace\\$class",
to: app_path('MoonShine/Layouts/MoonShineLayout.php'),
to: $reflector->getFileName(),
between: static fn (Stringable $content): Stringable => $content->betweenFirst("protected function menu(): array", '}'),
replace: static fn (Stringable $content, Closure $tab): Stringable => $content->replace("];", "{$tab()}MenuItem::make('$title', $class::class),\n{$tab(2)}];"),
use: MenuItem::class
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Laravel/src/DependencyInjection/MoonShineConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function __construct(Repository $repository)
$this->items = $repository->get('moonshine', []);
$this->authorizationRules = Collection::make();
$this
->set('dir', 'app/MoonShine')
->set('namespace', 'App\MoonShine');
->set('dir', $this->items['dir'] ?? 'app/MoonShine')
->set('namespace', $this->items['namespace'] ?? 'App\MoonShine');
}

public function dir(string $dir, string $namespace): self
Expand Down
9 changes: 9 additions & 0 deletions tests/Feature/Commands/ResourceCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MoonShine\Tests\Feature\Commands;

use MoonShine\Laravel\Commands\MakeResourceCommand;
use MoonShine\MenuManager\MenuItem;
use MoonShine\Tests\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
Expand All @@ -19,9 +20,12 @@ final class ResourceCommandTest extends TestCase
#[TestDox('it successful file created')]
public function successfulCreated(): void
{
$reflector = new \ReflectionClass(moonshineConfig()->getLayout());

$name = 'DeleteMeResource';
$file = "$name.php";
$path = __DIR__ . "/../../../app/MoonShine/Resources/$file";
$layoutPath = $reflector->getFileName();

@unlink($path);

Expand All @@ -37,6 +41,11 @@ public function successfulCreated(): void
->assertSuccessful();

$this->assertFileExists($path);

$layoutContent = file_get_contents($layoutPath);

$this->assertStringContainsString(MenuItem::class, $layoutContent);
$this->assertStringContainsString('DeleteMeResource', $layoutContent);
}

#[Test]
Expand Down

0 comments on commit 4d95bcc

Please sign in to comment.