From f858716e573d3a626e0ad56b6cda7784be9efdfc Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sun, 22 Sep 2024 22:58:31 +0200 Subject: [PATCH] Add Arch tests --- phpunit.xml | 3 +++ tests/Arch.php | 15 +++++++++++++++ tests/Pest.php | 11 +++++++++++ 3 files changed, 29 insertions(+) create mode 100644 tests/Arch.php diff --git a/phpunit.xml b/phpunit.xml index 50e1c960..adb5557d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,6 +10,9 @@ ./tests/Fileshare + + tests/Arch.php + ./packages/laravel-nami/tests/Unit diff --git a/tests/Arch.php b/tests/Arch.php new file mode 100644 index 00000000..7cb5f3b6 --- /dev/null +++ b/tests/Arch.php @@ -0,0 +1,15 @@ +expect('App') + ->not->toUse(['die', 'dd', 'dump']); + + +arch() + ->expect(globArch('App\*\Models')) + ->toExtend('Illuminate\Database\Eloquent\Model') + ->toBeClasses(); + +arch('app') + ->expect('App') + ->not->toHaveFileSystemPermissions('0777'); diff --git a/tests/Pest.php b/tests/Pest.php index a97bd509..f6bdb97a 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -11,6 +11,8 @@ | */ +use Symfony\Component\Finder\Finder; + uses( Tests\TestCase::class, // Illuminate\Foundation\Testing\RefreshDatabase::class, @@ -41,3 +43,12 @@ uses( | global functions to help you to reduce the number of lines of code in your test files. | */ + +function globArch(string $pattern) +{ + $files = iterator_to_array(Finder::create()->files()->in(str($pattern)->replaceStart('App', './app')->replace('\\', '/'))->name('*.php')); + + return collect($files)->map( + fn ($file) => str($file->getPathname())->replaceStart('./app', 'App')->replace('/', '\\')->replaceEnd('.php', '')->toString() + )->values()->toArray(); +}