CodeIgniter Forums
How make fake test to work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: How make fake test to work (/showthread.php?tid=77096)



How make fake test to work - natanfelles - 07-18-2020

Hello everyone! I having a bad time trying to use the new fake testing helper.


Here is my model:

PHP Code:
<?php namespace App\Models;

use 
CodeIgniter\Model;
use 
Faker\Generator;

class 
Users extends Model
{
    protected 
$table 'users';
    protected 
$allowedFields = [
        
'name',
        
'email',
        
'password',
    ];
    protected 
$useTimestamps true;
    protected 
$returnType User::class;

    public function 
fake(Generator &$faker)
    {
        return [
            
'name' => $faker->name,
            
'email' => $faker->email,
            
'password' => password_hash('password'PASSWORD_DEFAULT),
        ];
    }



Here is my controller:

PHP Code:
<?php namespace App\Controllers;

use 
App\Models\Users as UsersModel;

class 
Home extends BaseController
{
    public function 
index()
    {
        
helper('test');
        
$user fake(UsersModel::class);
        
var_dump($user);
    }



The result is

[Image: Captura-de-tela-de-2020-07-18-18-33-48.png]



CodeIgniter\Database\Exceptions\DataException

There is no data to insert.


What am I doing wrong? Thank you!


RE: How make fake test to work - InsiteFX - 07-19-2020

Lonnie created a video that you can watch on using it.

See the forums News & Discussion.


RE: How make fake test to work - marcogmonteiro - 07-20-2020

Check this thread. https://forum.codeigniter.com/thread-77071.html


RE: How make fake test to work - natanfelles - 07-20-2020

OK. Seems like it do not works with custom Entities.

Here is the Entity:

PHP Code:
<?php namespace App\Models;

use 
CodeIgniter\Entity;

class 
User extends Entity
{
    protected 
$id;
    protected 
$name;
    protected 
$email;
    protected 
$password;



Now my question is: is this the expected behavior?

Thank you!


RE: How make fake test to work - natanfelles - 07-20-2020

Open an issue at https://github.com/codeigniter4/CodeIgniter4/issues/3368