Skip to content

Commit

Permalink
complete crud_files_created_successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
milwad-dev committed Apr 15, 2024
1 parent 8f7dbf9 commit 6690f22
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions tests/Commands/MakeCrudCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,44 @@ class MakeCrudCommandTest extends TestCase
public function crud_files_created_successfully(): void
{
$this->artisan('crud:make', ['name' => 'Product'])
->expectsQuestion('Do you want something extra?', 5)
->assertSuccessful();
->expectsQuestion('Do you want something extra?', 0)
->assertSuccessful()
->expectsOutput('Crud files successfully generated...');

// Model
$this->assertFileExists(app_path('Models/Product.php'));

// Migration
$this->migrationExists('create_products_table');

// Controller
$this->assertFileExists(app_path('Http/Controllers/ProductController.php'));

// Requests
$this->assertFileExists(app_path('Http/Requests/ProductStoreRequest.php'));
$this->assertFileExists(app_path('Http/Requests/ProductUpdateRequest.php'));

// View
$this->assertFileExists(resource_path('views/products/index.blade.php'));
$this->assertFileExists(resource_path('views/products/create.blade.php'));
$this->assertFileExists(resource_path('views/products/edit.blade.php'));
}

/**
* Check migration file exists.
*/
protected function migrationExists(string $mgr): bool
{
$path = database_path('migrations/');
$files = scandir($path);

foreach ($files as &$value) {
$pos = strpos($value, $mgr);
if ($pos !== false) {
return true;
}
}

return false;
}
}

0 comments on commit 6690f22

Please sign in to comment.