Comments (8)
Factory Muffin is good for that.
from testdummy.
@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.
Cheers, I'll check it out
from testdummy.
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.
@ddelnano, thanks, but my issue is that there is not table for the Status model.
from testdummy.
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.
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.
@ChenHom what is your approach now with L8 factories change?
from testdummy.
Related Issues (20)
- `$faker->optional()` is not getting called foreach transaction HOT 3
- Issue with using strings as primary id HOT 1
- Create Models from json/array
- Call to undefined method User::fill() HOT 2
- Factory::build should take times() into account HOT 2
- Create factory extending/overriding an existing factory's attributes HOT 1
- More then one row beeing adding to relational models
- factory:App\Album syntax doesn't work. it said 'Integrity Constrain Violation' message. HOT 6
- Getting faker not found error running through behat
- Problem with attribute casting
- Can't use array attributes
- fakerphp/faker downgraded when installing laracasts/testdummy
- Is unique() supported? HOT 7
- Object of class Closure could not be converted to string HOT 2
- Could not locate a factory HOT 9
- unique() in user Closures
- Relationship attributes not being added to model instance before saving? HOT 5
- Ability to specify relation create new or use existing HOT 8
- Faker Localization HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testdummy.