laracasts / TestDummy

Easy factories for PHP integration testing.
https://laracasts.com/lessons/whats-new-in-testdummy
MIT License
456 stars 80 forks source link

Overriding relation attributes #19

Closed spamoom closed 10 years ago

spamoom commented 10 years ago

At the moment to set overrides on a relationship object I need to initiate both manually...

$dummyBrand = TestDummy::create('Brand', [
    'slug' => 'the-brand-slug',
]);
TestDummy::create('Trip', [
    'slug'     => 'the-trip-slug',
    'brand_id' => $dummyBrand->id,
]);

In the example above.. I'd like to see a method of overriding Brand attributes via a Trip create()

TestDummy::create('Trip', [
    'slug'     => 'the-trip-slug',
    'brand_id' => [
        'slug' => 'the-brand-slug',
    ],
]);

I could probably implement this, but wanted to see if anyone else would benefit first!

laracasts commented 10 years ago

Yeah, this should be fairly easy to implement. I'll try to find time to do it soon.

ssfinney commented 10 years ago

Interesting. That's useful for me too.

devinfd commented 10 years ago

I've just encountered this need as well. It would be nice if overrides could cascaded through the fixtures attributes tree into child models.

This would also require that TestDummy does not add an override value to a model that does not have that column. IE: TestDumy\Builder -> mergeFixtureWithOverrides($type, $fields) should not blindly use array_merge. It should first check to see if the keys in $fields are also keys in the current fixture.

If ever get time I'll create a PR....

devinfd commented 10 years ago

As I mentioned in the above pull request, https://github.com/laracasts/TestDummy/pull/29 The test only failed because composer.json was requiring "illuminate/support": "~5.0", which technically does not exist yet and so composer instal failed. With the requirement changed to 4.2 phpSpec is able to run and all 10 of its test do pass. Please consider this pull request as I believe that it is an important patch.

JeffreyWay commented 10 years ago

Okay, updated tests to bring back to green.

Thanks for this.

devinfd commented 10 years ago

Thank you, I appreciate it!

On Sep 27, 2014, at 4:32 PM, Jeffrey Way notifications@github.com wrote:

Okay, updated tests to bring back to green.

Thanks for this.

— Reply to this email directly or view it on GitHub.