PHP code example of fabtec / test-craft

1. Go to this page and download the library: Download fabtec/test-craft library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fabtec / test-craft example snippets


    protected string $modelClass = \App\Models\Product::class;
    

    protected string $routePrefix = 'products';
    

    protected function generateData(): array
    {
        return [
            'name' => 'Product Test',
            'price' => 100.0,
        ];
    }
    

    protected function generateCreateData(): array
    {
        return [
            'name' => 'New Product',
            'price' => 150.0,
        ];
    }
    

namespace Tests\Feature\Http\Controllers;

use App\Models\Product;
use FabTec\TestCraft\ResourceControllerTestCase;

class ProductControllerTest extends ResourceControllerTestCase
{
    /**
     * {@inheritDoc}
     */
    protected string $modelClass = Product::class;

    /**
     * {@inheritDoc}
     */
    protected string $routePrefix = 'products';

    /**
     * {@inheritDoc}
     */
    protected function generateData(): array
    {
        return [
            'name' => 'Product Test',
            'price' => 100.0,
        ];
    }
}
bash
php artisan testcraft:create {entity}