PHP code example of lucasmelocvl / laravel-model-unit-testing

1. Go to this page and download the library: Download lucasmelocvl/laravel-model-unit-testing 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/ */

    

lucasmelocvl / laravel-model-unit-testing example snippets


namespace Tests\Unit\Models;

use App\Models\User;
use Lucasmelocvl\LaravelModelUnitTesting\Abstracts\BaseModelTest;

class UserTest extends BaseModelTest
{
    protected function modelClass(): string
    {
        return \App\Models\User::class;
    }

    protected function expectedTable(): string
    {
        return 'users';
    }

    protected function expectedPrimaryKey(): string
    {
        return 'id';
    }

    protected function expectedIncrementing(): bool
    {
        return true;
    }

    protected function expectedKeyType(): string
    {
        return 'int';
    }

    protected function expectedFillable(): array
    {
        return ['name', 'email', 'password'];
    }

    protected function expectedGuarded(): array
    {
        return [];
    }

    protected function expectedHidden(): array
    {
        return ['password', 'remember_token'];
    }

    protected function expectedCasts(): array
    {
        return ['email_verified_at' => 'datetime'];
    }

    protected function expectedDates(): array
    {
        return ['created_at', 'updated_at'];
    }

    protected function expectedAppends(): array
    {
        return [];
    }

    protected function expectedTraits(): array
    {
        return [
            'Illuminate\Database\Eloquent\SoftDeletes',
        ];
    }

    protected function expectedRelationships(): array
    {
        return [
            'orders' => [
                'type' => 'HasMany',
                'related' => 'App\Models\Order',
                'foreignKey' => 'user_id',
            ],
        ];
    }
}
bash
php artisan models:generate-unit-tests --force
bash
php -d memory_limit=-1 vendor/bin/phpunit tests/Unit/Models