-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Mortexa\LaravelArkitect; | ||
|
||
use Illuminate\Support\Arr; | ||
|
||
class RuleLoader | ||
{ | ||
public static function user(): array | ||
{ | ||
$rules = []; | ||
|
||
foreach (glob(base_path('tests/Architecture/*.php')) as $file) { | ||
$class = basename($file, '.php'); | ||
$rules[] = 'Tests\\Architecture\\'.$class; | ||
} | ||
|
||
return $rules; | ||
} | ||
|
||
public static function package(): array | ||
{ | ||
$package_config = CreateApplication::app()->make('config')['arkitect']; | ||
|
||
return Arr::flatten($package_config['rules']); | ||
} | ||
|
||
public static function all(): array | ||
{ | ||
return array_merge(static::package(), static::user()); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\File; | ||
use Mortexa\LaravelArkitect\RuleLoader; | ||
use function PHPUnit\Framework\assertEqualsCanonicalizing; | ||
|
||
it('loads user\'s rules', function () { | ||
$fooClass = base_path('tests/Architecture/Foo.php'); | ||
$barClass = base_path('tests/Architecture/Bar.php'); | ||
|
||
if (File::exists($fooClass)) { | ||
unlink($fooClass); | ||
} | ||
|
||
if (File::exists($barClass)) { | ||
unlink($barClass); | ||
} | ||
|
||
Artisan::call('make:arkitect Foo'); | ||
Artisan::call('make:arkitect Bar'); | ||
|
||
$rules = RuleLoader::user(); | ||
|
||
assertEqualsCanonicalizing(['Tests\\Architecture\\Foo', 'Tests\\Architecture\\Bar'], $rules); | ||
}); |