Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Oct 8, 2023
1 parent 8b62292 commit f07538a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Concerns/UsesGeneratorOverrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Orchestra\Canvas\Core\Concerns;

use Illuminate\Support\Str;
use Orchestra\Canvas\Core\Presets\Preset;
use Symfony\Component\Finder\Finder;

trait UsesGeneratorOverrides
Expand Down Expand Up @@ -96,4 +97,17 @@ protected function possibleEventsUsingCanvas(): array
->values()
->all();
}

/**
* Get the root namespace for the class.
*
* @return string
*/
abstract protected function rootNamespace();


/**
* Resolve the generator preset.
*/
abstract protected function generatorPreset(): Preset;
}
63 changes: 63 additions & 0 deletions tests/Concerns/UsesGeneratorOverridesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Orchestra\Canvas\Core\Tests\Concerns;

use Illuminate\Contracts\Support\Arrayable;
use Orchestra\Canvas\Core\Concerns\UsesGeneratorOverrides;
use Orchestra\Canvas\Core\PresetManager;
use Orchestra\Canvas\Core\Presets\Preset;
use Orchestra\Testbench\TestCase;

class UsesGeneratorOverridesTest extends TestCase
{
/** @test */
public function it_can_get_qualify_model_class()
{
$filesystem = $this->app['files'];

$filesystem->ensureDirectoryExists(base_path('app/Models'));

$stub = new UsesGeneratorOverridesTestStub();

$this->assertSame([
'user-model' => 'App\Models\User',
'welcome-view' => $this->app->joinPaths(base_path('resources'.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'welcome.blade.php')),
], $stub->toArray());
}
}

class UsesGeneratorOverridesTestStub implements Arrayable
{
use UsesGeneratorOverrides;

/**
* Get the root namespace for the class.
*
* @return string
*/
protected function rootNamespace()
{
return $this->rootNamespaceUsingCanvas();
}

/**
* Get the instance as an array.
*
* @return array<string, mixed>
*/
public function toArray()
{
return [
'user-model' => $this->qualifyModelUsingCanvas('User'),
'welcome-view' => $this->viewPathUsingCanvas('welcome.blade.php'),
];
}

/**
* Resolve the generator preset.
*/
protected function generatorPreset(): Preset
{
return app(PresetManager::class)->driver('laravel');
}
}

0 comments on commit f07538a

Please sign in to comment.