Conversation
Co-authored-by: StyleCI Bot <bot@styleci.io> Co-authored-by: Cristian Tabacitu <cristian.tabacitu@digitallyhappy.com>
Co-authored-by: StyleCI Bot <bot@styleci.io> Co-authored-by: Cristian Tabacitu <cristian.tabacitu@digitallyhappy.com> Co-authored-by: Cristian Tăbăcitu <cristitabacitu@gmail.com>
[ci skip] [skip ci]
[ci skip] [skip ci]
| public function setup() | ||
| { | ||
| // Default setup can be defined here if needed | ||
| } |
| * @param string $controllerClass | ||
| * @return void | ||
| */ | ||
| public static function applyConfiguration(string $controllerClass, $operation = 'list'): void |
| * @param string $method | ||
| * @return void | ||
| */ | ||
| public static function mockRoute(array $parameters, string $operation, string $uri = '/', string $method = 'GET'): void |
| } | ||
| } | ||
|
|
||
| public static function createTestEntry(string $model, array $attributes = []) |
There was a problem hiding this comment.
Let's dump the code in the file
| public function invalidInput() | ||
| { | ||
| return []; | ||
| } |
There was a problem hiding this comment.
Let's dump the code in the file
| return $model::factory()->raw(); | ||
| } | ||
|
|
||
| public function validUpdateInput($model) |
There was a problem hiding this comment.
Let's dump the code in the file
| public function getRouteParameters() | ||
| { | ||
| return []; | ||
| } |
There was a problem hiding this comment.
Let's make this a property on BaseTest
| * @param array $attributes | ||
| * @return \Illuminate\Database\Eloquent\Model | ||
| */ | ||
| public function createEntry(array $attributes = []) |
There was a problem hiding this comment.
Let's dump the code in the file
| return $url; | ||
| } | ||
|
|
||
| public function createTestEntries(int $count = 5, array $attributes = []) |
There was a problem hiding this comment.
Let's dump the code in the file
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | Test Configurations | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | Here you can map your CrudControllers to a specific TestConfiguration class. | ||
| | This allows you to customize the data used for testing, mock dependencies, | ||
| | or define valid/invalid inputs for specific controllers. | ||
| | | ||
| | Example: | ||
| | App\Http\Controllers\Admin\ProductCrudController::class => Tests\Config\ProductConfig::class, | ||
| | | ||
| */ | ||
| 'configurations' => [], |
There was a problem hiding this comment.
My delete test failed, because my entity had SoftDeletes
There was a problem hiding this comment.
Translated columns need stubs updated
There was a problem hiding this comment.
TODO: if CrudController instantiation fails, generate using conventions with comment in TestBase:
/**
* TODO: This testbase was generated using conventions. Please double-check and fix the configuration below.
*/
There was a problem hiding this comment.
In all my CrudController setup() methods i have something like this:
public function setup(): void
{
CRUD::setModel(\App\Models\City::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/city');
CRUD::setEntityNameStrings(__('common.city'), __('common.cities'));
$this->checkPermissions();
}So when i run the tests, they all fail with:
But it should be a permission error, not "on null".
There was a problem hiding this comment.
Then we have to document the way to easily change actingAs() to be able to add permissions etc. Perhaps a good way would be in DefaultTestBase to be able to do:
public function actingAs() {
// ..
}Perhaps we already have there there the code, so they can CHANGE IT instead of having to create the method.
Also maybe we have the code that creates the roles/permissions, commented out, so they can only uncomment it or something.

This PR adds the ability to generate tests for your crud operations. It comes with some helpers that aim to make developers life easier when generating tests for crud controllers.
See the full docs here: Laravel-Backpack/docs#656