Welcome Guest, Not a member yet? Register   Sign In
How make fake test to work
#1
Exclamation 
(This post was last modified: 07-18-2020, 04:19 PM by natanfelles.)

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!
Reply
#2

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

See the forums News & Discussion.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Check this thread. https://forum.codeigniter.com/thread-77071.html
Website: marcomonteiro.net  | Blog: blog.marcomonteiro.net | Twitter: @marcogmonteiro | TILThings: tilthings.com
Reply
#4

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!
Reply
#5

Open an issue at https://github.com/codeigniter4/CodeIgni...ssues/3368
Reply




Theme © iAndrew 2016 - Forum software by © MyBB