Giter Club home page Giter Club logo

Comments (8)

ddelnano avatar ddelnano commented on July 28, 2024 1

Factory Muffin is good for that.

from testdummy.

ddelnano avatar ddelnano commented on July 28, 2024 1

@troccoli this definitely works on plain objects. We use it where I work to seed tables that we have hand written SQL for. You must define a ->save method on your model class that will persist it to your datastore. Its not extremely obvious from the docs (it would be nice if they defined an interface you must implement) but if you read the docs it will say they will call a save method on your model when trying to persist it.

from testdummy.

troccoli avatar troccoli commented on July 28, 2024

Cheers, I'll check it out

from testdummy.

troccoli avatar troccoli commented on July 28, 2024

@ddelnano,

I had a look at that but it seems it doesn't work on non Eloquent model either.

Let's try with an exanple of what I am trying to do:

class Status
{
    public $code;
    public $message;

    public function __construct() {
        $this->code = 0;
        $this->message = '';
    }

    // Setter and Getters omitted for simplicity
    ...
}

Now I woiuld like to write some intergation tests to make sure the setters and getters work. If this was an Eloquent model I would use a model factory, something like

$factory->define('Status', function (\Faker\Generator $faker) {
    return [
        'status'  => $faker->randomDigit,
        'message' => $faker->sentence,
    ];
});

This does not work (and I wasn't really expecting it to). But I would like a way similar to use, i.e. some way to create a factory to be reused (I do need it in other places in my integration tests).

Thanks

from testdummy.

troccoli avatar troccoli commented on July 28, 2024

@ddelnano, thanks, but my issue is that there is not table for the Status model.

from testdummy.

ddelnano avatar ddelnano commented on July 28, 2024

This is probably not the correct place for this since this is unrelated to TestDummy. Feel free to contact me [email protected] if you want to ask questions about our implementation.

from testdummy.

ChenHom avatar ChenHom commented on July 28, 2024

wow~It's long time ago.
I encountered this problem recently.
I built an anonymous class that inherits eloquent model to resolve this problem

like exampl below

use Faker\Generator as Faker;
use Illuminate\Database\Eloquent\Model;

$factory->define(
    $dummyClassName = get_class(new class extends Model{}),
    function (Faker $faker) {
        return [
            'profit' => $faker->numberBetween(10, 5000)
        ];
    }
);

config(compact('dummyClassName'));

in TestCase.php

    $fake = factory(config('dummyClassName'))->make();

from testdummy.

talovicnedim avatar talovicnedim commented on July 28, 2024

@ChenHom what is your approach now with L8 factories change?

from testdummy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.