PHP code example of roaresearch / yii2-arfixture

1. Go to this page and download the library: Download roaresearch/yii2-arfixture 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/ */

    

roaresearch / yii2-arfixture example snippets


class UserFixture extends ARFixture
{
    public $modelClass = User::class;
}

return [
    // record with no explicit alias, will only show the key number on the log.
    [
        'username' => 'faryshta',
        'name' => 'Angel',
        'lastname' => 'Guevara',
        'email' => '[email protected]',
    ],

    // record with explicit alias, will be shown on the log
    'duplicated' => [
        'username' => 'faryshta',
        'name' => 'Angel',
        'lastname' => 'Guevara',
        'email' => '[email protected]',

        // optional, will apply the scenario before loading the models.
        'scenario' => 'api-save',

        // optional, will check the validation errors.
        'attributeErrors' => [
            // will check that username has this exact validation error.
            'username' => 'Username already in use',
            // will check that email has any validation error
            'email',
            // the other attributes are not expected to have a validation error.
        ],
    ]    
];

  'attributeErrors' => [
      'attribute1', // will check that it contains any error.
      'attribute2' => 'Error Message' // This has to be the error found.
  ]