From cde48230e15bedbe8df39a7595ee7712d33b2ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20H=C3=B8rlyck?= Date: Mon, 16 Oct 2023 20:50:14 +0200 Subject: [PATCH] feat: add tests (#11) * feat: add tests * fix: naming of tests * Fix styling --------- Co-authored-by: emilhorlyck --- src/Commands/InitCommand.php | 11 +++++++---- src/ServiceProvider.php | 4 ++++ tests/ArchTest.php | 38 ++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/Commands/InitCommand.php b/src/Commands/InitCommand.php index 1deef06..c340ee3 100644 --- a/src/Commands/InitCommand.php +++ b/src/Commands/InitCommand.php @@ -31,7 +31,7 @@ public function handle(): int // - [ ] Conventional commit script // - [ ] Release script // - [ ] Pre push git hook for pest - // - [ ] Run tests + // - [ ] Add tests // - [x] Fillament Admin panel $initSteps = [ @@ -43,7 +43,7 @@ public function handle(): int // 'conventional-commits' => 'Conventional commit script', // 'release' => 'Release script', // 'pre-push' => 'Pre push git hook for pest', - // 'tests' => 'Run tests', + 'tests' => 'Add tests', 'admin' => 'Fillament Admin panel', ]; @@ -316,10 +316,13 @@ public function handle(): int info('Fillament installed successfully. go to /admin to see the admin panel.'); } - // Run tests + // Add tests if ($chosenSteps->contains('tests')) { + $this->info('Adding tests...'); + exec('php artisan vendor:publish --tag=Laravel-pareto-tests'); + $this->info('Tests added successfully.'); exec('./vendor/bin/pest --init'); - exec('./vendor/bin/pest'); + // exec('./vendor/bin/pest'); } return self::SUCCESS; diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index e9c99b0..02ad318 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -24,5 +24,9 @@ public function boot(): void InitCommand::class, ]); } + + $this->publishes([ + __DIR__.'/../tests/ArchTest.php' => config_path('../tests/Feature/Pareto/ArchTest.php'), + ], 'Laravel-pareto-tests'); } } diff --git a/tests/ArchTest.php b/tests/ArchTest.php index fd6a1e4..5ab4049 100644 --- a/tests/ArchTest.php +++ b/tests/ArchTest.php @@ -3,3 +3,41 @@ it('will not use debugging functions') ->expect(['dd', 'dump', 'ray']) ->not->toBeUsed(); + +test('invokable actions') + ->expect('App\Actions') + ->toBeInvokable(); + +test('models extend eloquent') + ->expect('App\Models') + ->toExtend('Illuminate\Database\Eloquent\Model'); + +test('jobs implement should queue') + ->expect('App\Jobs') + ->toImplement('Illuminate\Contracts\Queue\ShouldQueue'); + +// Suffixes + +test('controllers end with controller') + ->expect('App\Http\Controllers') + ->toHaveSuffix('Controller'); + +test('jobs end with job') + ->expect('App\Jobs') + ->toHaveSuffix('Job'); + +test('clients end with client') + ->expect('App\Http\Clients') + ->toHaveSuffix('Client'); + +test('factories end with factory') + ->expect('App\databases\factories') + ->toHaveSuffix('Factory'); + +test('seeders end with seeder') + ->expect('App\database\seeders') + ->toHaveSuffix('Seeder'); + +test('providers end with provider') + ->expect('App\Providers') + ->toHaveSuffix('Provider');