-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add blade component support and fix livewire support
- Loading branch information
Showing
33 changed files
with
383 additions
and
9 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
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
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,29 @@ | ||
<?php | ||
|
||
namespace Mozex\Modules\Scouts; | ||
|
||
use Illuminate\View\Component; | ||
use Mozex\Modules\Contracts\ModuleClassScout; | ||
use Mozex\Modules\Enums\AssetType; | ||
use Spatie\StructureDiscoverer\Data\DiscoveredClass; | ||
use Spatie\StructureDiscoverer\Discover; | ||
use Spatie\StructureDiscoverer\Enums\Sort; | ||
|
||
class BladeComponentsScout extends ModuleClassScout | ||
{ | ||
public function asset(): AssetType | ||
{ | ||
return AssetType::BladeComponents; | ||
} | ||
|
||
protected function definition(): Discover | ||
{ | ||
return Discover::in(...$this->patterns()) | ||
->parallel() | ||
->classes() | ||
->extending(Component::class) | ||
->custom(fn (DiscoveredClass $structure) => ! $structure->isAbstract) | ||
->full() | ||
->sortBy(Sort::Name); | ||
} | ||
} |
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,19 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
define('TESTBENCH_CORE', true); | ||
define('TESTBENCH_WORKING_PATH', $workingPath = getcwd()); | ||
|
||
require $_composer_autoload_path ?? __DIR__.'/vendor/autoload.php'; | ||
|
||
$config = Orchestra\Testbench\Foundation\Config::loadFromYaml( | ||
workingPath: $workingPath, | ||
defaults: [ | ||
'providers' => [], | ||
'dont-discover' => [], | ||
], | ||
); | ||
|
||
$commander = new Orchestra\Testbench\Console\Commander($config, $workingPath); | ||
|
||
$commander->handle(); |
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,66 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Blade; | ||
use Modules\First\View\Components\Filter; | ||
use Modules\First\View\Components\WrongComponent; | ||
use Modules\Second\View\Components\Button\Loading; | ||
use Modules\Second\View\Components\Search; | ||
use Mozex\Modules\Enums\AssetType; | ||
use Mozex\Modules\Scouts\BladeComponentsScout; | ||
|
||
test('scout will not collect when disabled', function () { | ||
config()->set( | ||
'modules.'.AssetType::BladeComponents->value.'.active', | ||
false | ||
); | ||
|
||
expect(BladeComponentsScout::create()->get())->toHaveCount(0); | ||
}); | ||
|
||
test('scout has correct structure', function () { | ||
expect(BladeComponentsScout::create()->get()) | ||
->each->toHaveKeys(['module', 'path', 'namespace']); | ||
}); | ||
|
||
test('scout will select correct classes', function () { | ||
expect(BladeComponentsScout::create()->collect()->pluck('namespace')) | ||
->toContain(Filter::class) | ||
->toContain(Search::class) | ||
->toContain(Loading::class) | ||
->not->toContain(WrongComponent::class); | ||
}); | ||
|
||
it('can load blade components', function () { | ||
$components = Blade::getClassComponentAliases(); | ||
|
||
BladeComponentsScout::create()->collect() | ||
->each(function (array $asset) use ($components) { | ||
expect($components)->toContain($asset['namespace']); | ||
}); | ||
|
||
expect(Blade::render( | ||
string: '<x-first::filter name="Filter"/>', | ||
deleteCachedView: true | ||
)) | ||
->toContain('Filter Component') | ||
->and(Blade::render( | ||
string: '<x-first::select name="Select"/>', | ||
deleteCachedView: true | ||
)) | ||
->toContain('Select Component') | ||
->and(Blade::render( | ||
string: '<x-first::without-view name="Without View"/>', | ||
deleteCachedView: true | ||
)) | ||
->toContain('Without View Component') | ||
->and(Blade::render( | ||
string: '<x-second::search name="Search"/>', | ||
deleteCachedView: true | ||
)) | ||
->toContain('Search Component') | ||
->and(Blade::render( | ||
string: '<x-second::button.loading name="Loading"/>', | ||
deleteCachedView: true | ||
)) | ||
->toContain('Loading Component'); | ||
}); |
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
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 | ||
|
||
namespace Modules\First\Components; | ||
|
||
use Illuminate\Contracts\View\View; | ||
use Illuminate\View\Component; | ||
|
||
class Select extends Component | ||
{ | ||
public function __construct( | ||
public string $name, | ||
) { | ||
$this->name .= ' Component'; | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('first::components.select'); | ||
} | ||
} |
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 | ||
|
||
namespace Modules\First\Components; | ||
|
||
use Illuminate\View\Component; | ||
|
||
class WithoutView extends Component | ||
{ | ||
public function __construct( | ||
public string $name, | ||
) { | ||
$this->name .= ' Component'; | ||
} | ||
|
||
public function render(): string | ||
{ | ||
return <<<'blade' | ||
{{ $name }} | ||
blade; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Modules\First\Livewire\Nested; | ||
|
||
use Illuminate\View\View; | ||
use Livewire\Component; | ||
|
||
class NestedUsers extends Component | ||
{ | ||
public function render(): View | ||
{ | ||
return view('first::livewire.nested.nested-users', [ | ||
'name' => 'Nested Users Livewire Component', | ||
]); | ||
} | ||
} |
Oops, something went wrong.